@@ -147,62 +147,58 @@ def test_can_cast(_from, to):
147
147
assert out == expected , f"{ out = } , but should be { expected } { f_func } "
148
148
149
149
150
- @pytest .mark .parametrize ("arg_type" , ["dtype" , "array" ])
151
150
@pytest .mark .parametrize ("dtype" , dh .real_float_dtypes + dh .complex_dtypes )
152
- def test_finfo (dtype , arg_type ):
153
- arg = xp .asarray (1 , dtype = dtype ) if arg_type == "array" else dtype
154
- out = xp .finfo (arg )
155
-
156
- f_func = f"[finfo({ dh .dtype_to_name [dtype ]} )]"
157
- for attr , stype in [
158
- ("bits" , int ),
159
- ("eps" , float ),
160
- ("max" , float ),
161
- ("min" , float ),
162
- ("smallest_normal" , float ),
163
- ]:
164
- assert hasattr (out , attr ), f"out has no attribute '{ attr } ' { f_func } "
165
- value = getattr (out , attr )
166
- assert isinstance (
167
- value , stype
168
- ), f"type(out.{ attr } )={ type (value )!r} , but should be { stype .__name__ } { f_func } "
169
- assert hasattr (out , "dtype" ), f"out has no attribute 'dtype' { f_func } "
170
-
171
- assert isinstance (out .bits , int )
172
- assert isinstance (out .eps , float )
173
- assert isinstance (out .max , float )
174
- assert isinstance (out .min , float )
175
- assert isinstance (out .smallest_normal , float )
151
+ def test_finfo (dtype ):
152
+ for arg in (
153
+ dtype ,
154
+ xp .asarray (1 , dtype = dtype ),
155
+ # np.float64 and np.asarray(1, dtype=np.float64).dtype are different
156
+ xp .asarray (1 , dtype = dtype ).dtype ,
157
+ ):
158
+ out = xp .finfo (arg )
159
+ assert isinstance (out .bits , int )
160
+ assert isinstance (out .eps , float )
161
+ assert isinstance (out .max , float )
162
+ assert isinstance (out .min , float )
163
+ assert isinstance (out .smallest_normal , float )
164
+
165
+
166
+ @pytest .mark .min_version ("2022.12" )
167
+ @pytest .mark .parametrize ("dtype" , dh .real_float_dtypes + dh .complex_dtypes )
168
+ def test_finfo_dtype (dtype ):
169
+ out = xp .finfo (dtype )
170
+
176
171
if dtype == xp .complex64 :
177
172
assert out .dtype == xp .float32
178
173
elif dtype == xp .complex128 :
179
174
assert out .dtype == xp .float64
180
175
else :
181
176
assert out .dtype == dtype
177
+
182
178
# Guard vs. numpy.dtype.__eq__ lax comparison
183
179
assert not isinstance (out .dtype , str )
184
180
assert out .dtype is not float
185
181
assert out .dtype is not complex
186
182
187
183
188
- @pytest .mark .parametrize ("arg_type" , ["dtype" , "array" ])
189
184
@pytest .mark .parametrize ("dtype" , dh .int_dtypes + dh .uint_dtypes )
190
- def test_iinfo (dtype , arg_type ):
191
- arg = xp .asarray (1 , dtype = dtype ) if arg_type == "array" else dtype
192
- out = xp .iinfo (arg )
193
-
194
- f_func = f"[iinfo({ dh .dtype_to_name [dtype ]} )]"
195
- for attr in ["bits" , "max" , "min" ]:
196
- assert hasattr (out , attr ), f"out has no attribute '{ attr } ' { f_func } "
197
- value = getattr (out , attr )
198
- assert isinstance (
199
- value , int
200
- ), f"type(out.{ attr } )={ type (value )!r} , but should be int { f_func } "
201
- assert hasattr (out , "dtype" ), f"out has no attribute 'dtype' { f_func } "
202
-
203
- assert isinstance (out .bits , int )
204
- assert isinstance (out .max , int )
205
- assert isinstance (out .min , int )
185
+ def test_iinfo (dtype ):
186
+ for arg in (
187
+ dtype ,
188
+ xp .asarray (1 , dtype = dtype ),
189
+ # np.int64 and np.asarray(1, dtype=np.int64).dtype are different
190
+ xp .asarray (1 , dtype = dtype ).dtype ,
191
+ ):
192
+ out = xp .iinfo (arg )
193
+ assert isinstance (out .bits , int )
194
+ assert isinstance (out .max , int )
195
+ assert isinstance (out .min , int )
196
+
197
+
198
+ @pytest .mark .min_version ("2022.12" )
199
+ @pytest .mark .parametrize ("dtype" , dh .int_dtypes + dh .uint_dtypes )
200
+ def test_iinfo_dtype (dtype ):
201
+ out = xp .iinfo (dtype )
206
202
assert out .dtype == dtype
207
203
# Guard vs. numpy.dtype.__eq__ lax comparison
208
204
assert not isinstance (out .dtype , str )
0 commit comments