12 #include <Eigen/CXX11/Tensor> 19 DSizes<DenseIndex, 2> result;
25 template <
typename Output,
typename Device>
28 array<DenseIndex, 2> strides;
31 output.stride(strides).device(device) = input;
35 output.slice(offsets, extents).stride(strides).device(device) = input.constant(0.0
f);
48 for (
int i = 0; i < 6; i+=2) {
49 for (
int j = 0; j < 10; j+=2) {
50 VERIFY_IS_EQUAL(result(i, j), tensor(i/2, j/2));
53 for (
int i = 1; i < 6; i+=2) {
54 for (
int j = 1; j < 10; j+=2) {
55 VERIFY_IS_EQUAL(result(i, j), 0);
63 DSizes<DenseIndex, 3> result;
70 template <
typename Output,
typename Device>
72 Output& output,
const Device& device)
const 75 array<DimPair, 1> dims;
77 for (
int i = 0; i < output.dimension(2); ++i) {
78 output.template chip<2>(i).device(device) = input1.
chip<2>(i).contract(input2.
chip<2>(i), dims);
92 for (
int i = 0; i < 5; ++i) {
94 array<DimPair, 1> dims;
97 TensorRef<Tensor<float, 2> > val = result.
chip<2>(i);
98 for (
int j = 0; j < 2; ++j) {
99 for (
int k = 0; k < 7; ++k) {
100 VERIFY_IS_APPROX(val(j, k), reference(j, k));
DSizes< DenseIndex, 2 > dimensions(const Tensor< float, 2 > &input) const
void eval(const Tensor< float, 3 > &input1, const Tensor< float, 3 > &input2, Output &output, const Device &device) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
static void test_custom_unary_op()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorChippingOp< DimId, const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > > chip(const Index offset) const
Tensor< float, 1 >::DimensionPair DimPair
void eval(const Tensor< float, 2 > &input, Output &output, const Device &device) const
void test_cxx11_tensor_custom_op()
static void test_custom_binary_op()
DSizes< DenseIndex, 3 > dimensions(const Tensor< float, 3 > &input1, const Tensor< float, 3 > &input2) const