def test_reciprocal(self): from numpypy import array, reciprocal, complex64, complex128 c_and_relerr = [(complex64, 2e-7), (complex128, 2e-15)] try: from numpypy import clongdouble c_and_relerr.append((clongdouble, 2e-30)) except: pass # no longdouble yet inf = float('inf') nan = float('nan') #complex orig = [2.+4.j, -2.+4.j, 2.-4.j, -2.-4.j, complex(inf, 3), complex(inf, -3), complex(inf, -inf), complex(nan, 3), 0+0j, 0-0j] a2 = 2.**2 + 4.**2 r = 2. / a2 i = 4. / a2 cnan = complex(nan, nan) expected = [complex(r, -i), complex(-r, -i), complex(r, i), complex(-r, i), -0j, 0j, cnan, cnan, cnan, cnan] for c, rel_err in c_and_relerr: actual = reciprocal(array([orig], dtype=c)) for b, a, e in zip(orig, actual, expected): assert (a[0].real - e.real) < rel_err assert (a[0].imag - e.imag) < rel_err
def test_reciporocal(self): from numpypy import array, reciprocal reference = [-0.2, float("inf"), float("-inf"), 2.0] a = array([-5.0, 0.0, -0.0, 0.5]) b = reciprocal(a) for i in range(4): assert b[i] == reference[i]
def test_reciprocal(self): from numpypy import array, reciprocal, complex64, complex128 inf = float('inf') nan = float('nan') reference = [-0.2, inf, -inf, 2.0, nan] a = array([-5.0, 0.0, -0.0, 0.5, nan]) b = reciprocal(a) for i in range(4): assert b[i] == reference[i] for dtype in ['int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64']: reference = [0, -1, 0, 1, 0] if dtype[0] == 'u': reference[1] = 0 # XXX need to fix specialization issue in types.py first #elif dtype == 'int32': # reference[2] = -2147483648 #elif dtype == 'int64': # reference[2] = -9223372036854775808 a = array([-2, -1, 0, 1, 2], dtype) b = reciprocal(a) assert (b == reference).all()
def test_reciprocal(self): from numpypy import array, reciprocal inf = float('inf') nan = float('nan') #complex orig = [2.+4.j, -2.+4.j, 2.-4.j, -2.-4.j, complex(inf, 3), complex(inf, -3), complex(inf, -inf), complex(nan, 3), 0+0j, 0-0j] a2 = 2.**2 + 4.**2 r = 2. / a2 i = 4. / a2 cnan = complex(nan, nan) expected = [complex(r, -i), complex(-r, -i), complex(r, i), complex(-r, i), -0j, 0j, cnan, cnan, cnan, cnan] for c, rel_err in (('complex64', 2e-7), ('complex128', 2e-15), ('clongdouble', 2e-15)): actual = reciprocal(array([orig], dtype=c)) for b, a, e in zip(orig, actual, expected): assert (a[0].real - e.real) < rel_err assert (a[0].imag - e.imag) < rel_err