Skip to content

Commit

Permalink
improve performance of multiidx2n (#173)
Browse files Browse the repository at this point in the history
* improve performance of multiidx2n

* minor cleanup

* minor fix
  • Loading branch information
enum-class authored May 7, 2024
1 parent de626c7 commit 4d93478
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions include/qpp/internal/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,11 @@ template <typename V, typename T = V, typename U = T>
#endif
// no error checks in release version to improve speed

// static allocation for speed!
// allocate twice the size for matrices reshaped as vectors
T part_prod[2 * internal::maxn];

T part_prod = 1;
T result = 0;
part_prod[numdims - 1] = 1;
for (std::size_t i = 1; i < numdims; ++i) {
part_prod[numdims - i - 1] = part_prod[numdims - i] * dims[numdims - i];
result += midx[numdims - i - 1] * part_prod[numdims - i - 1];
part_prod *= dims[numdims - i];
result += midx[numdims - i - 1] * part_prod;
}

return result + midx[numdims - 1];
Expand Down

0 comments on commit 4d93478

Please sign in to comment.