def test_type_from_ctypes_carray(self): self.assertEqual(ndt.make_cfixed_dim(10, ndt.int32), ndt.type(ctypes.c_int32 * 10)) self.assertEqual(ndt.make_cfixed_dim((10, 3), ndt.int32), ndt.type((ctypes.c_int32 * 3) * 10)) self.assertEqual(ndt.make_cfixed_dim((10, 3, 4), ndt.int32), ndt.type(((ctypes.c_int32 * 4) * 3) * 10)) class POINT(ctypes.Structure): _fields_ = [('x', ctypes.c_int32), ('y', ctypes.c_int32)] self.assertEqual(ndt.make_cfixed_dim(10, ndt.type(POINT)), ndt.type(POINT * 10))
def test_empty(self): # Constructor from scalar type a = nd.empty(ndt.int32) self.assertEqual(a.access_flags, "readwrite") self.assertEqual(nd.type_of(a), ndt.int32) # Constructor from type with fixed dimension a = nd.empty("3 * int32") self.assertEqual(a.access_flags, "readwrite") self.assertEqual(nd.type_of(a), ndt.make_fixed_dim(3, ndt.int32)) self.assertEqual(a.shape, (3,)) # Constructor from type with cfixed dimension a = nd.empty("cfixed[3] * int32") self.assertEqual(a.access_flags, "readwrite") self.assertEqual(nd.type_of(a), ndt.make_cfixed_dim(3, ndt.int32)) self.assertEqual(a.shape, (3,)) # Constructor from type with fixed dimension, accesskwarg a = nd.empty("3 * int32", access="rw") self.assertEqual(a.access_flags, "readwrite") self.assertEqual(nd.type_of(a), ndt.make_fixed_dim(3, ndt.int32)) self.assertEqual(a.shape, (3,)) # Can't create with access as immutable self.assertRaises(ValueError, nd.empty, "3 * int32", access="immutable") # Constructor from shape as single integer a = nd.empty(3, ndt.int32) self.assertEqual(a.access_flags, "readwrite") self.assertEqual(nd.type_of(a), ndt.make_strided_dim(ndt.int32)) self.assertEqual(a.shape, (3,)) # Constructor from shape as tuple a = nd.empty((3, 4), ndt.int32) self.assertEqual(a.access_flags, "readwrite") self.assertEqual(nd.type_of(a), ndt.type("strided * strided * int32")) self.assertEqual(a.shape, (3, 4)) # Constructor from shape as variadic arguments a = nd.empty(3, 4, ndt.int32) self.assertEqual(a.access_flags, "readwrite") self.assertEqual(nd.type_of(a), ndt.type("strided * strided * int32")) self.assertEqual(a.shape, (3, 4)) # Constructor from shape as variadic arguments, access kwarg a = nd.empty(3, 4, ndt.int32, access="rw") self.assertEqual(a.access_flags, "readwrite") self.assertEqual(nd.type_of(a), ndt.type("strided * strided * int32")) self.assertEqual(a.shape, (3, 4)) # Can't create with access as immutable self.assertRaises(ValueError, nd.empty, 3, 4, ndt.int32, access="immutable")
def test_empty(self): # Constructor from scalar type a = nd.empty(ndt.int32) self.assertEqual(a.access_flags, 'readwrite') self.assertEqual(nd.type_of(a), ndt.int32) # Constructor from type with fixed dimension a = nd.empty('3 * int32') self.assertEqual(a.access_flags, 'readwrite') self.assertEqual(nd.type_of(a), ndt.make_fixed_dim(3, ndt.int32)) self.assertEqual(a.shape, (3,)) # Constructor from type with cfixed dimension a = nd.empty('cfixed[3] * int32') self.assertEqual(a.access_flags, 'readwrite') self.assertEqual(nd.type_of(a), ndt.make_cfixed_dim(3, ndt.int32)) self.assertEqual(a.shape, (3,)) # Constructor from type with fixed dimension, accesskwarg a = nd.empty('3 * int32', access='rw') self.assertEqual(a.access_flags, 'readwrite') self.assertEqual(nd.type_of(a), ndt.make_fixed_dim(3, ndt.int32)) self.assertEqual(a.shape, (3,)) # Can't create with access as immutable self.assertRaises(ValueError, nd.empty, '3 * int32', access='immutable') # Constructor from shape as single integer a = nd.empty(3, ndt.int32) self.assertEqual(a.access_flags, 'readwrite') self.assertEqual(nd.type_of(a), ndt.type('3 * int32')) self.assertEqual(a.shape, (3,)) # Constructor from shape as tuple a = nd.empty((3,4), ndt.int32) self.assertEqual(a.access_flags, 'readwrite') self.assertEqual(nd.type_of(a), ndt.type('3 * 4 * int32')) self.assertEqual(a.shape, (3,4)) # Constructor from shape as variadic arguments a = nd.empty(3, 4, ndt.int32) self.assertEqual(a.access_flags, 'readwrite') self.assertEqual(nd.type_of(a), ndt.type('3 * 4 * int32')) self.assertEqual(a.shape, (3,4)) # Constructor from shape as variadic arguments, access kwarg a = nd.empty(3, 4, ndt.int32, access='rw') self.assertEqual(a.access_flags, 'readwrite') self.assertEqual(nd.type_of(a), ndt.type('3 * 4 * int32')) self.assertEqual(a.shape, (3,4)) # Can't create with access as immutable self.assertRaises(ValueError, nd.empty, 3, 4, ndt.int32, access='immutable')
def test_cfixed_array(self): # Tests of datashapes that produce the DyND fixed array type self.assertEqual(ndt.make_cfixed_dim(3, ndt.int32), ndt.type('cfixed[3] * int32')) self.assertEqual(ndt.make_cfixed_dim((5, 2), ndt.float64), ndt.type('cfixed[5] * cfixed[2] * float64'))