diff options
author | Benoit Steiner <benoit.steiner.goog@gmail.com> | 2015-02-27 12:57:13 -0800 |
---|---|---|
committer | Benoit Steiner <benoit.steiner.goog@gmail.com> | 2015-02-27 12:57:13 -0800 |
commit | 2386fc8528fa8f923b0300af6ddc4cd46a178afd (patch) | |
tree | 4ad32d535ce9e8874ac9bd8a6e16ff7da0f02118 /unsupported/test/cxx11_tensor_mixed_indices.cpp | |
parent | 05089aba75f8bf1ab3d1bfd566decfc08ce729f9 (diff) |
Added support for 32bit index on a per tensor/tensor expression. This enables us to use 32bit indices to evaluate expressions on GPU faster while keeping the ability to use 64 bit indices to manipulate large tensors on CPU in the same binary.
Diffstat (limited to 'unsupported/test/cxx11_tensor_mixed_indices.cpp')
-rw-r--r-- | unsupported/test/cxx11_tensor_mixed_indices.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/unsupported/test/cxx11_tensor_mixed_indices.cpp b/unsupported/test/cxx11_tensor_mixed_indices.cpp new file mode 100644 index 000000000..8a12f9207 --- /dev/null +++ b/unsupported/test/cxx11_tensor_mixed_indices.cpp @@ -0,0 +1,55 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "main.h" + +#include <Eigen/CXX11/Tensor> + +using Eigen::Tensor; +using Eigen::RowMajor; + +static void test_simple() +{ + Tensor<float, 1> vec1({6}); + Tensor<float, 1, Index32Bit> vec2({6}); + + vec1(0) = 4.0; vec2(0) = 0.0; + vec1(1) = 8.0; vec2(1) = 1.0; + vec1(2) = 15.0; vec2(2) = 2.0; + vec1(3) = 16.0; vec2(3) = 3.0; + vec1(4) = 23.0; vec2(4) = 4.0; + vec1(5) = 42.0; vec2(5) = 5.0; + + float data3[6]; + TensorMap<Tensor<float, 1>> vec3(data3, 6); + vec3 = vec1.sqrt(); + float data4[6]; + TensorMap<Tensor<float, 1, Index32Bit>> vec4(data4, 6); + vec4 = vec2.square(); + + VERIFY_IS_APPROX(vec3(0), sqrtf(4.0)); + VERIFY_IS_APPROX(vec3(1), sqrtf(8.0)); + VERIFY_IS_APPROX(vec3(2), sqrtf(15.0)); + VERIFY_IS_APPROX(vec3(3), sqrtf(16.0)); + VERIFY_IS_APPROX(vec3(4), sqrtf(23.0)); + VERIFY_IS_APPROX(vec3(5), sqrtf(42.0)); + + VERIFY_IS_APPROX(vec4(0), 0.0f); + VERIFY_IS_APPROX(vec4(1), 1.0f); + VERIFY_IS_APPROX(vec4(2), 2.0f * 2.0f); + VERIFY_IS_APPROX(vec4(3), 3.0f * 3.0f); + VERIFY_IS_APPROX(vec4(4), 4.0f * 4.0f); + VERIFY_IS_APPROX(vec4(5), 5.0f * 5.0f); +} + + +void test_cxx11_tensor_mixed_indices() +{ + CALL_SUBTEST(test_simple()); +} |