def test_cast_to_fp(self):
     R = Recaster()
     # Define expected type output from fp recast of value
     sta = sctype_attributes()
     inp_outp = (
         (1, np.complex128, 'c', sta[np.complex128]['size'], 0, np.complex128),
         (1, np.complex128, 'c', sta[np.complex128]['size'], 1, np.complex64),
         (1, np.complex128, 'c', sta[np.complex64]['size'], 0, np.complex64),
         (1, np.complex128, 'f', sta[np.float64]['size'], 0, np.float64),
         (1.0+1j, np.complex128, 'f', sta[np.complex128]['size'], 0, None),
         (1, np.float64, 'f', sta[np.float64]['size'], 0, np.float64),
         (1, np.float64, 'f', sta[np.float64]['size'], 1, np.float32),
         (1, np.float64, 'f', sta[np.float32]['size'], 0, np.float32),
         (1, np.float64, 'c', sta[np.complex128]['size'], 0, np.complex128),
         (1, np.float64, 'c', sta[np.complex128]['size'], 1, np.complex64),
         (1, np.int32, 'f', sta[np.float64]['size'], 0, np.float64),
         (1, np.int32, 'f', sta[np.float64]['size'], 1, np.float32),
         (1, np.float64, 'f', 0, 0, None),
         )
     for value, inp, kind, max_size, continue_down, outp in inp_outp:
         arr = np.array(value, dtype=inp)
         arr = R.cast_to_fp(arr, kind, max_size, continue_down)
         if outp is None:
             assert arr is None, \
                    'Expected None from type %s, got %s' \
                    % (inp, arr.dtype.type)
             continue
         assert arr is not None, \
                'Expected %s from %s, got None' % (outp, inp)
         dtt = arr.dtype.type
         assert dtt is outp, \
                'Expected %s from %s, got %s' % (outp, inp, dtt)
Esempio n. 2
0
 def test_cast_to_fp(self):
     R = Recaster()
     # Define expected type output from fp recast of value
     sta = sctype_attributes()
     inp_outp = (
         (1, np.complex128, 'c', sta[np.complex128]['size'], 0,
          np.complex128),
         (1, np.complex128, 'c', sta[np.complex128]['size'], 1,
          np.complex64),
         (1, np.complex128, 'c', sta[np.complex64]['size'], 0,
          np.complex64),
         (1, np.complex128, 'f', sta[np.float64]['size'], 0, np.float64),
         (1.0 + 1j, np.complex128, 'f', sta[np.complex128]['size'], 0,
          None),
         (1, np.float64, 'f', sta[np.float64]['size'], 0, np.float64),
         (1, np.float64, 'f', sta[np.float64]['size'], 1, np.float32),
         (1, np.float64, 'f', sta[np.float32]['size'], 0, np.float32),
         (1, np.float64, 'c', sta[np.complex128]['size'], 0, np.complex128),
         (1, np.float64, 'c', sta[np.complex128]['size'], 1, np.complex64),
         (1, np.int32, 'f', sta[np.float64]['size'], 0, np.float64),
         (1, np.int32, 'f', sta[np.float64]['size'], 1, np.float32),
         (1, np.float64, 'f', 0, 0, None),
     )
     for value, inp, kind, max_size, continue_down, outp in inp_outp:
         arr = np.array(value, dtype=inp)
         arr = R.cast_to_fp(arr, kind, max_size, continue_down)
         if outp is None:
             assert arr is None, \
                    'Expected None from type %s, got %s' \
                    % (inp, arr.dtype.type)
             continue
         assert arr is not None, \
                'Expected %s from %s, got None' % (outp, inp)
         dtt = arr.dtype.type
         assert dtt is outp, \
                'Expected %s from %s, got %s' % (outp, inp, dtt)