12 #include <Eigen/CXX11/Tensor> 17 float operator()(
const array<Eigen::DenseIndex, 1>& coordinates)
const {
18 return coordinates[0];
22 template <
int DataLayout>
25 Tensor<float, 1> vec(6);
26 Tensor<float, 1> result = vec.generate(
Generator1D());
28 for (
int i = 0; i < 6; ++i) {
29 VERIFY_IS_EQUAL(result(i), i);
37 float operator()(
const array<Eigen::DenseIndex, 2>& coordinates)
const {
38 return 3 * coordinates[0] + 11 * coordinates[1];
42 template <
int DataLayout>
45 Tensor<float, 2> matrix(5, 7);
46 Tensor<float, 2> result = matrix.generate(
Generator2D());
48 for (
int i = 0; i < 5; ++i) {
49 for (
int j = 0; j < 5; ++j) {
50 VERIFY_IS_EQUAL(result(i, j), 3*i + 11*j);
56 template <
int DataLayout>
61 array<float, 2> means;
62 means[0] = rows / 2.0f;
63 means[1] = cols / 2.0f;
64 array<float, 2> std_devs;
67 internal::GaussianGenerator<float, Eigen::DenseIndex, 2> gaussian_gen(means, std_devs);
69 Tensor<float, 2> matrix(rows, cols);
70 Tensor<float, 2> result = matrix.generate(gaussian_gen);
72 for (
int i = 0; i < rows; ++i) {
73 for (
int j = 0; j < cols; ++j) {
74 float g_rows = powf(rows/2.0
f - i, 2) / (3.14f * 3.14f) * 0.5
f;
75 float g_cols = powf(cols/2.0
f - j, 2) / (2.7f * 2.7f) * 0.5
f;
76 float gaussian = expf(-g_rows - g_cols);
77 VERIFY_IS_EQUAL(result(i, j), gaussian);
85 CALL_SUBTEST(test_1D<ColMajor>());
86 CALL_SUBTEST(test_1D<RowMajor>());
87 CALL_SUBTEST(test_2D<ColMajor>());
88 CALL_SUBTEST(test_2D<RowMajor>());
89 CALL_SUBTEST(test_gaussian<ColMajor>());
90 CALL_SUBTEST(test_gaussian<RowMajor>());
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
static void test_gaussian()
float operator()(const array< Eigen::DenseIndex, 2 > &coordinates) const
void test_cxx11_tensor_generator()
float operator()(const array< Eigen::DenseIndex, 1 > &coordinates) const