diff --git a/include/qpp/internal/util.hpp b/include/qpp/internal/util.hpp index d1fd1a372..867a5fe47 100644 --- a/include/qpp/internal/util.hpp +++ b/include/qpp/internal/util.hpp @@ -105,15 +105,11 @@ template #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];