diff options
-rw-r--r-- | tensor.hpp | 17 |
1 files changed, 6 insertions, 11 deletions
@@ -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; } |