提交 8bcd1faf 编写于 作者: F fengjiayi

refactor product(DDim ddim)

上级 3f5e650d
...@@ -178,13 +178,16 @@ std::vector<int> vectorize(const DDim& ddim) { ...@@ -178,13 +178,16 @@ std::vector<int> vectorize(const DDim& ddim) {
return result; return result;
} }
ssize_t product(const DDim& ddim) { struct ProductVisitor : public boost::static_visitor<ssize_t> {
ssize_t result = 1; template <int D>
std::vector<int> v = vectorize(ddim); ssize_t operator()(const Dim<D>& dim) {
for (auto i : v) { return product(dim);
result *= i;
} }
return result; };
ssize_t product(const DDim& ddim) {
ProductVisitor visitor;
return boost::apply_visitor(visitor, ddim);
} }
///\cond HIDDEN ///\cond HIDDEN
......
...@@ -52,6 +52,9 @@ TEST(DDim, Equality) { ...@@ -52,6 +52,9 @@ TEST(DDim, Equality) {
// product of a DDim // product of a DDim
EXPECT_EQ(paddle::framework::product(vddim), 45); EXPECT_EQ(paddle::framework::product(vddim), 45);
EXPECT_EQ(
paddle::framework::product(paddle::framework::make_ddim({3, 2, 5, 3})),
90);
} }
TEST(DDim, Print) { TEST(DDim, Print) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册