@@ -30,15 +30,7 @@ def __init__(self, array, out_dtype=None)
3030"""
3131import numpy as np
3232
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
4234from .volumeutils import array_to_file , finite_range
4335
4436
@@ -152,9 +144,8 @@ def scaling_needed(self):
152144 # No scaling needed if data already fits in output type
153145 # But note - we need to convert to ints, to avoid conversion to float
154146 # 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 ):
158149 return False
159150 return True
160151
@@ -392,7 +383,7 @@ def _do_scaling(self):
392383 out_max , out_min = info .max , info .min
393384 # If left as int64, uint64, comparisons will default to floats, and
394385 # 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 ):
396387 # already in range
397388 return
398389 # (u)int to (u)int scaling
@@ -410,7 +401,7 @@ def _iu2iu(self):
410401 # that deals with max neg ints. abs problem only arises when all
411402 # the data is set to max neg integer value
412403 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?
414405 # -1.0 * arr will be in scaler_dtype precision
415406 self .slope = - 1.0
416407 return
@@ -427,7 +418,7 @@ def _range_scale(self, in_min, in_max):
427418 # not lose precision because min/max are of fp type.
428419 out_min , out_max = np .array ((out_min , out_max ), dtype = big_float )
429420 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 ))
431422 if self ._out_dtype .kind == 'u' :
432423 if in_min < 0 and in_max > 0 :
433424 raise WriterError (
@@ -546,14 +537,13 @@ def to_fileobj(self, fileobj, order='F'):
546537
547538 def _iu2iu (self ):
548539 # (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 ())
550541 # 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
552542 out_dtype = self ._out_dtype
553543 # Options in this method are scaling using intercept only. These will
554544 # have to pass through ``self.scaler_dtype`` (because the intercept is
555545 # 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 ))
557547 type_range = o_max - o_min
558548 mn2mx = mx - mn
559549 if mn2mx <= type_range : # might offset be enough?
@@ -565,12 +555,12 @@ def _iu2iu(self):
565555 else : # int output - take midpoint to 0
566556 # ceil below increases inter, pushing scale up to 0.5 towards
567557 # -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 ))
569559 # Floor exact decreases inter, so pulling scaled values more
570560 # positive. This may make mx - inter > t_max
571561 inter = floor_exact (midpoint , self .scaler_dtype )
572562 # Need to check still in range after floor_exact-ing
573- int_inter = as_int (inter )
563+ int_inter = int (inter )
574564 assert mn - int_inter >= o_min
575565 if mx - int_inter <= o_max :
576566 self .inter = inter
@@ -594,14 +584,13 @@ def _range_scale(self, in_min, in_max):
594584 in_min , in_max = np .array ([in_min , in_max ], dtype = big_float )
595585 in_range = np .diff ([in_min , in_max ])
596586 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 )
603592 # 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 ))
605594 if out_dtype .kind == 'f' :
606595 # Type range, these are also floats
607596 info = type_info (out_dtype )
0 commit comments