16 #define VERIFY_BFLOAT16_BITS_EQUAL(h, bits) \ 17 VERIFY_IS_EQUAL((numext::bit_cast<numext::uint16_t>(h)), (static_cast<numext::uint16_t>(bits))) 29 uint32_t src = (sign << 31) + (exponent << 23) + (high_mantissa << 16) + low_mantissa;
30 memcpy(static_cast<void*>(&dest),
31 static_cast<const void*>(&src),
sizeof(dest));
38 VERIFY_IS_EQUAL((internal::cast<bfloat16,T>(internal::cast<T,bfloat16>(-std::numeric_limits<T>::infinity()))), -std::numeric_limits<T>::infinity());
39 VERIFY_IS_EQUAL((internal::cast<bfloat16,T>(internal::cast<T,bfloat16>(std::numeric_limits<T>::infinity()))), std::numeric_limits<T>::infinity());
40 VERIFY_IS_EQUAL((internal::cast<bfloat16,T>(internal::cast<T,bfloat16>(
T(-1.0)))),
T(-1.0));
41 VERIFY_IS_EQUAL((internal::cast<bfloat16,T>(internal::cast<T,bfloat16>(
T(-0.5)))),
T(-0.5));
42 VERIFY_IS_EQUAL((internal::cast<bfloat16,T>(internal::cast<T,bfloat16>(
T(-0.0)))),
T(-0.0));
43 VERIFY_IS_EQUAL((internal::cast<bfloat16,T>(internal::cast<T,bfloat16>(
T(1.0)))),
T(1.0));
44 VERIFY_IS_EQUAL((internal::cast<bfloat16,T>(internal::cast<T,bfloat16>(
T(0.5)))),
T(0.5));
45 VERIFY_IS_EQUAL((internal::cast<bfloat16,T>(internal::cast<T,bfloat16>(
T(0.0)))),
T(0.0));
54 numext::bit_cast<bfloat16>(numext::bit_cast<numext::uint16_t>(
bfloat16(1.0
f))),
57 numext::bit_cast<bfloat16>(numext::bit_cast<numext::uint16_t>(
bfloat16(0.5
f))),
60 numext::bit_cast<bfloat16>(numext::bit_cast<numext::uint16_t>(
bfloat16(-0.33333
f))),
63 numext::bit_cast<bfloat16>(numext::bit_cast<numext::uint16_t>(
bfloat16(0.0
f))),
74 float val1 =
static_cast<float>(
bfloat16(__bfloat16_raw(0x3c00)));
75 float val2 =
static_cast<float>(
bfloat16(__bfloat16_raw(0x3c01)));
76 float val3 =
static_cast<float>(
bfloat16(__bfloat16_raw(0x3c02)));
117 test_roundtrip<float>();
118 test_roundtrip<double>();
119 test_roundtrip<std::complex<float> >();
120 test_roundtrip<std::complex<double> >();
124 for (
int i = 0;
i < 100;
i++)
a(
i) =
i + 1.25;
127 for (
int i = 0;
i < 100; ++
i) {
178 std::cout <<
"denorm min = " << (std::numeric_limits<bfloat16>::denorm_min)() <<
" (0x" << std::hex << numext::bit_cast<numext::uint16_t>((std::numeric_limits<bfloat16>::denorm_min)()) <<
")" << std::endl;
181 std::cout <<
"signaling nan = " << std::numeric_limits<bfloat16>::signaling_NaN() <<
" (0x" << std::hex << numext::bit_cast<numext::uint16_t>(std::numeric_limits<bfloat16>::signaling_NaN()) <<
")" << std::endl;
186 numext::bit_cast<numext::uint16_t>(std::numeric_limits<bfloat16>::infinity()),
187 numext::bit_cast<numext::uint16_t>(
bfloat16(std::numeric_limits<float>::infinity())) );
195 && ((numext::bit_cast<numext::uint16_t>(std::numeric_limits<bfloat16>::quiet_NaN()) & BFLOAT16_QUIET_BIT) > 0)
196 && ((numext::bit_cast<numext::uint16_t>(
bfloat16(std::numeric_limits<float>::quiet_NaN())) & BFLOAT16_QUIET_BIT) > 0) );
201 (
numext::isnan)(std::numeric_limits<bfloat16>::signaling_NaN())
203 && ((numext::bit_cast<numext::uint16_t>(std::numeric_limits<bfloat16>::signaling_NaN()) & BFLOAT16_QUIET_BIT) == 0) );
206 VERIFY( (std::numeric_limits<bfloat16>::denorm_min)() >
bfloat16(0.
f) );
334 Index size = internal::random<Index>(1,10);
335 Index i = internal::random<Index>(0,size-1);
336 ArrayXh
a1 = ArrayXh::Random(size),
a2 = ArrayXh::Random(size);
341 VERIFY( ((a1.min)(
a2) <= (a1.max)(
a2)).all() );
347 std::stringstream
ss;
357 MatrixXh Ah = MatrixXh::Random(rows,depth);
358 MatrixXh Bh = MatrixXh::Random(depth,cols);
359 MatrixXh Ch = MatrixXh::Random(rows,cols);
360 MatrixXf Af = Ah.cast<
float>();
361 MatrixXf Bf = Bh.cast<
float>();
362 MatrixXf Cf = Ch.cast<
float>();
363 VERIFY_IS_APPROX(Ch.noalias()+=Ah*Bh, (Cf.noalias()+=Af*Bf).cast<bfloat16>());
EIGEN_DEVICE_FUNC const Log1pReturnType log1p() const
void test_basic_functions()
Jet< T, N > cos(const Jet< T, N > &f)
static const Eigen::internal::all_t all
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T exp(const T &x)
Jet< T, N > sin(const Jet< T, N > &f)
Namespace containing all symbols from the Eigen library.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T cos(const T &x)
EIGEN_DEVICE_FUNC const LogReturnType log() const
EIGEN_DEVICE_FUNC T() ceil(const T &x)
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
EIGEN_DEVICE_FUNC const FloorReturnType floor() const
#define VERIFY_IS_APPROX(a, b)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE internal::enable_if< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real >::type abs(const T &x)
#define VERIFY_IS_EQUAL(a, b)
EIGEN_DEVICE_FUNC const Expm1ReturnType expm1() const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T tan(const T &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
EIGEN_DEVICE_FUNC const SignReturnType sign() const
Eigen::Triplet< double > T
EIGEN_DEVICE_FUNC T() floor(const T &x)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
#define VERIFY_BFLOAT16_BITS_EQUAL(h, bits)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T sin(const T &x)
float BinaryToFloat(uint32_t sign, uint32_t exponent, uint32_t high_mantissa, uint32_t low_mantissa)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool() isinf(const Eigen::bfloat16 &h)
EIGEN_DECLARE_TEST(bfloat16_float)
static std::stringstream ss
EIGEN_DEVICE_FUNC internal::pow_impl< ScalarX, ScalarY >::result_type pow(const ScalarX &x, const ScalarY &y)
void test_trigonometric_functions()
#define CALL_SUBTEST(FUNC)
#define EIGEN_TEST_MAX_SIZE
EIGEN_DEVICE_FUNC const TanReturnType tan() const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool() isnan(const Eigen::bfloat16 &h)
General-purpose arrays with easy API for coefficient-wise operations.
Jet< T, N > sqrt(const Jet< T, N > &f)
Jet< T, N > pow(const Jet< T, N > &f, double g)
The matrix class, also used for vectors and row-vectors.
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T log(const T &x)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float sqrt(const float &x)
EIGEN_DEVICE_FUNC const CeilReturnType ceil() const