@@ -30,15 +30,7 @@ def __init__(self, array, out_dtype=None)
30
30
"""
31
31
import numpy as np
32
32
33
- from .casting import (
34
- as_int ,
35
- best_float ,
36
- floor_exact ,
37
- int_abs ,
38
- int_to_float ,
39
- shared_range ,
40
- type_info ,
41
- )
33
+ from .casting import best_float , floor_exact , int_abs , shared_range , type_info
42
34
from .volumeutils import array_to_file , finite_range
43
35
44
36
@@ -152,9 +144,8 @@ def scaling_needed(self):
152
144
# No scaling needed if data already fits in output type
153
145
# But note - we need to convert to ints, to avoid conversion to float
154
146
# during comparisons, and therefore int -> float conversions which are
155
- # not exact. Only a problem for uint64 though. We need as_int here to
156
- # work around a numpy 1.4.1 bug in uint conversion
157
- if as_int (mn ) >= as_int (info .min ) and as_int (mx ) <= as_int (info .max ):
147
+ # not exact. Only a problem for uint64 though.
148
+ if int (mn ) >= int (info .min ) and int (mx ) <= int (info .max ):
158
149
return False
159
150
return True
160
151
@@ -392,7 +383,7 @@ def _do_scaling(self):
392
383
out_max , out_min = info .max , info .min
393
384
# If left as int64, uint64, comparisons will default to floats, and
394
385
# these are inexact for > 2**53 - so convert to int
395
- if as_int (mx ) <= as_int (out_max ) and as_int (mn ) >= as_int (out_min ):
386
+ if int (mx ) <= int (out_max ) and int (mn ) >= int (out_min ):
396
387
# already in range
397
388
return
398
389
# (u)int to (u)int scaling
@@ -410,7 +401,7 @@ def _iu2iu(self):
410
401
# that deals with max neg ints. abs problem only arises when all
411
402
# the data is set to max neg integer value
412
403
o_min , o_max = shared_range (self .scaler_dtype , out_dt )
413
- if mx <= 0 and int_abs (mn ) <= as_int (o_max ): # sign flip enough?
404
+ if mx <= 0 and int_abs (mn ) <= int (o_max ): # sign flip enough?
414
405
# -1.0 * arr will be in scaler_dtype precision
415
406
self .slope = - 1.0
416
407
return
@@ -427,7 +418,7 @@ def _range_scale(self, in_min, in_max):
427
418
# not lose precision because min/max are of fp type.
428
419
out_min , out_max = np .array ((out_min , out_max ), dtype = big_float )
429
420
else : # (u)int
430
- out_min , out_max = (int_to_float ( v , big_float ) for v in (out_min , out_max ))
421
+ out_min , out_max = (big_float ( v ) for v in (out_min , out_max ))
431
422
if self ._out_dtype .kind == 'u' :
432
423
if in_min < 0 and in_max > 0 :
433
424
raise WriterError (
@@ -546,14 +537,13 @@ def to_fileobj(self, fileobj, order='F'):
546
537
547
538
def _iu2iu (self ):
548
539
# (u)int to (u)int
549
- mn , mx = (as_int (v ) for v in self .finite_range ())
540
+ mn , mx = (int (v ) for v in self .finite_range ())
550
541
# range may be greater than the largest integer for this type.
551
- # as_int needed to work round numpy 1.4.1 int casting bug
552
542
out_dtype = self ._out_dtype
553
543
# Options in this method are scaling using intercept only. These will
554
544
# have to pass through ``self.scaler_dtype`` (because the intercept is
555
545
# in this type).
556
- o_min , o_max = (as_int (v ) for v in shared_range (self .scaler_dtype , out_dtype ))
546
+ o_min , o_max = (int (v ) for v in shared_range (self .scaler_dtype , out_dtype ))
557
547
type_range = o_max - o_min
558
548
mn2mx = mx - mn
559
549
if mn2mx <= type_range : # might offset be enough?
@@ -565,12 +555,12 @@ def _iu2iu(self):
565
555
else : # int output - take midpoint to 0
566
556
# ceil below increases inter, pushing scale up to 0.5 towards
567
557
# -inf, because ints have abs min == abs max + 1
568
- midpoint = mn + as_int (np .ceil (mn2mx / 2.0 ))
558
+ midpoint = mn + int (np .ceil (mn2mx / 2.0 ))
569
559
# Floor exact decreases inter, so pulling scaled values more
570
560
# positive. This may make mx - inter > t_max
571
561
inter = floor_exact (midpoint , self .scaler_dtype )
572
562
# Need to check still in range after floor_exact-ing
573
- int_inter = as_int (inter )
563
+ int_inter = int (inter )
574
564
assert mn - int_inter >= o_min
575
565
if mx - int_inter <= o_max :
576
566
self .inter = inter
@@ -594,14 +584,13 @@ def _range_scale(self, in_min, in_max):
594
584
in_min , in_max = np .array ([in_min , in_max ], dtype = big_float )
595
585
in_range = np .diff ([in_min , in_max ])
596
586
else : # max possible (u)int range is 2**64-1 (int64, uint64)
597
- # int_to_float covers this range. On windows longdouble is the
598
- # same as double so in_range will be 2**64 - thus overestimating
599
- # slope slightly. Casting to int needed to allow in_max-in_min to
600
- # be larger than the largest (u)int value
601
- in_min , in_max = as_int (in_min ), as_int (in_max )
602
- in_range = int_to_float (in_max - in_min , big_float )
587
+ # On windows longdouble is the same as double so in_range will be 2**64 -
588
+ # thus overestimating slope slightly. Casting to int needed to allow
589
+ # in_max-in_min to be larger than the largest (u)int value
590
+ in_min , in_max = int (in_min ), int (in_max )
591
+ in_range = big_float (in_max - in_min )
603
592
# Cast to float for later processing.
604
- in_min , in_max = (int_to_float ( v , big_float ) for v in (in_min , in_max ))
593
+ in_min , in_max = (big_float ( v ) for v in (in_min , in_max ))
605
594
if out_dtype .kind == 'f' :
606
595
# Type range, these are also floats
607
596
info = type_info (out_dtype )
0 commit comments