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

refactor product(DDim ddim)

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