diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2021-01-15 14:45:19 +0100 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2021-01-15 14:45:19 +0100 |
commit | 136fcddcd38d0b8f3b40faf7c1cb7365d9b2a753 (patch) | |
tree | 38723818277fda2ed2573ee4479cc2b9a66c39a9 /tensor.hpp | |
parent | c10b0a99ecb9a6aab144aeca9c7538d1a897fd49 (diff) | |
download | code-136fcddcd38d0b8f3b40faf7c1cb7365d9b2a753.tar.gz code-136fcddcd38d0b8f3b40faf7c1cb7365d9b2a753.tar.bz2 code-136fcddcd38d0b8f3b40faf7c1cb7365d9b2a753.zip |
Converted more of library to templates accepting generic Scalar types and p
Diffstat (limited to 'tensor.hpp')
-rw-r--r-- | tensor.hpp | 20 |
1 files changed, 9 insertions, 11 deletions
@@ -5,43 +5,41 @@ #include <eigen3/unsupported/Eigen/CXX11/Tensor> -#include "factorial.hpp" - -template <class Scalar, unsigned p, std::size_t... Indices> +template <class Scalar, int p, std::size_t... Indices> Eigen::Tensor<Scalar, p> initializeJHelper(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> +template <class Scalar, int p> Eigen::Tensor<Scalar, p> initializeJ(unsigned N) { return initializeJHelper<Scalar, p>(N, std::make_index_sequence<p>()); } -template <class Scalar, unsigned p, std::size_t... Indices> +template <class Scalar, int p, std::size_t... Indices> void setJHelper(Eigen::Tensor<Scalar, p>& J, const std::array<unsigned, p>& ind, Scalar val, std::index_sequence<Indices...>) { J(std::get<Indices>(ind)...) = val; } -template <class Scalar, unsigned p> +template <class Scalar, int p> void setJ(Eigen::Tensor<Scalar, p>& J, std::array<unsigned, p> ind, Scalar val) { do { setJHelper<Scalar, p>(J, ind, val, std::make_index_sequence<p>()); } while (std::next_permutation(ind.begin(), ind.end())); } -template <class Scalar, unsigned p, std::size_t... Indices> +template <class Scalar, int p, std::size_t... Indices> Scalar getJHelper(const Eigen::Tensor<Scalar, p>& J, const std::array<unsigned, p>& ind, std::index_sequence<Indices...>) { return J(std::get<Indices>(ind)...); } -template <class Scalar, unsigned p> +template <class Scalar, int p> Scalar getJ(const Eigen::Tensor<Scalar, p>& J, const std::array<unsigned, p>& ind) { return getJHelper<Scalar, p>(J, ind, std::make_index_sequence<p>()); } -template <class Scalar, unsigned p> +template <class Scalar, int p> void iterateOverHelper(Eigen::Tensor<Scalar, p>& J, std::function<void(Eigen::Tensor<Scalar, p>&, std::array<unsigned, p>)>& f, unsigned l, std::array<unsigned, p> is) { @@ -62,13 +60,13 @@ void iterateOverHelper(Eigen::Tensor<Scalar, p>& J, } } -template <class Scalar, unsigned p> +template <class Scalar, int p> void iterateOver(Eigen::Tensor<Scalar, p>& J, std::function<void(Eigen::Tensor<Scalar, p>&, std::array<unsigned, p>)>& f) { std::array<unsigned, p> is; iterateOverHelper<Scalar, p>(J, f, p, is); } -template <class Scalar, unsigned p, class Distribution, class Generator> +template <class Scalar, int p, class Distribution, class Generator> Eigen::Tensor<Scalar, p> generateCouplings(unsigned N, Distribution d, Generator& r) { Eigen::Tensor<Scalar, p> J = initializeJ<Scalar, p>(N); |