[go: nahoru, domu]

Skip to content

Commit

Permalink
Fix bug in prod function. Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
romeric committed Mar 7, 2019
1 parent 155a50d commit 99e3ff0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tensor/Tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,11 @@ class Tensor: public AbstractTensor<Tensor<T,Rest...>,sizeof...(Rest)> {
constexpr int stride = V::Size;
int i = 0;

V vec =static_cast<T>(1);
V vec = static_cast<T>(1);
for (; i< unroll_upto; i+=stride) {
vec *= V(_data+i);
}
T scalar = static_cast<T>(0);
T scalar = static_cast<T>(1);
for (; i< Size; ++i) {
scalar *= _data[i];
}
Expand Down
8 changes: 7 additions & 1 deletion tests/test_basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void test_basics() {
assert(std::abs(norm(t8) - 46.4758001)<BigTol);
assert(std::abs(norm(t9) - 46.4758001)<BigTol);
assert(std::abs(norm(t10) - 7.7459667)<BigTol);


Tensor<T,2,2,2,2> t11; t11.fill(16);
assert(std::abs(norm(static_cast<decltype(t11)>(sqrt(t11)))- 16)<BigTol);
Expand All @@ -69,6 +69,12 @@ void test_basics() {
Tensor<T,2,2,2,2> t12 = sqrt(t11 + t11 - 2*t11 + t11/2 + 16/t11);
assert(std::abs(norm(t12)- 12)<BigTol);

Tensor<T,10> t13;
t13.iota(1);
assert(std::abs(t13.product() - 3628800) < Tol);
t13.iota(0);
assert(std::abs(t13.product()) < Tol);

print(FGRN(BOLD("All tests passed successfully")));

}
Expand Down

0 comments on commit 99e3ff0

Please sign in to comment.