Skip to content

Commit 62e2b36

Browse files
committed
Merge pull request #67 from mwiebe/type_tweaks
Type tweaks
2 parents bbf83ba + 509eb8d commit 62e2b36

28 files changed

+388
-207
lines changed

buildscripts/jenkins-build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fi
8181
export EXTRA="-DDYND_BUILD_TESTS=OFF ${EXTRA}"
8282

8383
# Create a fresh makefile with cmake, and do the build/install
84-
cd build
84+
pushd build
8585
cmake ${EXTRA} \
8686
-DCMAKE_INSTALL_PREFIX=${PYENV_PREFIX} \
8787
-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} \
@@ -100,9 +100,9 @@ if [ '${PYDYND_VERSION}' == '' ]; then
100100
exit 1
101101
fi
102102
export PYDYND_VERSION=${PYDYND_VERSION//-/_}
103+
popd
103104

104105
# Put the conda package by itself in the directory pkgs
105-
cd ..
106106
rm -rf pkgs
107107
mkdir pkgs
108108
cd pkgs

dynd/_lowlevel/type_id.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
'POINTER', 'BYTES', 'FIXEDBYTES',
99
'CHAR', 'STRING', 'FIXEDSTRING',
1010
'CATEGORICAL', 'DATE', 'TIME', 'DATETIME', 'BUSDATE',
11-
'JSON', 'STRIDED_DIM', 'FIXED_DIM',
11+
'JSON', 'STRIDED_DIM', 'CFIXED_DIM',
1212
'OFFSET_DIM', 'VAR_DIM', 'STRUCT',
13-
'FIXEDSTRUCT', 'TUPLE', 'NDOBJECT',
13+
'CSTRUCT', 'TUPLE', 'NDOBJECT',
1414
'CONVERT', 'BYTESWAP', 'VIEW',
1515
'CUDA_HOST', 'CUDA_DEVICE',
1616
'PROPERTY', 'EXPR', 'UNARY_EXPR',
@@ -52,21 +52,23 @@
5252
JSON = 31
5353
STRIDED_DIM = 32
5454
FIXED_DIM = 33
55-
OFFSET_DIM = 34
56-
VAR_DIM = 35
57-
STRUCT = 36
58-
FIXEDSTRUCT = 37
59-
TUPLE = 38
60-
NDOBJECT = 39
61-
CONVERT = 40
62-
BYTESWAP = 41
63-
VIEW = 42
64-
CUDA_HOST = 43
65-
CUDA_DEVICE = 44
66-
PROPERTY = 45
67-
EXPR = 46
68-
UNARY_EXPR = 47
69-
GROUPBY = 48
70-
TYPE = 49
55+
CFIXED_DIM = 34
56+
OFFSET_DIM = 35
57+
VAR_DIM = 36
58+
STRUCT = 37
59+
CSTRUCT = 38
60+
TUPLE = 39
61+
CTUPLE = 40
62+
NDOBJECT = 41
63+
CONVERT = 42
64+
BYTESWAP = 43
65+
VIEW = 44
66+
CUDA_HOST = 45
67+
CUDA_DEVICE = 46
68+
PROPERTY = 47
69+
EXPR = 48
70+
UNARY_EXPR = 49
71+
GROUPBY = 50
72+
TYPE = 51
7173

7274
BUILTIN_TYPE_ID_COUNT = 19

dynd/ndt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
make_view, \
66
make_unaligned, make_fixedstring, make_string, \
77
make_pointer, make_struct, make_cstruct, \
8-
make_strided_dim, make_fixed_dim, make_var_dim, \
8+
make_strided_dim, make_fixed_dim, make_cfixed_dim, make_var_dim, \
99
make_categorical, replace_dtype, extract_dtype, \
1010
factor_categorical, make_bytes, make_property, \
1111
make_reversed_property, cuda_support

dynd/tests/test_array_assign.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_nested_struct(self):
3333
self.assertEqual(nd.as_py(a.z), [3j])
3434

3535
def test_single_struct_array(self):
36-
a = nd.empty('3 * {x:int32, y:int32}')
36+
a = nd.empty('3 * c{x:int32, y:int32}')
3737
a[...] = [(0,0), (3,5), (12,10)]
3838
self.assertEqual(nd.as_py(a.x), [0, 3, 12])
3939
self.assertEqual(nd.as_py(a.y), [0, 5, 10])
@@ -42,7 +42,7 @@ def test_single_struct_array(self):
4242
self.assertEqual(nd.as_py(a.x), [1, 4, 14])
4343
self.assertEqual(nd.as_py(a.y), [2, 7, 190])
4444

45-
a = nd.empty('2 * var * {count:int32, size:string[1,"A"]}')
45+
a = nd.empty('2 * var * c{count:int32, size:string[1,"A"]}')
4646
a[...] = [[(3, 'X')], [(10, 'L'), (12, 'M')]]
4747
self.assertEqual(nd.as_py(a.count), [[3], [10, 12]])
4848
self.assertEqual(nd.as_py(a.size), [['X'], ['L', 'M']])
@@ -61,7 +61,7 @@ def test_single_struct_array(self):
6161
self.assertEqual(nd.as_py(a.size), [['A'], ['B', 'B']])
6262

6363
def test_nested_struct_array(self):
64-
a = nd.empty('3 * {x:{a:int16, b:int16}, y:int32}')
64+
a = nd.empty('3 * c{x:c{a:int16, b:int16}, y:int32}')
6565
a[...] = [((0,1),0), ((2,2),5), ((100,10),10)]
6666
self.assertEqual(nd.as_py(a.x.a), [0, 2, 100])
6767
self.assertEqual(nd.as_py(a.x.b), [1, 2, 10])
@@ -74,7 +74,7 @@ def test_nested_struct_array(self):
7474
self.assertEqual(nd.as_py(a.x.b), [2, 6, 110])
7575
self.assertEqual(nd.as_py(a.y), [5, 7, 110])
7676

77-
a = nd.empty('2 * var * {count:int32, size:{name:string[1,"A"], id: int8}}')
77+
a = nd.empty('2 * var * c{count:int32, size:c{name:string[1,"A"], id: int8}}')
7878
a[...] = [[(3, ('X', 10))], [(10, ('L', 7)), (12, ('M', 5))]]
7979
self.assertEqual(nd.as_py(a.count), [[3], [10, 12]])
8080
self.assertEqual(nd.as_py(a.size.name), [['X'], ['L', 'M']])

dynd/tests/test_array_construct.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ def test_empty(self):
5151
self.assertEqual(a.access_flags, 'readwrite')
5252
self.assertEqual(nd.type_of(a), ndt.make_fixed_dim(3, ndt.int32))
5353
self.assertEqual(a.shape, (3,))
54+
# Constructor from type with cfixed dimension
55+
a = nd.empty('cfixed[3] * int32')
56+
self.assertEqual(a.access_flags, 'readwrite')
57+
self.assertEqual(nd.type_of(a), ndt.make_cfixed_dim(3, ndt.int32))
58+
self.assertEqual(a.shape, (3,))
5459
# Constructor from type with fixed dimension, accesskwarg
5560
a = nd.empty('3 * int32', access='rw')
5661
self.assertEqual(a.access_flags, 'readwrite')
@@ -549,27 +554,27 @@ def test_nested_struct_array(self):
549554

550555
def test_missing_field(self):
551556
self.assertRaises(RuntimeError, nd.array,
552-
[0, 1], type='{x:int32, y:int32, z:int32}')
557+
[0, 1], type='c{x:int32, y:int32, z:int32}')
553558
# With dtype= parameter instead of type=
554559
self.assertRaises(RuntimeError, nd.array,
555-
[0, 1], dtype='{x:int32, y:int32, z:int32}')
560+
[0, 1], dtype='c{x:int32, y:int32, z:int32}')
556561
self.assertRaises(RuntimeError, nd.array,
557-
{'x':0, 'z':1}, type='{x:int32, y:int32, z:int32}')
562+
{'x':0, 'z':1}, type='c{x:int32, y:int32, z:int32}')
558563
# With dtype= parameter instead of type=
559564
self.assertRaises(RuntimeError, nd.array,
560-
{'x':0, 'z':1}, dtype='{x:int32, y:int32, z:int32}')
565+
{'x':0, 'z':1}, dtype='c{x:int32, y:int32, z:int32}')
561566

562567
def test_extra_field(self):
563568
self.assertRaises(RuntimeError, nd.array,
564-
[0, 1, 2, 3], type='{x:int32, y:int32, z:int32}')
569+
[0, 1, 2, 3], type='c{x:int32, y:int32, z:int32}')
565570
# With dtype= parameter instead of type=
566571
self.assertRaises(RuntimeError, nd.array,
567-
[0, 1, 2, 3], dtype='{x:int32, y:int32, z:int32}')
572+
[0, 1, 2, 3], dtype='c{x:int32, y:int32, z:int32}')
568573
self.assertRaises(RuntimeError, nd.array,
569-
{'x':0,'y':1,'z':2,'w':3}, type='{x:int32, y:int32, z:int32}')
574+
{'x':0,'y':1,'z':2,'w':3}, type='c{x:int32, y:int32, z:int32}')
570575
# With dtype= parameter instead of type=
571576
self.assertRaises(RuntimeError, nd.array,
572-
{'x':0,'y':1,'z':2,'w':3}, dtype='{x:int32, y:int32, z:int32}')
577+
{'x':0,'y':1,'z':2,'w':3}, dtype='c{x:int32, y:int32, z:int32}')
573578

574579
class TestIteratorConstruct(unittest.TestCase):
575580
# Test dynd construction from iterators
@@ -731,8 +736,8 @@ def test_simple_fromiter_medsize(self):
731736
def test_ragged_fromiter(self):
732737
# Strided array of var from list of iterators
733738
a = nd.array([(1+x for x in range(3)), (5*x - 10 for x in range(5)),
734-
[2, 10]], type='M * var * int32')
735-
self.assertEqual(nd.type_of(a), ndt.type('M * var * int32'))
739+
[2, 10]], type='strided * var * int32')
740+
self.assertEqual(nd.type_of(a), ndt.type('strided * var * int32'))
736741
self.assertEqual(nd.as_py(a),
737742
[[1,2,3], [-10, -5, 0, 5, 10], [2, 10]])
738743
# Var array of var from iterator of iterators

dynd/tests/test_array_getitem.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ class TestArrayGetItem(unittest.TestCase):
77
def test_strided_dim(self):
88
a = nd.empty(100, ndt.int32)
99
a[...] = nd.range(100)
10-
self.assertEqual(nd.type_of(a), ndt.type('A * int32'))
11-
self.assertEqual(nd.type_of(a[...]), ndt.type('A * int32'))
10+
self.assertEqual(nd.type_of(a), ndt.type('strided * int32'))
11+
self.assertEqual(nd.type_of(a[...]), ndt.type('strided * int32'))
1212
self.assertEqual(nd.type_of(a[0]), ndt.int32)
13-
self.assertEqual(nd.type_of(a[0:1]), ndt.type('A * int32'))
13+
self.assertEqual(nd.type_of(a[0:1]), ndt.type('strided * int32'))
1414
self.assertEqual(nd.as_py(a[0]), 0)
1515
self.assertEqual(nd.as_py(a[99]), 99)
1616
self.assertEqual(nd.as_py(a[-1]), 99)
@@ -26,7 +26,7 @@ def test_fixed_dim(self):
2626
self.assertEqual(nd.type_of(a), ndt.type('100 * int32'))
2727
self.assertEqual(nd.type_of(a[...]), ndt.type('100 * int32'))
2828
self.assertEqual(nd.type_of(a[0]), ndt.int32)
29-
self.assertEqual(nd.type_of(a[0:1]), ndt.type('A * int32'))
29+
self.assertEqual(nd.type_of(a[0:1]), ndt.type('strided * int32'))
3030
self.assertEqual(nd.as_py(a[0]), 0)
3131
self.assertEqual(nd.as_py(a[99]), 99)
3232
self.assertEqual(nd.as_py(a[-1]), 99)
@@ -41,9 +41,9 @@ def test_var_dim(self):
4141
a[...] = nd.range(100)
4242
self.assertEqual(nd.type_of(a), ndt.type('var * int32'))
4343
self.assertEqual(nd.type_of(a[...]), ndt.type('var * int32'))
44-
self.assertEqual(nd.type_of(a[:]), ndt.type('M * int32'))
44+
self.assertEqual(nd.type_of(a[:]), ndt.type('strided * int32'))
4545
self.assertEqual(nd.type_of(a[0]), ndt.int32)
46-
self.assertEqual(nd.type_of(a[0:1]), ndt.type('A * int32'))
46+
self.assertEqual(nd.type_of(a[0:1]), ndt.type('strided * int32'))
4747
self.assertEqual(nd.as_py(a[0]), 0)
4848
self.assertEqual(nd.as_py(a[99]), 99)
4949
self.assertEqual(nd.as_py(a[-1]), 99)

dynd/tests/test_computed_fields.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_simple_expr(self):
1414
('onemore', np.int16, 'xyz + 1')])
1515
self.assertEqual(nd.type_of(b).element_type.type_id, 'unary_expr')
1616
self.assertEqual(nd.type_of(b).element_type.value_type,
17-
ndt.type('{xyz: int32, twice: int32, onemore: int16}'))
17+
ndt.type('c{xyz: int32, twice: int32, onemore: int16}'))
1818
self.assertEqual(nd.as_py(b.xyz), [1, 2, 3, 4, 5])
1919
self.assertEqual(nd.as_py(b.twice), [2, 4, 6, 8, 10])
2020
self.assertEqual(nd.as_py(b.onemore), [2, 3, 4, 5, 6])
@@ -29,7 +29,7 @@ def test_rm_fields(self):
2929
('complex', np.complex64, 'x + 1j*y')],
3030
rm_fields=['x', 'y'])
3131
self.assertEqual(nd.type_of(b).element_type.value_type,
32-
ndt.type('{sum: float32, difference: float32,' +
32+
ndt.type('c{sum: float32, difference: float32,' +
3333
' product: float32, complex: complex[float32]}'))
3434
self.assertEqual(nd.as_py(b.sum), [3, 0, 7]),
3535
self.assertEqual(nd.as_py(b.difference), [-1, -2, -3])
@@ -44,7 +44,7 @@ def test_aggregate(self):
4444
('A', 0.5, 9),
4545
('C', 1, 5),
4646
('B', 2, 2)],
47-
dtype='{cat: string, x: float32, y: float32}')
47+
dtype='c{cat: string, x: float32, y: float32}')
4848
gb = nd.groupby(a, nd.fields(a, 'cat')).eval()
4949
b = nd.make_computed_fields(gb, 1,
5050
fields=[('sum_x', ndt.float32, 'sum(x)'),

dynd/tests/test_ctypes_interop.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ class DATA(ctypes.Structure):
4343
ndt.type(DATA))
4444

4545
def test_type_from_ctypes_carray(self):
46-
self.assertEqual(ndt.make_fixed_dim(10, ndt.int32),
46+
self.assertEqual(ndt.make_cfixed_dim(10, ndt.int32),
4747
ndt.type(ctypes.c_int32 * 10))
48-
self.assertEqual(ndt.make_fixed_dim((10, 3), ndt.int32),
48+
self.assertEqual(ndt.make_cfixed_dim((10, 3), ndt.int32),
4949
ndt.type((ctypes.c_int32 * 3) * 10))
50-
self.assertEqual(ndt.make_fixed_dim((10, 3, 4), ndt.int32),
50+
self.assertEqual(ndt.make_cfixed_dim((10, 3, 4), ndt.int32),
5151
ndt.type(((ctypes.c_int32 * 4) * 3) * 10))
5252

5353
class POINT(ctypes.Structure):
5454
_fields_ = [('x', ctypes.c_int32), ('y', ctypes.c_int32)]
55-
self.assertEqual(ndt.make_fixed_dim(10, ndt.type(POINT)),
55+
self.assertEqual(ndt.make_cfixed_dim(10, ndt.type(POINT)),
5656
ndt.type(POINT * 10))
5757

5858
if __name__ == '__main__':

dynd/tests/test_dtype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def test_type_shape(self):
213213
# The shape attribute of ndt.type
214214
tp = ndt.type('3 * 4 * int32')
215215
self.assertEqual(tp.shape, (3, 4))
216-
tp = ndt.type('M * 3 * var * int32')
216+
tp = ndt.type('strided * 3 * var * int32')
217217
self.assertEqual(tp.shape, (-1, 3, -1))
218218
tp = ndt.type('var * 3 * 2 * int32')
219219
self.assertEqual(tp.shape, (-1, 3, 2))

dynd/tests/test_dtype_datashape.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,21 @@ def test_aliases(self):
3434
self.assertEqual(ndt.float64, ndt.type('real'))
3535
self.assertEqual(ndt.complex_float64, ndt.type('complex'))
3636

37-
def test_fixed_array(self):
37+
def test_cfixed_array(self):
3838
# Tests of datashapes that produce the DyND fixed array type
39-
self.assertEqual(ndt.make_fixed_dim(3, ndt.int32),
40-
ndt.type('3 * int32'))
41-
self.assertEqual(ndt.make_fixed_dim((5, 2), ndt.float64),
42-
ndt.type('5 * 2 * float64'))
39+
self.assertEqual(ndt.make_cfixed_dim(3, ndt.int32),
40+
ndt.type('cfixed[3] * int32'))
41+
self.assertEqual(ndt.make_cfixed_dim((5, 2), ndt.float64),
42+
ndt.type('cfixed[5] * cfixed[2] * float64'))
4343

4444
def test_struct(self):
45+
# Tests of cstruct datashape
46+
dt = ndt.type('c{x: cfixed[3] * int32, y: string}')
47+
self.assertEqual(dt.type_id, 'cstruct')
48+
self.assertEqual(nd.as_py(dt.field_names), ['x', 'y'])
4549
# Tests of struct datashape
4650
dt = ndt.type('{x: 3 * int32, y: string}')
47-
self.assertEqual(dt.type_id, 'cstruct')
51+
self.assertEqual(dt.type_id, 'struct')
4852
self.assertEqual(nd.as_py(dt.field_names), ['x', 'y'])
4953

5054
def test_var_dshape(self):

0 commit comments

Comments
 (0)