summaryrefslogtreecommitdiff
path: root/tensor.hpp
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2021-01-05 12:02:45 +0100
committerJaron Kent-Dobias <jaron@kent-dobias.com>2021-01-05 12:02:45 +0100
commit21a40622a0f542a7cf6ae695f2230205ecc3f445 (patch)
tree5b66ea1325954dd3dba6ae3b40c1643702a588a3 /tensor.hpp
parent4ef7461eded758cdab5f8dc063f06176310e0760 (diff)
downloadcode-21a40622a0f542a7cf6ae695f2230205ecc3f445.tar.gz
code-21a40622a0f542a7cf6ae695f2230205ecc3f445.tar.bz2
code-21a40622a0f542a7cf6ae695f2230205ecc3f445.zip
Eliminated one pesky helper function.
Diffstat (limited to 'tensor.hpp')
-rw-r--r--tensor.hpp17
1 files changed, 6 insertions, 11 deletions
diff --git a/tensor.hpp b/tensor.hpp
index 9e860d9..a2170a8 100644
--- a/tensor.hpp
+++ b/tensor.hpp
@@ -8,25 +8,20 @@
#include "factorial.hpp"
template <class Scalar, unsigned p, std::size_t... Indices>
-void setJ(Scalar z, Eigen::Tensor<Scalar, p>& J, const std::array<unsigned, p>& is,
- std::index_sequence<Indices...>) {
- J(std::get<Indices>(is)...) = z;
-}
-
-template <class Scalar, unsigned p, std::size_t... Indices>
Eigen::Tensor<Scalar, p> initializeJ(unsigned N, std::index_sequence<Indices...>) {
std::array<unsigned, p> Ns;
std::fill_n(Ns.begin(), p, N);
return Eigen::Tensor<Scalar, p>(std::get<Indices>(Ns)...);
}
-template <class Scalar, unsigned p, class Distribution, class Generator>
+template <class Scalar, unsigned p, class Distribution, class Generator, std::size_t... Indices>
void populateCouplings(Eigen::Tensor<Scalar, p>& J, unsigned N, unsigned l,
- std::array<unsigned, p> is, Distribution d, Generator& r) {
+ std::array<unsigned, p> is, Distribution d, Generator& r,
+ std::index_sequence<Indices...> ii) {
if (l == 0) {
Scalar z = d(r);
do {
- setJ<Scalar, p>(z, J, is, std::make_index_sequence<p>());
+ J(std::get<Indices>(is)...) = z;
} while (std::next_permutation(is.begin(), is.end()));
} else {
unsigned iMin;
@@ -38,7 +33,7 @@ void populateCouplings(Eigen::Tensor<Scalar, p>& J, unsigned N, unsigned l,
for (unsigned i = iMin; i < N; i++) {
std::array<unsigned, p> js = is;
js[p - l] = i;
- populateCouplings<Scalar, p, Distribution, Generator>(J, N, l - 1, js, d, r);
+ populateCouplings<Scalar, p>(J, N, l - 1, js, d, r, ii);
}
}
}
@@ -48,7 +43,7 @@ Eigen::Tensor<Scalar, p> generateCouplings(unsigned N, Distribution d, Generator
Eigen::Tensor<Scalar, p> J = initializeJ<Scalar, p>(N, std::make_index_sequence<p>());
std::array<unsigned, p> is;
- populateCouplings<Scalar, p, Distribution, Generator>(J, N, p, is, d, r);
+ populateCouplings<Scalar, p>(J, N, p, is, d, r, std::make_index_sequence<p>());
return J;
}