13 #include <Eigen/CXX11/Tensor>
21 ftensor = ftensor.random() * 100.f;
27 chartensor = ftensor.cast<
char>();
28 cplextensor = ftensor.cast<std::complex<float> >();
30 for (
int i = 0;
i < 20; ++
i) {
31 for (
int j = 0;
j < 30; ++
j) {
42 itensor = itensor.random() / 1000;
48 ftensor = itensor.cast<
float>();
49 dtensor = itensor.cast<
double>();
51 for (
int i = 0;
i < 20; ++
i) {
52 for (
int j = 0;
j < 30; ++
j) {
63 ftensor = ftensor.random() * 1000.0f;
65 dtensor = dtensor.random() * 1000.0;
70 for (
int i = 0;
i < 20; ++
i) {
71 for (
int j = 0;
j < 30; ++
j) {
84 ftensor = dtensor.cast<
float>();
86 for (
int i = 0;
i < 20; ++
i) {
87 for (
int j = 0;
j < 30; ++
j) {
99 dtensor = ftensor.cast<
double>();
101 for (
int i = 0;
i < 20; ++
i) {
102 for (
int j = 0;
j < 30; ++
j) {
108 template <
typename FromType,
typename ToType>
112 for (
int i = 0;
i < 100; ++
i) {
113 for (
int j = 0;
j < 200; ++
j) {
119 ttensor = ftensor.template cast<ToType>();
121 for (
int i = 0;
i < 100; ++
i) {
122 for (
int j = 0;
j < 200; ++
j) {
123 const ToType
ref = internal::cast<FromType,ToType>(ftensor(
i,
j));
129 template<
typename Scalar,
typename EnableIf =
void>
132 test_type_cast<Scalar, bool>();
133 test_type_cast<Scalar, int8_t>();
134 test_type_cast<Scalar, int16_t>();
135 test_type_cast<Scalar, int32_t>();
136 test_type_cast<Scalar, int64_t>();
137 test_type_cast<Scalar, uint8_t>();
138 test_type_cast<Scalar, uint16_t>();
139 test_type_cast<Scalar, uint32_t>();
140 test_type_cast<Scalar, uint64_t>();
141 test_type_cast<Scalar, half>();
142 test_type_cast<Scalar, bfloat16>();
143 test_type_cast<Scalar, float>();
144 test_type_cast<Scalar, double>();
145 test_type_cast<Scalar, std::complex<float>>();
146 test_type_cast<Scalar, std::complex<double>>();
151 template<
typename Scalar>
154 test_type_cast<Scalar, half>();
155 test_type_cast<Scalar, bfloat16>();
156 test_type_cast<Scalar, std::complex<float>>();
157 test_type_cast<Scalar, std::complex<double>>();