diff options
author | 2015-04-22 11:14:58 -0700 | |
---|---|---|
committer | 2015-04-22 11:14:58 -0700 | |
commit | 91359e1d0acf74bd586900849c4ab94c117c138f (patch) | |
tree | 8011a3348c60e16faeab2770c9547ad6b1194a92 /unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h | |
parent | 8838ed39f49bc1eb44efbcf13946132611a3132f (diff) |
Added the ability to generate a tensor from a custom user defined 'generator'. This simplifies the creation of constant tensors initialized using specific regular patterns.
Created a gaussian window generator as a first use case.
Diffstat (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h')
-rw-r--r-- | unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h b/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h index b5adb4041..450b1df40 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h @@ -496,6 +496,35 @@ template <typename T> class NormalRandomGenerator { #endif +template <typename T, typename Index, size_t NumDims> +class GaussianGenerator { + public: + static const bool PacketAccess = false; + + EIGEN_DEVICE_FUNC GaussianGenerator(const array<T, NumDims>& means, + const array<T, NumDims>& std_devs) + : m_means(means) + { + for (int i = 0; i < NumDims; ++i) { + m_two_sigmas[i] = std_devs[i] * std_devs[i] * 2; + } + } + + T operator()(const array<Index, NumDims>& coordinates) const { + T tmp = T(0); + for (int i = 0; i < NumDims; ++i) { + T offset = coordinates[i] - m_means[i]; + tmp += offset * offset / m_two_sigmas[i]; + } + return std::exp(-tmp); + } + + private: + array<T, NumDims> m_means; + array<T, NumDims> m_two_sigmas; +}; + + } // end namespace internal } // end namespace Eigen |