@@ -24,11 +24,22 @@ def convert_strides_to_counts(strides, itemsize):
24
24
np .empty ((3 , 4 ), order = 'F' ),
25
25
)
26
26
)
27
- def test_viewable_cpu ( in_arr ) :
27
+ class TestViewCPU :
28
28
29
- @viewable ((0 ,))
30
- def my_func (arr ):
31
- view = arr .view (- 1 )
29
+ def test_viewable_cpu (self , in_arr ):
30
+
31
+ @viewable ((0 ,))
32
+ def my_func (arr ):
33
+ view = arr .view (- 1 )
34
+ self ._check_view (view , in_arr )
35
+
36
+ my_func (in_arr )
37
+
38
+ def test_strided_memory_view_cpu (self , in_arr ):
39
+ view = StridedMemoryView (in_arr , stream_ptr = - 1 )
40
+ self ._check_view (view , in_arr )
41
+
42
+ def _check_view (self , view , in_arr ):
32
43
assert isinstance (view , StridedMemoryView )
33
44
assert view .ptr == in_arr .ctypes .data
34
45
assert view .shape == in_arr .shape
@@ -43,8 +54,6 @@ def my_func(arr):
43
54
assert view .device_accessible == False
44
55
assert view .exporting_obj is in_arr
45
56
46
- my_func (in_arr )
47
-
48
57
49
58
def gpu_array_samples ():
50
59
# TODO: this function would initialize the device at test collection time
@@ -78,15 +87,33 @@ def gpu_array_ptr(arr):
78
87
* gpu_array_samples (),
79
88
)
80
89
)
81
- def test_viewable_gpu (in_arr , stream ):
82
- # TODO: use the device fixture?
83
- dev = Device ()
84
- dev .set_current ()
85
- s = dev .create_stream () if stream else None
86
-
87
- @viewable ((0 ,))
88
- def my_func (arr ):
89
- view = arr .view (s .handle if s else - 1 )
90
+ class TestViewGPU :
91
+
92
+ def test_viewable_gpu (self , in_arr , stream ):
93
+ # TODO: use the device fixture?
94
+ dev = Device ()
95
+ dev .set_current ()
96
+ s = dev .create_stream () if stream else None
97
+
98
+ @viewable ((0 ,))
99
+ def my_func (arr ):
100
+ view = arr .view (s .handle if s else - 1 )
101
+ self ._check_view (view , in_arr , dev )
102
+
103
+ my_func (in_arr )
104
+
105
+ def test_strided_memory_view_cpu (self , in_arr , stream ):
106
+ # TODO: use the device fixture?
107
+ dev = Device ()
108
+ dev .set_current ()
109
+ s = dev .create_stream () if stream else None
110
+
111
+ view = StridedMemoryView (
112
+ in_arr ,
113
+ stream_ptr = s .handle if s else - 1 )
114
+ self ._check_view (view , in_arr , dev )
115
+
116
+ def _check_view (self , view , in_arr , dev ):
90
117
assert isinstance (view , StridedMemoryView )
91
118
assert view .ptr == gpu_array_ptr (in_arr )
92
119
assert view .shape == in_arr .shape
@@ -100,5 +127,3 @@ def my_func(arr):
100
127
assert view .device_id == dev .device_id
101
128
assert view .device_accessible == True
102
129
assert view .exporting_obj is in_arr
103
-
104
- my_func (in_arr )
0 commit comments