@@ -1710,6 +1710,30 @@ def test_sparse(self):
1710
1710
assert_equal (np .nonzero (c )[0 ],
1711
1711
np .concatenate ((np .arange (10 + i , 20 + i ), [20 + i * 2 ])))
1712
1712
1713
+ def test_nonzero_dtypes (self ):
1714
+ rng = np .random .default_rng (seed = 10 )
1715
+ zero_indices = np .arange (50 )
1716
+ sample = ((2 ** 33 )* rng .normal (size = 100 ))
1717
+
1718
+ # test for different dtypes
1719
+ types = [bool , np .int8 , np .int16 , np .int32 , np .int64 , np .float32 , np .float64 ]
1720
+ for dtype in types :
1721
+ x = sample .astype (dtype )
1722
+ rng .shuffle (zero_indices )
1723
+ x [zero_indices ] = 0
1724
+ idxs = np .nonzero (x )[0 ]
1725
+ assert_equal (np .array_equal (np .where (x != 0 )[0 ], idxs ), True )
1726
+
1727
+ unsigned_types = [np .uint8 , np .uint16 , np .uint32 , np .uint64 ]
1728
+ sample = rng .integers (0 , 255 , size = 100 )
1729
+ for dtype in unsigned_types :
1730
+ x = sample .astype (dtype )
1731
+ rng .shuffle (zero_indices )
1732
+ x [zero_indices ] = 0
1733
+ idxs = np .nonzero (x )[0 ]
1734
+ assert_equal (np .array_equal (np .where (x != 0 )[0 ], idxs ), True )
1735
+
1736
+
1713
1737
def test_return_type (self ):
1714
1738
class C (np .ndarray ):
1715
1739
pass
0 commit comments