mirror of https://github.com/commaai/tinygrad.git
test dtype.min and dtype.max (#5479)
compared with np.iinfo for integer dtype
This commit is contained in:
parent
a9f5a764dc
commit
f8a47608cc
|
@ -347,6 +347,20 @@ class TestHelpers(unittest.TestCase):
|
||||||
with self.assertRaises(RuntimeError): dtypes.from_py({})
|
with self.assertRaises(RuntimeError): dtypes.from_py({})
|
||||||
with self.assertRaises(RuntimeError): dtypes.from_py(set())
|
with self.assertRaises(RuntimeError): dtypes.from_py(set())
|
||||||
|
|
||||||
|
def test_dtype_range(self):
|
||||||
|
for dt in core_dtypes:
|
||||||
|
if dtypes.is_float(dt):
|
||||||
|
np.testing.assert_equal(dtypes.min(dt), -math.inf)
|
||||||
|
np.testing.assert_equal(dtypes.max(dt), math.inf)
|
||||||
|
elif dtypes.is_int(dt):
|
||||||
|
info = np.iinfo(_to_np_dtype(dt))
|
||||||
|
np.testing.assert_equal(dtypes.min(dt), info.min)
|
||||||
|
np.testing.assert_equal(dtypes.max(dt), info.max)
|
||||||
|
else:
|
||||||
|
assert dt == dtypes.bool, dt
|
||||||
|
np.testing.assert_equal(dtypes.min(dt), False)
|
||||||
|
np.testing.assert_equal(dtypes.max(dt), True)
|
||||||
|
|
||||||
class TestTypeSpec(unittest.TestCase):
|
class TestTypeSpec(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.old_default_int, self.old_default_float = dtypes.default_int, dtypes.default_float
|
self.old_default_int, self.old_default_float = dtypes.default_int, dtypes.default_float
|
||||||
|
|
Loading…
Reference in New Issue