cxx11_tensor_random.cpp File Reference
#include "main.h"
#include <Eigen/CXX11/Tensor>

Classes

struct  MyGenerator
 

Functions

template<typename Scalar >
static void test_default ()
 
template<typename Scalar >
static void test_normal ()
 
static void test_custom ()
 
 EIGEN_DECLARE_TEST (cxx11_tensor_random)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( cxx11_tensor_random  )
70  {
71  CALL_SUBTEST((test_default<float>()));
72  CALL_SUBTEST((test_normal<float>()));
73  CALL_SUBTEST((test_default<double>()));
74  CALL_SUBTEST((test_normal<double>()));
75  CALL_SUBTEST((test_default<Eigen::half>()));
76  CALL_SUBTEST((test_normal<Eigen::half>()));
77  CALL_SUBTEST((test_default<Eigen::bfloat16>()));
78  CALL_SUBTEST((test_normal<Eigen::bfloat16>()));
80 }
static void test_custom()
Definition: cxx11_tensor_random.cpp:61
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST, and test_custom().

◆ test_custom()

static void test_custom ( )
static
61  {
62  Tensor<int, 1> vec(6);
63  vec.setRandom<MyGenerator>();
64 
65  for (int i = 0; i < 6; ++i) {
66  VERIFY_IS_EQUAL(vec(i), 3 * i);
67  }
68 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
The tensor class.
Definition: Tensor.h:68
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
Definition: cxx11_tensor_random.cpp:38

References i, Eigen::TensorBase< Derived, AccessLevel >::setRandom(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_default()

template<typename Scalar >
static void test_default ( )
static
15  {
16  Tensor<Scalar, 1> vec(6);
17  vec.setRandom();
18 
19  // Fixme: we should check that the generated numbers follow a uniform
20  // distribution instead.
21  for (int i = 1; i < 6; ++i) {
22  VERIFY_IS_NOT_EQUAL(vec(i), vec(i - 1));
23  }
24 }
#define VERIFY_IS_NOT_EQUAL(a, b)
Definition: main.h:368

References i, Eigen::TensorBase< Derived, AccessLevel >::setRandom(), and VERIFY_IS_NOT_EQUAL.

◆ test_normal()

template<typename Scalar >
static void test_normal ( )
static
27  {
28  Tensor<Scalar, 1> vec(6);
29  vec.template setRandom<Eigen::internal::NormalRandomGenerator<Scalar>>();
30 
31  // Fixme: we should check that the generated numbers follow a gaussian
32  // distribution instead.
33  for (int i = 1; i < 6; ++i) {
34  VERIFY_IS_NOT_EQUAL(vec(i), vec(i - 1));
35  }
36 }

References i, and VERIFY_IS_NOT_EQUAL.