def test_ufunc_struct(self): ufb = UFuncBuilder(add) ufb.add("complex64(complex64, complex64)") ufunc = ufb.build_ufunc() a = numpy.arange(10, dtype='complex64') + 1j b = ufunc(a, a) self.assertTrue(numpy.all(a + a == b))
def test_ufunc_forceobj(self): ufb = UFuncBuilder(add, targetoptions={'forceobj': True}) cres = ufb.add("int32(int32, int32)") self.assertTrue(cres.objectmode) ufunc = ufb.build_ufunc() a = numpy.arange(10, dtype='int32') b = ufunc(a, a) self.assertTrue(numpy.all(a + a == b))
def test_basic_ufunc(self): ufb = UFuncBuilder(add) ufb.add("int32(int32, int32)") ufb.add("int64(int64, int64)") ufunc = ufb.build_ufunc() a = numpy.arange(10, dtype='int32') b = ufunc(a, a) self.assertTrue(numpy.all(a + a == b))
def test_ufunc_struct(self): ufb = UFuncBuilder(add) cres = ufb.add("complex64(complex64, complex64)") self.assertFalse(cres.objectmode) ufunc = ufb.build_ufunc() a = numpy.arange(10, dtype='complex64') + 1j b = ufunc(a, a) self.assertTrue(numpy.all(a + a == b)) self.assertEqual(b.dtype, numpy.dtype('complex64'))
def test_basic_ufunc(self): ufb = UFuncBuilder(add) cres = ufb.add("int32(int32, int32)") self.assertFalse(cres.objectmode) cres = ufb.add("int64(int64, int64)") self.assertFalse(cres.objectmode) ufunc = ufb.build_ufunc() a = numpy.arange(10, dtype='int32') b = ufunc(a, a) self.assertTrue(numpy.all(a + a == b)) # Metadata self.assertEqual(ufunc.__name__, "add") self.assertIn("An addition", ufunc.__doc__)
def test_ufunc_struct(self): ufb = UFuncBuilder(add) cres = ufb.add("complex64(complex64, complex64)") self.assertFalse(cres.objectmode) ufunc = ufb.build_ufunc() def check(a): b = ufunc(a, a) self.assertTrue(numpy.all(a + a == b)) self.assertEqual(b.dtype, a.dtype) a = numpy.arange(12, dtype='complex64') + 1j check(a) # Non-contiguous dimension a = a[::2] check(a) a = a.reshape((2, 3)) check(a)
def test_basic_ufunc(self): ufb = UFuncBuilder(add) cres = ufb.add("int32(int32, int32)") self.assertFalse(cres.objectmode) cres = ufb.add("int64(int64, int64)") self.assertFalse(cres.objectmode) ufunc = ufb.build_ufunc() def check(a): b = ufunc(a, a) self.assertTrue(numpy.all(a + a == b)) self.assertEqual(b.dtype, a.dtype) a = numpy.arange(12, dtype='int32') check(a) # Non-contiguous dimension a = a[::2] check(a) a = a.reshape((2, 3)) check(a) # Metadata self.assertEqual(ufunc.__name__, "add") self.assertIn("An addition", ufunc.__doc__)