xobjects 0.2.6__tar.gz → 0.2.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {xobjects-0.2.6 → xobjects-0.2.7}/PKG-INFO +1 -1
- {xobjects-0.2.6 → xobjects-0.2.7}/setup.py +1 -1
- xobjects-0.2.7/xobjects/_version.py +1 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/context_cpu.py +11 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/context_cupy.py +12 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/context_pyopencl.py +7 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects.egg-info/PKG-INFO +1 -1
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects.egg-info/SOURCES.txt +0 -17
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects.egg-info/requires.txt +1 -0
- xobjects-0.2.6/tests/test_align.py +0 -18
- xobjects-0.2.6/tests/test_array.py +0 -303
- xobjects-0.2.6/tests/test_buffer.py +0 -135
- xobjects-0.2.6/tests/test_capi.py +0 -583
- xobjects-0.2.6/tests/test_chunk.py +0 -23
- xobjects-0.2.6/tests/test_hybrid_class.py +0 -312
- xobjects-0.2.6/tests/test_kernel.py +0 -263
- xobjects-0.2.6/tests/test_linked_array.py +0 -89
- xobjects-0.2.6/tests/test_nplike_arrays.py +0 -163
- xobjects-0.2.6/tests/test_ref.py +0 -340
- xobjects-0.2.6/tests/test_scalars.py +0 -40
- xobjects-0.2.6/tests/test_strides.py +0 -41
- xobjects-0.2.6/tests/test_string.py +0 -51
- xobjects-0.2.6/tests/test_struct.py +0 -262
- xobjects-0.2.6/tests/test_to_json.py +0 -41
- xobjects-0.2.6/tests/test_typeutils.py +0 -104
- xobjects-0.2.6/tests/test_unionref.py +0 -74
- xobjects-0.2.6/xobjects/_version.py +0 -1
- {xobjects-0.2.6 → xobjects-0.2.7}/LICENSE +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/pyproject.toml +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/setup.cfg +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/__init__.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/_patch_pyopencl_array.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/array.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/capi.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/context.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/general.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/hybrid_class.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/linkedarray.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/ref.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/scalar.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/specialize_source.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/string.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/struct.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/test_helpers.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/typeutils.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects/union.py +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects.egg-info/dependency_links.txt +0 -0
- {xobjects-0.2.6 → xobjects-0.2.7}/xobjects.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.7"
|
|
@@ -14,6 +14,7 @@ from typing import Callable, Dict, List, Sequence, Tuple
|
|
|
14
14
|
from .general import _print
|
|
15
15
|
|
|
16
16
|
import numpy as np
|
|
17
|
+
import scipy as sp
|
|
17
18
|
|
|
18
19
|
from .context import (
|
|
19
20
|
Kernel,
|
|
@@ -535,6 +536,16 @@ class ContextCpu(XContext):
|
|
|
535
536
|
|
|
536
537
|
return np
|
|
537
538
|
|
|
539
|
+
@property
|
|
540
|
+
def splike_lib(self):
|
|
541
|
+
"""
|
|
542
|
+
Module containing all the scipy features. Numpy members should be accessed
|
|
543
|
+
through ``splike_lib`` to keep compatibility with the other contexts.
|
|
544
|
+
|
|
545
|
+
"""
|
|
546
|
+
|
|
547
|
+
return sp
|
|
548
|
+
|
|
538
549
|
def synchronize(self):
|
|
539
550
|
"""
|
|
540
551
|
Ensures that all computations submitted to the context are completed.
|
|
@@ -26,6 +26,11 @@ log = logging.getLogger(__name__)
|
|
|
26
26
|
|
|
27
27
|
try:
|
|
28
28
|
import cupy
|
|
29
|
+
import cupyx.scipy
|
|
30
|
+
import cupyx.scipy.interpolate
|
|
31
|
+
import cupyx.scipy.signal
|
|
32
|
+
import cupyx.scipy.special
|
|
33
|
+
import cupyx.scipy.stats
|
|
29
34
|
from cupyx.scipy import fftpack as cufftp
|
|
30
35
|
|
|
31
36
|
_enabled = True
|
|
@@ -500,6 +505,13 @@ class ContextCupy(XContext):
|
|
|
500
505
|
"""
|
|
501
506
|
return cupy
|
|
502
507
|
|
|
508
|
+
@property
|
|
509
|
+
def splike_lib(self):
|
|
510
|
+
"""
|
|
511
|
+
Module containing all the scipy features supported by cupy.
|
|
512
|
+
"""
|
|
513
|
+
return cupyx.scipy
|
|
514
|
+
|
|
503
515
|
def synchronize(self):
|
|
504
516
|
"""
|
|
505
517
|
Ensures that all computations submitted to the context are completed.
|
|
@@ -273,6 +273,13 @@ class ContextPyopencl(XContext):
|
|
|
273
273
|
"""
|
|
274
274
|
return cla
|
|
275
275
|
|
|
276
|
+
@property
|
|
277
|
+
def splike_lib(self):
|
|
278
|
+
"""
|
|
279
|
+
Scipy features are not available through openCL
|
|
280
|
+
"""
|
|
281
|
+
raise NotImplementedError
|
|
282
|
+
|
|
276
283
|
def synchronize(self):
|
|
277
284
|
"""
|
|
278
285
|
Ensures that all computations submitted to the context are completed.
|
|
@@ -2,23 +2,6 @@ LICENSE
|
|
|
2
2
|
pyproject.toml
|
|
3
3
|
setup.cfg
|
|
4
4
|
setup.py
|
|
5
|
-
tests/test_align.py
|
|
6
|
-
tests/test_array.py
|
|
7
|
-
tests/test_buffer.py
|
|
8
|
-
tests/test_capi.py
|
|
9
|
-
tests/test_chunk.py
|
|
10
|
-
tests/test_hybrid_class.py
|
|
11
|
-
tests/test_kernel.py
|
|
12
|
-
tests/test_linked_array.py
|
|
13
|
-
tests/test_nplike_arrays.py
|
|
14
|
-
tests/test_ref.py
|
|
15
|
-
tests/test_scalars.py
|
|
16
|
-
tests/test_strides.py
|
|
17
|
-
tests/test_string.py
|
|
18
|
-
tests/test_struct.py
|
|
19
|
-
tests/test_to_json.py
|
|
20
|
-
tests/test_typeutils.py
|
|
21
|
-
tests/test_unionref.py
|
|
22
5
|
xobjects/__init__.py
|
|
23
6
|
xobjects/_patch_pyopencl_array.py
|
|
24
7
|
xobjects/_version.py
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# copyright ################################# #
|
|
2
|
-
# This file is part of the Xobjects Package. #
|
|
3
|
-
# Copyright (c) CERN, 2021. #
|
|
4
|
-
# ########################################### #
|
|
5
|
-
|
|
6
|
-
import xobjects as xo
|
|
7
|
-
from xobjects.test_helpers import for_all_test_contexts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@for_all_test_contexts
|
|
11
|
-
def test_create_aligned_objects(test_context):
|
|
12
|
-
for Arr in xo.Float64[3], xo.Float64[16], xo.Float64[17]:
|
|
13
|
-
buff = test_context.new_buffer(10)
|
|
14
|
-
assert buff.default_alignment == test_context.minimum_alignment
|
|
15
|
-
for i in range(4):
|
|
16
|
-
aa = Arr(_buffer=buff, _offset="aligned")
|
|
17
|
-
print(test_context, Arr._size, aa._offset)
|
|
18
|
-
assert aa._offset % test_context.minimum_alignment == 0
|
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
# copyright ################################# #
|
|
2
|
-
# This file is part of the Xobjects Package. #
|
|
3
|
-
# Copyright (c) CERN, 2021. #
|
|
4
|
-
# ########################################### #
|
|
5
|
-
|
|
6
|
-
# pylint:disable=E1101
|
|
7
|
-
|
|
8
|
-
import numpy as np
|
|
9
|
-
import pytest
|
|
10
|
-
|
|
11
|
-
import xobjects as xo
|
|
12
|
-
from xobjects.test_helpers import for_all_test_contexts
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def test_get_shape():
|
|
16
|
-
from xobjects.array import get_shape_from_array
|
|
17
|
-
|
|
18
|
-
assert get_shape_from_array(0, 0) == ()
|
|
19
|
-
assert get_shape_from_array([], 1) == (0,)
|
|
20
|
-
assert get_shape_from_array([1, 2, 3], 1) == (3,)
|
|
21
|
-
assert get_shape_from_array(range(3), 1) == (3,)
|
|
22
|
-
assert get_shape_from_array([[], []], 2) == (2, 0)
|
|
23
|
-
assert get_shape_from_array([[2], [2]], 2) == (2, 1)
|
|
24
|
-
assert get_shape_from_array([[1, 3], [3]], 1) == (2,)
|
|
25
|
-
assert get_shape_from_array([[1, [2]], [[3], [4, 5]]], 2) == (2, 2)
|
|
26
|
-
|
|
27
|
-
with pytest.raises(ValueError):
|
|
28
|
-
get_shape_from_array([[1, [2]], [[3], [4, 5]]], 3)
|
|
29
|
-
get_shape_from_array([[1], [2, 3], [4, 5, 6]], 2)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def mk_classes() -> xo.Array:
|
|
33
|
-
class ArrayA(xo.Array):
|
|
34
|
-
_itemtype = xo.Float64
|
|
35
|
-
_shape = (6, 6)
|
|
36
|
-
_order = (0, 1)
|
|
37
|
-
|
|
38
|
-
class ArrayB(xo.Array):
|
|
39
|
-
_itemtype = xo.Float64
|
|
40
|
-
_shape = (6, None)
|
|
41
|
-
_order = (0, 1)
|
|
42
|
-
|
|
43
|
-
class ArrayC(xo.Array):
|
|
44
|
-
_itemtype = xo.Float64
|
|
45
|
-
_shape = (None,)
|
|
46
|
-
_order = "C"
|
|
47
|
-
|
|
48
|
-
class ArrayD(xo.Array):
|
|
49
|
-
_itemtype = ArrayA
|
|
50
|
-
_shape = (None,)
|
|
51
|
-
_order = "F"
|
|
52
|
-
|
|
53
|
-
class ArrayE(xo.Array):
|
|
54
|
-
_itemtype = ArrayB
|
|
55
|
-
_shape = (None,)
|
|
56
|
-
_order = "C"
|
|
57
|
-
|
|
58
|
-
return ArrayA, ArrayB, ArrayC, ArrayD, ArrayE
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def test_class_creation():
|
|
62
|
-
ArrayA, ArrayB, ArrayC, ArrayD, ArrayE = mk_classes()
|
|
63
|
-
|
|
64
|
-
assert ArrayA._is_static_shape == True
|
|
65
|
-
assert ArrayE._is_static_type == False
|
|
66
|
-
assert ArrayA._size == 36 * 8
|
|
67
|
-
|
|
68
|
-
for arr in ArrayB, ArrayC, ArrayD, ArrayE:
|
|
69
|
-
assert arr._is_static_shape == False
|
|
70
|
-
for arr in ArrayB, ArrayC, ArrayD, ArrayE:
|
|
71
|
-
assert arr._is_static_shape == False
|
|
72
|
-
|
|
73
|
-
assert ArrayA._data_offset == 0
|
|
74
|
-
assert ArrayB._data_offset == 32
|
|
75
|
-
assert ArrayC._data_offset == 16
|
|
76
|
-
assert ArrayD._data_offset == 16
|
|
77
|
-
assert ArrayE._data_offset == 16
|
|
78
|
-
|
|
79
|
-
assert ArrayA._strides == (48, 8)
|
|
80
|
-
assert ArrayC._strides == (8,)
|
|
81
|
-
assert ArrayD._strides == (ArrayA._size,)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def test_class_mk_array():
|
|
85
|
-
ArrayA = xo.Float64[3, 6]
|
|
86
|
-
assert ArrayA._shape == (3, 6)
|
|
87
|
-
assert ArrayA._order == (0, 1)
|
|
88
|
-
assert ArrayA.__name__ == "Arr3x6Float64"
|
|
89
|
-
|
|
90
|
-
ArrayA = xo.Float64[None, 6]
|
|
91
|
-
assert ArrayA._shape == (None, 6)
|
|
92
|
-
assert ArrayA.__name__ == "ArrNx6Float64"
|
|
93
|
-
|
|
94
|
-
ArrayA = xo.String[3:1, 4:0, 5:2]
|
|
95
|
-
assert ArrayA._shape == (3, 4, 5)
|
|
96
|
-
assert ArrayA.__name__ == "Arr3x4x5String"
|
|
97
|
-
|
|
98
|
-
class StructA(xo.Struct):
|
|
99
|
-
a = xo.Float64
|
|
100
|
-
|
|
101
|
-
ArrayA = StructA[10]
|
|
102
|
-
|
|
103
|
-
assert ArrayA.__name__ == "Arr10StructA"
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
def test_inspect_args():
|
|
107
|
-
import numpy as np
|
|
108
|
-
|
|
109
|
-
arrays = mk_classes()
|
|
110
|
-
|
|
111
|
-
for AnArray in arrays:
|
|
112
|
-
if AnArray._size is not None:
|
|
113
|
-
info = AnArray._inspect_args()
|
|
114
|
-
assert info.value == None
|
|
115
|
-
|
|
116
|
-
ArrayA = arrays[0]
|
|
117
|
-
info = ArrayA._inspect_args(np.zeros((6, 6)))
|
|
118
|
-
|
|
119
|
-
assert info.size == 36 * 8
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
def test_array_allocation():
|
|
123
|
-
MyArray = xo.Int64[10]
|
|
124
|
-
ss = MyArray()
|
|
125
|
-
assert ss._itemtype == xo.Int64
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
def test_array_sshape_stype():
|
|
129
|
-
Array1D = xo.Int64[3]
|
|
130
|
-
Array2D = xo.Int64[2, 3]
|
|
131
|
-
Array3D = xo.Int64[2, 3, 4]
|
|
132
|
-
|
|
133
|
-
for cls in Array1D, Array2D, Array3D:
|
|
134
|
-
ss = cls()
|
|
135
|
-
for ii in ss._iter_index():
|
|
136
|
-
assert ss[0] == 0
|
|
137
|
-
ss[ii] = sum(ii) if len(ss._shape) > 1 else ii
|
|
138
|
-
for ii in ss._iter_index():
|
|
139
|
-
assert ss[ii] == (sum(ii) if len(ss._shape) > 1 else ii)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def test_array_dshape_stype():
|
|
143
|
-
Array1 = xo.Int64[:]
|
|
144
|
-
Array2 = xo.Int64[:, 3, 4]
|
|
145
|
-
Array3 = xo.Int64[2, :, 4]
|
|
146
|
-
Array4 = xo.Int64[2, 3, :]
|
|
147
|
-
|
|
148
|
-
for cls in Array1, Array2, Array3, Array4:
|
|
149
|
-
ss = cls(3)
|
|
150
|
-
for ii in ss._iter_index():
|
|
151
|
-
assert ss[0] == 0
|
|
152
|
-
ss[ii] = sum(ii) if len(ss._shape) > 1 else ii
|
|
153
|
-
for ii in ss._iter_index():
|
|
154
|
-
assert ss[ii] == (sum(ii) if len(ss._shape) > 1 else ii)
|
|
155
|
-
|
|
156
|
-
arr = Array1(10)
|
|
157
|
-
arr[3] = 42
|
|
158
|
-
data = arr._buffer.to_nplike(arr._offset, "int64", (12,))
|
|
159
|
-
assert data[0] == 8 + 8 + 10 * 8
|
|
160
|
-
assert data[1] == 10
|
|
161
|
-
data[6] = 43
|
|
162
|
-
assert arr[4] == 43
|
|
163
|
-
|
|
164
|
-
arr = Array2(2)
|
|
165
|
-
arr[1, 2, 3] = 42
|
|
166
|
-
data = arr._buffer.to_nplike(arr._offset, "int64", (29,))
|
|
167
|
-
|
|
168
|
-
assert data[0] == 8 + 8 + 3 * 8 + 24 * 8
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
def test_array_sshape_dtype():
|
|
172
|
-
Array1 = xo.Int64[:]
|
|
173
|
-
Array2 = Array1[3]
|
|
174
|
-
arr = Array2([2, 3, 4])
|
|
175
|
-
arr[0][1] = 3
|
|
176
|
-
assert arr[0][1] == 3
|
|
177
|
-
|
|
178
|
-
arr1 = Array1(2)
|
|
179
|
-
assert arr1._shape == arr[0]._shape
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
def test_array_dshape_dtype():
|
|
183
|
-
Array1 = xo.Int64[:]
|
|
184
|
-
Array2 = Array1[:]
|
|
185
|
-
ss = Array2([2, 3, 4])
|
|
186
|
-
ss[0][1] = 3
|
|
187
|
-
assert ss[0][1] == 3
|
|
188
|
-
|
|
189
|
-
ss0 = Array1(2)
|
|
190
|
-
ss1 = Array1(3)
|
|
191
|
-
ss2 = Array1(4)
|
|
192
|
-
assert ss0._shape == ss[0]._shape
|
|
193
|
-
|
|
194
|
-
ss = Array2([[1], [2, 3], [4, 5, 6]])
|
|
195
|
-
assert ss[0][0] == 1
|
|
196
|
-
assert ss[1][1] == 3
|
|
197
|
-
assert ss[2][2] == 6
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
def test_array_in_struct():
|
|
201
|
-
class Multipole(xo.Struct):
|
|
202
|
-
order = xo.Int64
|
|
203
|
-
length = xo.Float64
|
|
204
|
-
hxl = xo.Float64
|
|
205
|
-
hyl = xo.Float64
|
|
206
|
-
bal = xo.Float64[:]
|
|
207
|
-
|
|
208
|
-
m = Multipole(order=2, bal=np.array([1.0, 2.0, 3.0, 4.0]))
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
def test_initialize_from_array():
|
|
212
|
-
class MyStruct(xo.Struct):
|
|
213
|
-
a = xo.Float64[3]
|
|
214
|
-
|
|
215
|
-
sa = MyStruct()
|
|
216
|
-
buf = sa._buffer
|
|
217
|
-
sb = MyStruct(_buffer=buf)
|
|
218
|
-
sa.a = sb.a
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
def test_init_with_nparray():
|
|
222
|
-
a = xo.Float64[:](np.array([1, 2, 3], dtype=np.float64))
|
|
223
|
-
assert a[1] == 2.0
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
def test_init_with_nparray2d():
|
|
227
|
-
class Mys(xo.Struct):
|
|
228
|
-
m0 = xo.Float64[6]
|
|
229
|
-
m1 = xo.Float64[6, 6]
|
|
230
|
-
|
|
231
|
-
m = Mys(m1=np.ones((6, 6)) * 3, m0=np.ones(6))
|
|
232
|
-
assert m.m1[3, 4] == 3
|
|
233
|
-
assert m.m0[3] == 1
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
def test_update():
|
|
237
|
-
class A(xo.Struct):
|
|
238
|
-
a = xo.Float64[:]
|
|
239
|
-
b = xo.Float64[10]
|
|
240
|
-
|
|
241
|
-
a = A(a=3)
|
|
242
|
-
with pytest.raises(Exception) as e:
|
|
243
|
-
a.a = 2
|
|
244
|
-
assert e.type == ValueError
|
|
245
|
-
|
|
246
|
-
with pytest.raises(Exception) as e:
|
|
247
|
-
a.a = [1, 2]
|
|
248
|
-
assert e.type == ValueError
|
|
249
|
-
|
|
250
|
-
a.a = [1, 2, 3]
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
@for_all_test_contexts
|
|
254
|
-
def test_array_custom_strides(test_context):
|
|
255
|
-
Array = xo.Int8[2:1, 3:0, 4:2]
|
|
256
|
-
a_xo = Array(_context=test_context)
|
|
257
|
-
|
|
258
|
-
assert a_xo._strides == (4, 8, 1)
|
|
259
|
-
|
|
260
|
-
j = 0
|
|
261
|
-
for i0, i1, i2 in np.ndindex(2, 3, 4):
|
|
262
|
-
a_xo[i0, i1, i2] = j
|
|
263
|
-
j += 1
|
|
264
|
-
|
|
265
|
-
buffer_contents = a_xo._buffer.to_bytearray(
|
|
266
|
-
offset=0, nbytes=a_xo._buffer.capacity
|
|
267
|
-
)
|
|
268
|
-
assert np.all(
|
|
269
|
-
buffer_contents
|
|
270
|
-
== bytearray(
|
|
271
|
-
[
|
|
272
|
-
0,
|
|
273
|
-
1,
|
|
274
|
-
2,
|
|
275
|
-
3,
|
|
276
|
-
12,
|
|
277
|
-
13,
|
|
278
|
-
14,
|
|
279
|
-
15,
|
|
280
|
-
4,
|
|
281
|
-
5,
|
|
282
|
-
6,
|
|
283
|
-
7,
|
|
284
|
-
16,
|
|
285
|
-
17,
|
|
286
|
-
18,
|
|
287
|
-
19,
|
|
288
|
-
8,
|
|
289
|
-
9,
|
|
290
|
-
10,
|
|
291
|
-
11,
|
|
292
|
-
20,
|
|
293
|
-
21,
|
|
294
|
-
22,
|
|
295
|
-
23,
|
|
296
|
-
]
|
|
297
|
-
)
|
|
298
|
-
)
|
|
299
|
-
|
|
300
|
-
j = 0
|
|
301
|
-
for i0, i1, i2 in np.ndindex(2, 3, 4):
|
|
302
|
-
assert a_xo[i0, i1, i2] == j
|
|
303
|
-
j += 1
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
# copyright ################################# #
|
|
2
|
-
# This file is part of the Xobjects Package. #
|
|
3
|
-
# Copyright (c) CERN, 2021. #
|
|
4
|
-
# ########################################### #
|
|
5
|
-
|
|
6
|
-
import numpy as np
|
|
7
|
-
|
|
8
|
-
import xobjects as xo
|
|
9
|
-
from xobjects.test_helpers import for_all_test_contexts, requires_context
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class Check:
|
|
13
|
-
def __init__(self, ctx, capacity):
|
|
14
|
-
self.ctx = ctx
|
|
15
|
-
self.buffer = ctx.new_buffer(capacity=capacity)
|
|
16
|
-
self.state = {}
|
|
17
|
-
|
|
18
|
-
def random_string(self, maxlength=100):
|
|
19
|
-
size = np.random.randint(1, maxlength)
|
|
20
|
-
self.new_string(size)
|
|
21
|
-
|
|
22
|
-
def new_string(self, size=100):
|
|
23
|
-
if size > 0:
|
|
24
|
-
data = bytes(np.random.randint(65, 90, size, dtype="u1"))
|
|
25
|
-
|
|
26
|
-
offset = self.buffer.allocate(len(data))
|
|
27
|
-
self.buffer.update_from_buffer(offset, data)
|
|
28
|
-
self.state[offset] = data
|
|
29
|
-
return offset
|
|
30
|
-
else:
|
|
31
|
-
raise ValueError("size must be >0")
|
|
32
|
-
|
|
33
|
-
def free_string(self, offset):
|
|
34
|
-
size = len(self.state[offset])
|
|
35
|
-
self.buffer.free(offset, size)
|
|
36
|
-
del self.state[offset]
|
|
37
|
-
|
|
38
|
-
def random_free(self):
|
|
39
|
-
ii = np.random.randint(1, len(self.state))
|
|
40
|
-
offset = list(self.state.keys())[ii]
|
|
41
|
-
self.free_string(offset)
|
|
42
|
-
|
|
43
|
-
def check(self):
|
|
44
|
-
for offset, value in self.state.items():
|
|
45
|
-
assert self.buffer.to_bytearray(offset, len(value)) == value
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
@requires_context("ContextPyopencl")
|
|
49
|
-
def test_cl_print_devices():
|
|
50
|
-
xo.ContextPyopencl.print_devices()
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
@requires_context("ContextPyopencl")
|
|
54
|
-
def test_cl_init():
|
|
55
|
-
_ = xo.ContextPyopencl(device="0.0")
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
@for_all_test_contexts
|
|
59
|
-
def test_new_buffer(test_context):
|
|
60
|
-
_ = test_context.new_buffer()
|
|
61
|
-
_ = test_context.new_buffer(capacity=200)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
@for_all_test_contexts
|
|
65
|
-
def test_read_write(test_context):
|
|
66
|
-
buff = test_context.new_buffer()
|
|
67
|
-
bb = b"asdfasdfafsdf"
|
|
68
|
-
buff.update_from_buffer(23, bb)
|
|
69
|
-
assert buff.to_bytearray(23, len(bb)) == bb
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
@for_all_test_contexts
|
|
73
|
-
def test_to_from_byterarray(test_context):
|
|
74
|
-
buff = test_context.new_buffer()
|
|
75
|
-
bb = b"asdfasdfafsdf"
|
|
76
|
-
buff.update_from_buffer(23, bb)
|
|
77
|
-
assert buff.to_bytearray(23, len(bb)) == bb
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
@for_all_test_contexts
|
|
81
|
-
def test_allocate_simple(test_context):
|
|
82
|
-
ch = Check(test_context, 200)
|
|
83
|
-
ch.new_string(30)
|
|
84
|
-
ch.check()
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
@for_all_test_contexts
|
|
88
|
-
def test_free_simple(test_context):
|
|
89
|
-
ch = Check(test_context, 200)
|
|
90
|
-
offsets = [ch.new_string(ii * 2 + 1) for ii in range(10)]
|
|
91
|
-
print(offsets)
|
|
92
|
-
for offset in offsets:
|
|
93
|
-
print(offset)
|
|
94
|
-
ch.free_string(offset)
|
|
95
|
-
ch.check()
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
@for_all_test_contexts
|
|
99
|
-
def test_grow(test_context):
|
|
100
|
-
ch = Check(test_context, 200)
|
|
101
|
-
st = ch.new_string(150)
|
|
102
|
-
st = ch.new_string(60)
|
|
103
|
-
ch.check()
|
|
104
|
-
assert ch.buffer.capacity == 400
|
|
105
|
-
assert ch.buffer.chunks[0].start == st + 60
|
|
106
|
-
assert ch.buffer.chunks[0].end == 400
|
|
107
|
-
st = ch.new_string(500)
|
|
108
|
-
assert ch.buffer.capacity == 900 + ch.buffer.default_alignment - 1
|
|
109
|
-
ch.check()
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
@for_all_test_contexts
|
|
113
|
-
def test_random_string(test_context):
|
|
114
|
-
ch = Check(test_context, 200)
|
|
115
|
-
|
|
116
|
-
for i in range(50):
|
|
117
|
-
ch.random_string(maxlength=2000)
|
|
118
|
-
ch.check()
|
|
119
|
-
|
|
120
|
-
for i in range(50):
|
|
121
|
-
ch.random_string(maxlength=2000)
|
|
122
|
-
ch.check()
|
|
123
|
-
ch.random_free()
|
|
124
|
-
ch.check()
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
@for_all_test_contexts
|
|
128
|
-
def test_nplike(test_context):
|
|
129
|
-
buff = test_context.new_buffer(capacity=80)
|
|
130
|
-
arr = np.arange(6.0).reshape((2, 3))
|
|
131
|
-
offset = 3
|
|
132
|
-
buff.update_from_buffer(offset, arr.tobytes())
|
|
133
|
-
arr2 = buff.to_nplike(offset, "float64", (2, 3))
|
|
134
|
-
arr3 = test_context.nparray_from_context_array(arr2)
|
|
135
|
-
assert np.all(arr == arr3)
|