forked from Theano/libgpuarray
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tools.py
More file actions
139 lines (114 loc) · 4.54 KB
/
test_tools.py
File metadata and controls
139 lines (114 loc) · 4.54 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from pygpu.tools import (as_argument, Argument, ArrayArg, ScalarArg,
check_contig, check_args, Counter, lfu_cache)
from .support import (guard_devsup, rand, check_flags, check_meta, check_all,
context, gen_gpuarray, dtypes_no_complex)
def test_check_contig_1():
ac, ag = gen_gpuarray((50, 1, 20), 'float32', ctx=context)
bc, bg = gen_gpuarray((50, 1, 20), 'float32', ctx=context)
n, offsets, contig = check_contig((ag, bg))
assert n == 1000
assert offsets == (0, 0)
assert contig
def test_check_contig_2():
ac, ag = gen_gpuarray((50, 1, 20), 'float32', ctx=context)
bc, bg = gen_gpuarray((50, 1, 20), 'float32', ctx=context, sliced=2)
n, offsets, contig = check_contig((ag, bg))
assert n == None
assert offsets == None
assert not contig
def test_check_args_simple():
ac, ag = gen_gpuarray((50,), 'float32', ctx=context)
bc, bg = gen_gpuarray((50,), 'float32', ctx=context)
n, nd, dims, strs, offsets = check_args((ag, bg))
assert n == 50
assert nd == 1
assert dims == (50,)
assert strs == ((4,), (4,))
assert offsets == (0, 0)
ac, ag = gen_gpuarray((50, 1, 20), 'float32', ctx=context)
bc, bg = gen_gpuarray((50, 1, 20), 'float32', ctx=context)
n, nd, dims, strs, offsets = check_args((ag, bg))
assert n == 1000
assert nd == 3
assert dims == (50, 1, 20)
assert strs == ((80, 80, 4), (80, 80, 4))
assert offsets == (0, 0)
def test_check_args_collapse_1():
ac, ag = gen_gpuarray((50, 1, 20), 'float32', ctx=context)
bc, bg = gen_gpuarray((50, 1, 20), 'float32', ctx=context)
n, nd, dims, strs, offsets = check_args((ag, bg), collapse=False)
assert n == 1000
assert nd == 3
assert dims == (50, 1, 20)
assert strs == ((80, 80, 4), (80, 80, 4))
assert offsets == (0, 0)
n, nd, dims, strs, offsets = check_args((ag, bg), collapse=True)
assert n == 1000
assert nd == 1
assert dims == (1000,)
assert strs == ((4,), (4,))
assert offsets == (0, 0)
def test_check_args_collapse_2():
ac, ag = gen_gpuarray((50, 1, 20), 'float32', ctx=context, sliced=2,
offseted_inner=True)
bc, bg = gen_gpuarray((50, 1, 20), 'float32', ctx=context)
n, nd, dims, strs, offsets = check_args((ag, bg), collapse=True)
assert n == 1000
assert nd == 2
assert dims == (50, 20)
assert strs == ((168, 4), (80, 4))
assert offsets == (4, 0)
def test_check_args_collapse_3():
ac, ag = gen_gpuarray((50, 2, 10), 'float32', ctx=context, sliced=2,
offseted_outer=True)
bc, bg = gen_gpuarray((50, 2, 10), 'float32', ctx=context)
n, nd, dims, strs, offsets = check_args((ag, bg), collapse=True)
assert n == 1000
assert nd == 2
assert dims == (50, 20)
assert strs == ((160, 4), (80, 4))
assert offsets == (80, 0)
def test_check_args_collapse_4():
ac, ag = gen_gpuarray((1,), 'float32', ctx=context)
n, nd, dims, strs, offsets = check_args((ag,), collapse=False)
assert n == 1
assert nd == 1
assert dims == (1,)
assert strs == ((4,),)
assert offsets == (0,)
ac, ag = gen_gpuarray((1, 1), 'float32', ctx=context)
n, nd, dims, strs, offsets = check_args((ag,), collapse=True)
assert n == 1
assert nd == 1
assert dims == (1,)
assert strs == ((4,),)
assert offsets == (0,)
def test_check_args_broadcast_1():
ac, ag = gen_gpuarray((1,), 'float32', ctx=context)
bc, bg = gen_gpuarray((50,), 'float32', ctx=context)
n, nd, dims, strs, offsets = check_args((ag, bg), broadcast=True)
assert n == 50
assert nd == 1
assert dims == (50,)
assert strs == ((0,), (4,))
assert offsets == (0, 0)
def test_check_args_broadcast_2():
ac, ag = gen_gpuarray((50, 1, 20), 'float32', ctx=context, sliced=2,
offseted_inner=True)
bc, bg = gen_gpuarray((50, 1, 20), 'float32', ctx=context)
n, nd, dims, strs, offsets = check_args((ag, bg), collapse=True,
broadcast=True)
assert n == 1000
assert nd == 2
assert dims == (50, 20)
assert strs == ((168, 4), (80, 4))
assert offsets == (4, 0)
def test_check_args_broadcast_3():
ac, ag = gen_gpuarray((10, 20, 30), 'float32', ctx=context)
bc, bg = gen_gpuarray((1, 1, 1), 'float32', ctx=context)
n, nd, dims, strs, offsets = check_args((ag, bg), broadcast=True)
assert n == 6000
assert nd == 3
assert dims == (10, 20, 30)
assert strs == ((2400, 120, 4), (0, 0, 0))
assert offsets == (0, 0)