예제 #1
0
 def test_cast_to_fp(self):
     R = Recaster()
     # Define expected type output from fp recast of value
     sta = sctype_attributes()
     inp_outp = (
         (1, N.complex128, 'c', sta[N.complex128]['size'], 0, N.complex128),
         (1, N.complex128, 'c', sta[N.complex128]['size'], 1, N.complex64),
         (1, N.complex128, 'c', sta[N.complex64]['size'], 0, N.complex64),
         (1, N.complex128, 'f', sta[N.float64]['size'], 0, N.float64),
         (1.0+1j, N.complex128, 'f', sta[N.complex128]['size'], 0, None),
         (1, N.float64, 'f', sta[N.float64]['size'], 0, N.float64),
         (1, N.float64, 'f', sta[N.float64]['size'], 1, N.float32),
         (1, N.float64, 'f', sta[N.float32]['size'], 0, N.float32),
         (1, N.float64, 'c', sta[N.complex128]['size'], 0, N.complex128),
         (1, N.float64, 'c', sta[N.complex128]['size'], 1, N.complex64),
         (1, N.int32, 'f', sta[N.float64]['size'], 0, N.float64),
         (1, N.int32, 'f', sta[N.float64]['size'], 1, N.float32),
         (1, N.float64, 'f', 0, 0, None),
         )
     for value, inp, kind, max_size, continue_down, outp in inp_outp:
         arr = N.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)