12 #include <Eigen/CXX11/Tensor> 20 ftensor = ftensor.random() * 100.f;
26 chartensor = ftensor.cast<
char>();
27 cplextensor = ftensor.cast<std::complex<float> >();
29 for (
int i = 0; i < 20; ++i) {
30 for (
int j = 0; j < 30; ++j) {
31 VERIFY_IS_EQUAL(chartensor(i,j), static_cast<char>(ftensor(i,j)));
32 VERIFY_IS_EQUAL(cplextensor(i,j),
static_cast<std::complex<float>
>(ftensor(i,j)));
41 itensor = itensor.random() / 1000;
47 ftensor = itensor.cast<
float>();
48 dtensor = itensor.cast<
double>();
50 for (
int i = 0; i < 20; ++i) {
51 for (
int j = 0; j < 30; ++j) {
52 VERIFY_IS_EQUAL(itensor(i,j), static_cast<int>(ftensor(i,j)));
53 VERIFY_IS_EQUAL(dtensor(i,j), static_cast<double>(ftensor(i,j)));
62 ftensor = ftensor.random() * 1000.0f;
64 dtensor = dtensor.random() * 1000.0;
69 for (
int i = 0; i < 20; ++i) {
70 for (
int j = 0; j < 30; ++j) {
71 VERIFY_IS_EQUAL(i1tensor(i,j), static_cast<int>(ftensor(i,j)));
72 VERIFY_IS_EQUAL(i2tensor(i,j), static_cast<int>(dtensor(i,j)));
83 ftensor = dtensor.cast<
float>();
85 for (
int i = 0; i < 20; ++i) {
86 for (
int j = 0; j < 30; ++j) {
87 VERIFY_IS_APPROX(dtensor(i,j), static_cast<double>(ftensor(i,j)));
98 dtensor = ftensor.cast<
double>();
100 for (
int i = 0; i < 20; ++i) {
101 for (
int j = 0; j < 30; ++j) {
102 VERIFY_IS_APPROX(dtensor(i,j), static_cast<double>(ftensor(i,j)));
void test_cxx11_tensor_casts()
static void test_simple_cast()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
static void test_vectorized_cast()
static void test_small_to_big_type_cast()
static void test_big_to_small_type_cast()
static void test_float_to_int_cast()