@@ -487,24 +487,19 @@ def __call__(self, X, alpha=None, bytes=False):
487
487
xa = xa .byteswap ().newbyteorder ()
488
488
489
489
if xa .dtype .kind == "f" :
490
- # Treat 1.0 as slightly less than 1.
491
- vals = np .array ([1 , 0 ], dtype = xa .dtype )
492
- almost_one = np .nextafter (* vals )
493
- np .copyto (xa , almost_one , where = xa == 1.0 )
494
- # The following clip is fast, and prevents possible
495
- # conversion of large positive values to negative integers.
496
-
497
490
xa *= self .N
491
+ # Negative values are out of range, but astype(int) would truncate
492
+ # them towards zero.
493
+ xa [xa < 0 ] = - 1
494
+ # xa == 1 (== N after multiplication) is not out of range.
495
+ xa [xa == self .N ] = self .N - 1
496
+ # Avoid converting large positive values to negative integers.
498
497
np .clip (xa , - 1 , self .N , out = xa )
499
-
500
- # ensure that all 'under' values will still have negative
501
- # value after casting to int
502
- np .copyto (xa , - 1 , where = xa < 0.0 )
503
498
xa = xa .astype (int )
504
499
# Set the over-range indices before the under-range;
505
500
# otherwise the under-range values get converted to over-range.
506
- np . copyto ( xa , self . _i_over , where = xa > self .N - 1 )
507
- np . copyto ( xa , self . _i_under , where = xa < 0 )
501
+ xa [ xa > self .N - 1 ] = self . _i_over
502
+ xa [ xa < 0 ] = self . _i_under
508
503
if mask_bad is not None :
509
504
if mask_bad .shape == xa .shape :
510
505
np .copyto (xa , self ._i_bad , where = mask_bad )
0 commit comments