-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest_dtype.py
More file actions
91 lines (74 loc) · 2.86 KB
/
test_dtype.py
File metadata and controls
91 lines (74 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from grblas import dtypes, lib
all_dtypes = (
dtypes.BOOL,
dtypes.INT8,
dtypes.INT16,
dtypes.INT32,
dtypes.INT64,
dtypes.UINT8,
dtypes.UINT16,
dtypes.UINT32,
dtypes.UINT64,
dtypes.FP32,
dtypes.FP64,
)
def test_names():
assert dtypes.BOOL.name == 'BOOL'
assert dtypes.INT8.name == 'INT8'
assert dtypes.INT16.name == 'INT16'
assert dtypes.INT32.name == 'INT32'
assert dtypes.INT64.name == 'INT64'
assert dtypes.UINT8.name == 'UINT8'
assert dtypes.UINT16.name == 'UINT16'
assert dtypes.UINT32.name == 'UINT32'
assert dtypes.UINT64.name == 'UINT64'
assert dtypes.FP32.name == 'FP32'
assert dtypes.FP64.name == 'FP64'
def test_ctype():
assert dtypes.BOOL.c_type == '_Bool'
assert dtypes.INT8.c_type == 'int8_t'
assert dtypes.INT16.c_type == 'int16_t'
assert dtypes.INT32.c_type == 'int32_t'
assert dtypes.INT64.c_type == 'int64_t'
assert dtypes.UINT8.c_type == 'uint8_t'
assert dtypes.UINT16.c_type == 'uint16_t'
assert dtypes.UINT32.c_type == 'uint32_t'
assert dtypes.UINT64.c_type == 'uint64_t'
assert dtypes.FP32.c_type == 'float'
assert dtypes.FP64.c_type == 'double'
def test_gbtype():
assert dtypes.BOOL.gb_type == lib.GrB_BOOL
assert dtypes.INT8.gb_type == lib.GrB_INT8
assert dtypes.INT16.gb_type == lib.GrB_INT16
assert dtypes.INT32.gb_type == lib.GrB_INT32
assert dtypes.INT64.gb_type == lib.GrB_INT64
assert dtypes.UINT8.gb_type == lib.GrB_UINT8
assert dtypes.UINT16.gb_type == lib.GrB_UINT16
assert dtypes.UINT32.gb_type == lib.GrB_UINT32
assert dtypes.UINT64.gb_type == lib.GrB_UINT64
assert dtypes.FP32.gb_type == lib.GrB_FP32
assert dtypes.FP64.gb_type == lib.GrB_FP64
def test_lookup_by_name():
for dt in all_dtypes:
assert dtypes.lookup(dt.name) is dt
def test_lookup_by_ctype():
for dt in all_dtypes:
assert dtypes.lookup(dt.c_type) is dt
def test_lookup_by_gbtype():
for dt in all_dtypes:
assert dtypes.lookup(dt.gb_type) is dt
def test_lookup_by_dtype():
assert dtypes.lookup(bool) == dtypes.BOOL
assert dtypes.lookup(int) == dtypes.INT64
assert dtypes.lookup(float) == dtypes.FP64
def test_unify_dtypes():
assert dtypes.unify(dtypes.BOOL, dtypes.BOOL) == dtypes.BOOL
assert dtypes.unify(dtypes.BOOL, dtypes.INT16) == dtypes.INT16
assert dtypes.unify(dtypes.INT16, dtypes.INT8) == dtypes.INT16
assert dtypes.unify(dtypes.UINT32, dtypes.UINT8) == dtypes.UINT32
assert dtypes.unify(dtypes.UINT32, dtypes.FP32) == dtypes.FP32
assert dtypes.unify(dtypes.INT32, dtypes.FP32) == dtypes.FP32
assert dtypes.unify(dtypes.FP64, dtypes.UINT8) == dtypes.FP64
assert dtypes.unify(dtypes.FP64, dtypes.FP32) == dtypes.FP64
assert dtypes.unify(dtypes.INT16, dtypes.UINT16) == dtypes.INT32
assert dtypes.unify(dtypes.UINT64, dtypes.INT8) == dtypes.FP64