3
3
4
4
import numpy as np
5
5
6
- from ..casting import (float_to_int , as_int , int_clippers , CastingError ,
7
- int_to_float )
6
+ from ..casting import (float_to_int , shared_range , CastingError , int_to_float ,
7
+ as_int )
8
8
9
9
from numpy .testing import (assert_array_almost_equal , assert_array_equal )
10
10
11
11
from nose .tools import (assert_true , assert_equal , assert_raises )
12
12
13
13
14
- def test_int_clippers ():
14
+ def test_shared_range ():
15
15
for ft in np .sctypes ['float' ]:
16
16
for it in np .sctypes ['int' ] + np .sctypes ['uint' ]:
17
17
# Test that going a bit above or below the calculated min and max
18
18
# either generates the same number when cast, or the max int value
19
19
# (if this system generates that) or something smaller (because of
20
20
# overflow)
21
- mn , mx = int_clippers (ft , it )
21
+ mn , mx = shared_range (ft , it )
22
22
ovs = ft (mx ) + np .arange (2048 , dtype = ft )
23
23
# Float16 can overflow to inf
24
24
bit_bigger = ovs [np .isfinite (ovs )].astype (it )
25
25
casted_mx = ft (mx ).astype (it )
26
26
imax = int (np .iinfo (it ).max )
27
27
thresh_overflow = False
28
28
if casted_mx != imax :
29
- # The int_clippers have told us that they believe the imax does
29
+ # The shared_range have told us that they believe the imax does
30
30
# not have an exact representation.
31
31
fimax = int_to_float (imax , ft )
32
32
if np .isfinite (fimax ):
@@ -53,7 +53,7 @@ def test_int_clippers():
53
53
casted_mn = ft (mn ).astype (it )
54
54
imin = int (np .iinfo (it ).min )
55
55
if casted_mn != imin :
56
- # The int_clippers have told us that they believe the imin does
56
+ # The shared_range have told us that they believe the imin does
57
57
# not have an exact representation.
58
58
fimin = int_to_float (imin , ft )
59
59
if np .isfinite (fimin ):
@@ -72,6 +72,13 @@ def test_int_clippers():
72
72
assert_true (np .all ((bit_smaller >= casted_mn )))
73
73
74
74
75
+ def test_shared_range_inputs ():
76
+ # Check any dtype specifier will work as input
77
+ rng0 = shared_range (np .float32 , np .int32 )
78
+ assert_array_equal (rng0 , shared_range ('f4' , 'i4' ))
79
+ assert_array_equal (rng0 , shared_range (np .dtype ('f4' ), np .dtype ('i4' )))
80
+
81
+
75
82
def test_casting ():
76
83
for ft in np .sctypes ['float' ]:
77
84
for it in np .sctypes ['int' ] + np .sctypes ['uint' ]:
@@ -80,7 +87,7 @@ def test_casting():
80
87
farr_orig = np .array (arr , dtype = ft )
81
88
# We're later going to test if we modify this array
82
89
farr = farr_orig .copy ()
83
- mn , mx = int_clippers (ft , it )
90
+ mn , mx = shared_range (ft , it )
84
91
iarr = float_to_int (farr , it )
85
92
# Dammit - for long doubles we need to jump through some hoops not
86
93
# to round to numbers outside the range
0 commit comments