mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-14 04:35:57 +08:00
Fix half_float unit test wrt previous changeset
This commit is contained in:
parent
6eb4ce5f8e
commit
8180e13926
@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
#include <Eigen/src/Core/arch/CUDA/Half.h>
|
#include <Eigen/src/Core/arch/CUDA/Half.h>
|
||||||
|
|
||||||
|
#ifdef EIGEN_HAS_CUDA_FP16
|
||||||
|
#error "EIGEN_HAS_CUDA_FP16 should not be defined in this CPU unit test"
|
||||||
|
#endif
|
||||||
|
|
||||||
// Make sure it's possible to forward declare Eigen::half
|
// Make sure it's possible to forward declare Eigen::half
|
||||||
namespace Eigen {
|
namespace Eigen {
|
||||||
struct half;
|
struct half;
|
||||||
@ -20,7 +24,7 @@ using Eigen::half;
|
|||||||
|
|
||||||
void test_conversion()
|
void test_conversion()
|
||||||
{
|
{
|
||||||
using Eigen::half_impl::__half;
|
using Eigen::half_impl::__half_raw;
|
||||||
|
|
||||||
// Conversion from float.
|
// Conversion from float.
|
||||||
VERIFY_IS_EQUAL(half(1.0f).x, 0x3c00);
|
VERIFY_IS_EQUAL(half(1.0f).x, 0x3c00);
|
||||||
@ -37,9 +41,9 @@ void test_conversion()
|
|||||||
VERIFY_IS_EQUAL(half(1.19209e-07f).x, 0x0002);
|
VERIFY_IS_EQUAL(half(1.19209e-07f).x, 0x0002);
|
||||||
|
|
||||||
// Verify round-to-nearest-even behavior.
|
// Verify round-to-nearest-even behavior.
|
||||||
float val1 = float(half(__half(0x3c00)));
|
float val1 = float(half(__half_raw(0x3c00)));
|
||||||
float val2 = float(half(__half(0x3c01)));
|
float val2 = float(half(__half_raw(0x3c01)));
|
||||||
float val3 = float(half(__half(0x3c02)));
|
float val3 = float(half(__half_raw(0x3c02)));
|
||||||
VERIFY_IS_EQUAL(half(0.5f * (val1 + val2)).x, 0x3c00);
|
VERIFY_IS_EQUAL(half(0.5f * (val1 + val2)).x, 0x3c00);
|
||||||
VERIFY_IS_EQUAL(half(0.5f * (val2 + val3)).x, 0x3c02);
|
VERIFY_IS_EQUAL(half(0.5f * (val2 + val3)).x, 0x3c02);
|
||||||
|
|
||||||
@ -55,21 +59,21 @@ void test_conversion()
|
|||||||
VERIFY_IS_EQUAL(half(true).x, 0x3c00);
|
VERIFY_IS_EQUAL(half(true).x, 0x3c00);
|
||||||
|
|
||||||
// Conversion to float.
|
// Conversion to float.
|
||||||
VERIFY_IS_EQUAL(float(half(__half(0x0000))), 0.0f);
|
VERIFY_IS_EQUAL(float(half(__half_raw(0x0000))), 0.0f);
|
||||||
VERIFY_IS_EQUAL(float(half(__half(0x3c00))), 1.0f);
|
VERIFY_IS_EQUAL(float(half(__half_raw(0x3c00))), 1.0f);
|
||||||
|
|
||||||
// Denormals.
|
// Denormals.
|
||||||
VERIFY_IS_APPROX(float(half(__half(0x8001))), -5.96046e-08f);
|
VERIFY_IS_APPROX(float(half(__half_raw(0x8001))), -5.96046e-08f);
|
||||||
VERIFY_IS_APPROX(float(half(__half(0x0001))), 5.96046e-08f);
|
VERIFY_IS_APPROX(float(half(__half_raw(0x0001))), 5.96046e-08f);
|
||||||
VERIFY_IS_APPROX(float(half(__half(0x0002))), 1.19209e-07f);
|
VERIFY_IS_APPROX(float(half(__half_raw(0x0002))), 1.19209e-07f);
|
||||||
|
|
||||||
// NaNs and infinities.
|
// NaNs and infinities.
|
||||||
VERIFY(!(numext::isinf)(float(half(65504.0f)))); // Largest finite number.
|
VERIFY(!(numext::isinf)(float(half(65504.0f)))); // Largest finite number.
|
||||||
VERIFY(!(numext::isnan)(float(half(0.0f))));
|
VERIFY(!(numext::isnan)(float(half(0.0f))));
|
||||||
VERIFY((numext::isinf)(float(half(__half(0xfc00)))));
|
VERIFY((numext::isinf)(float(half(__half_raw(0xfc00)))));
|
||||||
VERIFY((numext::isnan)(float(half(__half(0xfc01)))));
|
VERIFY((numext::isnan)(float(half(__half_raw(0xfc01)))));
|
||||||
VERIFY((numext::isinf)(float(half(__half(0x7c00)))));
|
VERIFY((numext::isinf)(float(half(__half_raw(0x7c00)))));
|
||||||
VERIFY((numext::isnan)(float(half(__half(0x7c01)))));
|
VERIFY((numext::isnan)(float(half(__half_raw(0x7c01)))));
|
||||||
|
|
||||||
#if !EIGEN_COMP_MSVC
|
#if !EIGEN_COMP_MSVC
|
||||||
// Visual Studio errors out on divisions by 0
|
// Visual Studio errors out on divisions by 0
|
||||||
@ -79,12 +83,12 @@ void test_conversion()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Exactly same checks as above, just directly on the half representation.
|
// Exactly same checks as above, just directly on the half representation.
|
||||||
VERIFY(!(numext::isinf)(half(__half(0x7bff))));
|
VERIFY(!(numext::isinf)(half(__half_raw(0x7bff))));
|
||||||
VERIFY(!(numext::isnan)(half(__half(0x0000))));
|
VERIFY(!(numext::isnan)(half(__half_raw(0x0000))));
|
||||||
VERIFY((numext::isinf)(half(__half(0xfc00))));
|
VERIFY((numext::isinf)(half(__half_raw(0xfc00))));
|
||||||
VERIFY((numext::isnan)(half(__half(0xfc01))));
|
VERIFY((numext::isnan)(half(__half_raw(0xfc01))));
|
||||||
VERIFY((numext::isinf)(half(__half(0x7c00))));
|
VERIFY((numext::isinf)(half(__half_raw(0x7c00))));
|
||||||
VERIFY((numext::isnan)(half(__half(0x7c01))));
|
VERIFY((numext::isnan)(half(__half_raw(0x7c01))));
|
||||||
|
|
||||||
#if !EIGEN_COMP_MSVC
|
#if !EIGEN_COMP_MSVC
|
||||||
// Visual Studio errors out on divisions by 0
|
// Visual Studio errors out on divisions by 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user