@@ -58,3 +58,102 @@ def test_basic_slice3():
58
58
assert y .ndim == x .ndim
59
59
assert y .shape == x .shape
60
60
assert y .strides == x .strides
61
+
62
+
63
+ def test_basic_slice4 ():
64
+ q = get_queue_or_skip ()
65
+ n0 , n1 = 5 , 3
66
+ x = dpt .empty ((n0 , n1 ), dtype = "f4" , sycl_queue = q )
67
+ y = x [::- 1 ]
68
+ assert isinstance (y , dpt .usm_ndarray )
69
+ assert y .shape == x .shape
70
+ assert y .strides == (- x .strides [0 ], x .strides [1 ])
71
+ actual_offset = y .__sycl_usm_array_interface__ ["offset" ]
72
+ assert actual_offset == (n0 - 1 ) * n1
73
+
74
+
75
+ def test_basic_slice5 ():
76
+ q = get_queue_or_skip ()
77
+ n0 , n1 = 5 , 3
78
+ x = dpt .empty ((n0 , n1 ), dtype = "c8" , sycl_queue = q )
79
+ y = x [:, ::- 1 ]
80
+ assert isinstance (y , dpt .usm_ndarray )
81
+ assert y .shape == x .shape
82
+ assert y .strides == (x .strides [0 ], - x .strides [1 ])
83
+ actual_offset = y .__sycl_usm_array_interface__ ["offset" ]
84
+ assert actual_offset == (n1 - 1 )
85
+
86
+
87
+ def test_basic_slice6 ():
88
+ q = get_queue_or_skip ()
89
+ i0 , n0 , n1 = 2 , 4 , 3
90
+ x = dpt .empty ((n0 , n1 ), dtype = "c8" , sycl_queue = q )
91
+ y = x [i0 , ::- 1 ]
92
+ assert isinstance (y , dpt .usm_ndarray )
93
+ assert y .shape == (x .shape [1 ],)
94
+ assert y .strides == (- x .strides [1 ],)
95
+ actual_offset = y .__sycl_usm_array_interface__ ["offset" ]
96
+ expected_offset = i0 * x .strides [0 ] + (n1 - 1 ) * x .strides [1 ]
97
+ assert actual_offset == expected_offset
98
+
99
+
100
+ def test_basic_slice7 ():
101
+ q = get_queue_or_skip ()
102
+ n0 , n1 , n2 = 5 , 3 , 2
103
+ x = dpt .empty ((n0 , n1 , n2 ), dtype = "?" , sycl_queue = q )
104
+ y = x [..., ::- 1 ]
105
+ assert isinstance (y , dpt .usm_ndarray )
106
+ assert y .shape == x .shape
107
+ assert y .strides == (
108
+ x .strides [0 ],
109
+ x .strides [1 ],
110
+ - x .strides [2 ],
111
+ )
112
+ actual_offset = y .__sycl_usm_array_interface__ ["offset" ]
113
+ expected_offset = (n2 - 1 ) * x .strides [2 ]
114
+ assert actual_offset == expected_offset
115
+
116
+
117
+ def test_basic_slice8 ():
118
+ q = get_queue_or_skip ()
119
+ n0 , n1 = 3 , 7
120
+ x = dpt .empty ((n0 , n1 ), dtype = "u1" , sycl_queue = q )
121
+ y = x [..., dpt .newaxis ]
122
+ assert isinstance (y , dpt .usm_ndarray )
123
+ assert y .shape == (n0 , n1 , 1 )
124
+ assert y .strides == (n1 , 1 , 0 )
125
+
126
+
127
+ def test_basic_slice9 ():
128
+ q = get_queue_or_skip ()
129
+ n0 , n1 = 3 , 7
130
+ x = dpt .empty ((n0 , n1 ), dtype = "u8" , sycl_queue = q )
131
+ y = x [dpt .newaxis , ...]
132
+ assert isinstance (y , dpt .usm_ndarray )
133
+ assert y .shape == (1 , n0 , n1 )
134
+ assert y .strides == (0 , n1 , 1 )
135
+
136
+
137
+ def test_basic_slice10 ():
138
+ q = get_queue_or_skip ()
139
+ n0 , n1 , n2 = 3 , 7 , 5
140
+ x = dpt .empty ((n0 , n1 , n2 ), dtype = "u1" , sycl_queue = q )
141
+ y = x [dpt .newaxis , ..., :]
142
+ assert isinstance (y , dpt .usm_ndarray )
143
+ assert y .shape == (1 , n0 , n1 , n2 )
144
+ assert y .strides == (0 , n1 * n2 , n2 , 1 )
145
+
146
+
147
+ def test_advanced_slice1 ():
148
+ q = get_queue_or_skip ()
149
+ ii = dpt .asarray ([1 , 2 ], sycl_queue = q )
150
+ x = dpt .arange (10 , dtype = "i4" , sycl_queue = q )
151
+ y = x [ii ]
152
+ assert isinstance (y , dpt .usm_ndarray )
153
+ assert y .shape == ii .shape
154
+ assert y .strides == (1 ,)
155
+ # FIXME, once usm_ndarray.__equal__ is implemented,
156
+ # use of asnumpy should be removed
157
+ assert all (
158
+ dpt .asnumpy (x [ii [k ]]) == dpt .asnumpy (y [k ]) for k in range (ii .shape [0 ])
159
+ )
0 commit comments