13 #include <Eigen/CXX11/Tensor> 17 template <
int DataLayout>
35 for (
int i = 0;
i < 7; ++
i) {
48 for (
int i = 0;
i < 2; ++
i) {
49 for (
int j = 0;
j < 3; ++
j) {
56 template <
typename Scalar,
int DataLayout>
61 tensor += tensor.constant(
Scalar(0.5
f));
63 reduction_axis2[0] = 1;
64 reduction_axis2[1] = 3;
69 for (
int i = 0;
i < 2; ++
i) {
70 for (
int j = 0;
j < 5; ++
j) {
72 for (
int k = 0; k < 3; ++k) {
73 for (
int l = 0;
l < 7; ++
l) {
74 sum += tensor(
i, k,
j,
l);
86 reduction_axis4[0] = 0;
87 reduction_axis4[1] = 1;
88 reduction_axis4[2] = 2;
89 reduction_axis4[3] = 3;
96 reduction_axis2[0] = 0;
97 reduction_axis2[1] = 2;
98 result = tensor.prod(reduction_axis2);
101 for (
int i = 0;
i < 3; ++
i) {
102 for (
int j = 0;
j < 7; ++
j) {
104 for (
int k = 0; k < 2; ++k) {
105 for (
int l = 0;
l < 5; ++
l) {
106 prod *= tensor(k,
i,
l,
j);
118 reduction_axis4[0] = 0;
119 reduction_axis4[1] = 1;
120 reduction_axis4[2] = 2;
121 reduction_axis4[3] = 3;
128 reduction_axis2[0] = 0;
129 reduction_axis2[1] = 2;
130 result = tensor.maximum(reduction_axis2);
133 for (
int i = 0;
i < 3; ++
i) {
134 for (
int j = 0;
j < 7; ++
j) {
135 Scalar max_val = std::numeric_limits<Scalar>::lowest();
136 for (
int k = 0; k < 2; ++k) {
137 for (
int l = 0;
l < 5; ++
l) {
150 reduction_axis4[0] = 0;
151 reduction_axis4[1] = 1;
152 reduction_axis4[2] = 2;
153 reduction_axis4[3] = 3;
160 reduction_axis2[0] = 0;
161 reduction_axis2[1] = 1;
162 result = tensor.minimum(reduction_axis2);
165 for (
int i = 0;
i < 5; ++
i) {
166 for (
int j = 0;
j < 7; ++
j) {
168 for (
int k = 0; k < 2; ++k) {
169 for (
int l = 0;
l < 3; ++
l) {
182 reduction_axis4[0] = 0;
183 reduction_axis4[1] = 1;
184 reduction_axis4[2] = 2;
185 reduction_axis4[3] = 3;
192 reduction_axis2[0] = 0;
193 reduction_axis2[1] = 1;
194 result = tensor.mean(reduction_axis2);
197 for (
int i = 0;
i < 5; ++
i) {
198 for (
int j = 0;
j < 7; ++
j) {
201 for (
int k = 0; k < 2; ++k) {
202 for (
int l = 0;
l < 3; ++
l) {
203 sum += tensor(k,
l,
i,
j);
216 reduction_axis4[0] = 0;
217 reduction_axis4[1] = 1;
218 reduction_axis4[2] = 2;
219 reduction_axis4[3] = 3;
233 all_ = (ints >= ints.constant(0)).
all();
237 any = (ints > ints.constant(10)).any();
239 any = (ints < ints.constant(1)).any();
245 template <
int DataLayout>
250 reduction_axis2[0] = 1;
251 reduction_axis2[1] = 3;
254 result = result.constant(1.0
f) - tensor.sum(reduction_axis2);
257 for (
int i = 0;
i < 2; ++
i) {
258 for (
int j = 0;
j < 5; ++
j) {
260 for (
int k = 0; k < 3; ++k) {
261 for (
int l = 0;
l < 7; ++
l) {
262 sum += tensor(
i, k,
j,
l);
271 template <
int DataLayout>
276 reduction_axis[0] = 0;
277 reduction_axis[1] = 1;
283 for (
int i = 0;
i < 2; ++
i) {
284 for (
int j = 0;
j < 3; ++
j) {
290 result = tensor.square().sum(reduction_axis).sqrt();
294 for (
int i = 0;
i < 2; ++
i) {
295 for (
int j = 0;
j < 3; ++
j) {
296 sum += tensor(
i,
j) * tensor(
i,
j);
305 void reduce(
const float val,
float* accum) { *accum += val * val; }
313 template <
int DataLayout>
318 reduction_axis[0] = 1;
323 for (
int i = 0;
i < 5; ++
i) {
325 for (
int j = 0;
j < 7; ++
j) {
326 expected += tensor(
i,
j) * tensor(
i,
j);
333 template <
int DataLayout>
335 int inputs[2 * 3 * 5 * 7];
344 reduction_axis[0] = 1;
345 reduction_axis[1] = 3;
350 tensor_map_const_const.sum(reduction_axis);
352 for (
int i = 0;
i < 2; ++
i) {
353 for (
int j = 0;
j < 5; ++
j) {
355 for (
int k = 0; k < 3; ++k) {
356 for (
int l = 0;
l < 7; ++
l) {
357 sum += tensor_map(
i, k,
j,
l);
367 template <
int DataLayout>
373 #if !EIGEN_HAS_CONSTEXPR 375 reduction_axis[0] = 1;
376 reduction_axis[1] = 3;
378 Eigen::IndexList<Eigen::type2index<1>, Eigen::type2index<3> > reduction_axis;
381 out = in.maximum(reduction_axis);
383 for (
int i = 0;
i < 72; ++
i) {
384 for (
int j = 0;
j < 97; ++
j) {
386 for (
int k = 0; k < 53; ++k) {
387 for (
int l = 0;
l < 113; ++
l) {
396 template <
int DataLayout>
403 #if !EIGEN_HAS_CONSTEXPR 405 reduction_axis[0] = 0;
406 reduction_axis[1] = 1;
409 Eigen::IndexList<Eigen::type2index<0>, Eigen::type2index<1> > reduction_axis;
412 out = in.maximum(reduction_axis);
414 for (
int i = 0;
i < 97; ++
i) {
415 for (
int j = 0;
j < 113; ++
j) {
417 for (
int k = 0; k < 53; ++k) {
418 for (
int l = 0;
l < 72; ++
l) {
427 template <
int DataLayout>
434 #if !EIGEN_HAS_CONSTEXPR 436 reduction_axis[0] = 2;
437 reduction_axis[1] = 3;
440 Eigen::IndexList<Eigen::type2index<2>, Eigen::type2index<3>> reduction_axis;
443 out = in.maximum(reduction_axis);
445 for (
int i = 0;
i < 72; ++
i) {
446 for (
int j = 0;
j < 53; ++
j) {
448 for (
int k = 0; k < 97; ++k) {
449 for (
int l = 0;
l < 113; ++
l) {
458 template <
int DataLayout>
465 #if !EIGEN_HAS_CONSTEXPR 467 reduction_axis[0] = 1;
468 reduction_axis[1] = 2;
471 Eigen::IndexList<Eigen::type2index<1>, Eigen::type2index<2>> reduction_axis;
474 out = in.maximum(reduction_axis);
476 for (
int i = 0;
i < 72; ++
i) {
477 for (
int j = 0;
j < 113; ++
j) {
479 for (
int k = 0; k < 53; ++k) {
480 for (
int l = 0;
l < 97; ++
l) {
491 for (
float prescribed_mean : {1.0f, 10.0f, 100.0f, 1000.0f, 10000.0f}) {
493 tensor += tensor.constant(prescribed_mean);
496 double expected_sum = 0.0;
497 for (
int i = 0;
i < 101; ++
i) {
498 for (
int j = 0;
j < 101; ++
j) {
499 for (
int k = 0; k < 101; ++k) {
500 expected_sum +=
static_cast<double>(tensor(
i,
j, k));
511 CALL_SUBTEST(( test_simple_reductions<float,ColMajor>() ));
512 CALL_SUBTEST(( test_simple_reductions<float,RowMajor>() ));
513 CALL_SUBTEST(( test_simple_reductions<Eigen::half,ColMajor>() ));
514 CALL_SUBTEST(( test_simple_reductions<Eigen::bfloat16,ColMajor>() ));
static void test_trivial_reductions()
static void test_reductions_in_expr()
static const Eigen::internal::all_t all
static void test_tensor_maps()
std::ofstream out("Result.txt")
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate offset
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const
#define VERIFY_IS_APPROX(a, b)
static const Line3 l(Rot3(), 1, 1)
#define VERIFY_IS_EQUAL(a, b)
A tensor expression mapping an existing array of data.
static void test_sum_accuracy()
static void test_innermost_last_dims()
static void test_full_reductions()
EIGEN_DONT_INLINE void prod(const Lhs &a, const Rhs &b, Res &c)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
The fixed sized version of the tensor class.
EIGEN_DECLARE_TEST(cxx11_tensor_reduction)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
void reduce(const float val, float *accum)
static const bool PacketAccess
#define CALL_SUBTEST(FUNC)
UserReducer(float offset)
static void test_innermost_first_dims()
static void test_static_dims()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
static void test_reduce_middle_dims()
float finalize(const float accum) const
static void test_user_defined_reductions()
static void test_simple_reductions()