xobjects 0.4.5__tar.gz → 0.4.6__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.4.5 → xobjects-0.4.6}/PKG-INFO +1 -1
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_struct.py +87 -0
- xobjects-0.4.6/xobjects/_version.py +1 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/context_cpu.py +2 -1
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/test_helpers.py +20 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects.egg-info/PKG-INFO +1 -1
- xobjects-0.4.5/xobjects/_version.py +0 -1
- {xobjects-0.4.5 → xobjects-0.4.6}/.github/workflows/black.yml +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/.gitignore +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/.pre-commit-config.yaml +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/.readthedocs.yaml +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/Architecture.md +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/LICENSE +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/Readme.md +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/contributors_and_credits.txt +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/docs/Makefile +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/docs/architecture/contexts.rst +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/docs/architecture/types.rst +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/docs/architecture.rst +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/docs/conf.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/docs/index.rst +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/docs/make.bat +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/docs/quickstart.rst +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/docs/reference.rst +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/api_def.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/api_init.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/capi_example.c +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/check_assembly.c +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/ex_array_init_perf.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/ex_cpugpu.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/ex_nested_ref.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/ex_ref_cpu.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/ex_struct_cpu.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/ex_unionref_cpu.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/ex_unionref_method.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/init_soa.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/issue_with_two_pyopencl_contexts.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/kernel_basics/kernel_cffi.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/kernel_basics/kernel_cupy.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/kernel_basics/kernel_pyopencl.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/opencl_offsets.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/simple_kernel.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/examples/sixtracklib.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/mktest +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/pyproject.toml +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/release.sh +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/requirements.txt +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/setup.cfg +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/setup.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/__init__.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/__pycache__/test_context.cpython-37-pytest-6.2.1.pyc +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/notest_capi.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_align.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_array.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_buffer.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_capi.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_chunk.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_context_opencl.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_hybrid_class.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_kernel.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_linked_array.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_nplike_arrays.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_ref.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_scalars.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_shared_memory.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_strides.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_string.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_to_json.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_typeutils.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/tests/test_unionref.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/update_cprght_statement.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/__init__.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/_patch_pyopencl_array.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/array.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/capi.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/context.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/context_cupy.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/context_pyopencl.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/general.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/hybrid_class.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/linkedarray.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/ref.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/scalar.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/specialize_source.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/string.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/struct.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/typeutils.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects/union.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects.egg-info/SOURCES.txt +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects.egg-info/dependency_links.txt +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects.egg-info/requires.txt +0 -0
- {xobjects-0.4.5 → xobjects-0.4.6}/xobjects.egg-info/top_level.txt +0 -0
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# Copyright (c) CERN, 2021. #
|
|
4
4
|
# ########################################### #
|
|
5
5
|
import cffi
|
|
6
|
+
import numpy as np
|
|
6
7
|
|
|
7
8
|
import xobjects as xo
|
|
8
9
|
from xobjects.test_helpers import for_all_test_contexts, requires_context
|
|
@@ -213,6 +214,92 @@ def test_copy_dynamic():
|
|
|
213
214
|
assert s2.b[1] == 4
|
|
214
215
|
|
|
215
216
|
|
|
217
|
+
def test_kernel_namings():
|
|
218
|
+
class MyStruct(xo.Struct):
|
|
219
|
+
n = xo.Int32
|
|
220
|
+
var_mult_1 = xo.Float64[:]
|
|
221
|
+
var_mult_2 = xo.Float64[:]
|
|
222
|
+
var_mult_3 = xo.Float64[:]
|
|
223
|
+
var_mult_4 = xo.Float64[:]
|
|
224
|
+
|
|
225
|
+
_extra_c_sources = [
|
|
226
|
+
r"""
|
|
227
|
+
double mul(MyStruct stru) {
|
|
228
|
+
int32_t n = MyStruct_get_n(stru);
|
|
229
|
+
double* var_mult_1 = MyStruct_getp1_var_mult_1(stru, 0);
|
|
230
|
+
double* var_mult_2 = MyStruct_getp1_var_mult_2(stru, 0);
|
|
231
|
+
double y = 0;
|
|
232
|
+
for (int32_t tid=0; tid<n; tid++){
|
|
233
|
+
y+= var_mult_1[tid] * var_mult_2[tid];
|
|
234
|
+
}
|
|
235
|
+
return y;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
double mult(MyStruct stru) {
|
|
239
|
+
int32_t n = MyStruct_get_n(stru);
|
|
240
|
+
double* var_mult_1 = MyStruct_getp1_var_mult_1(stru, 0);
|
|
241
|
+
double* var_mult_2 = MyStruct_getp1_var_mult_2(stru, 0);
|
|
242
|
+
double* var_mult_3 = MyStruct_getp1_var_mult_3(stru, 0);
|
|
243
|
+
double y = 0;
|
|
244
|
+
for (int32_t tid=0; tid<n; tid++){
|
|
245
|
+
y+= var_mult_1[tid] * var_mult_2[tid] * var_mult_3[tid];
|
|
246
|
+
}
|
|
247
|
+
return y;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
double mult_four(MyStruct stru) {
|
|
251
|
+
int32_t n = MyStruct_get_n(stru);
|
|
252
|
+
double* var_mult_1 = MyStruct_getp1_var_mult_1(stru, 0);
|
|
253
|
+
double* var_mult_2 = MyStruct_getp1_var_mult_2(stru, 0);
|
|
254
|
+
double* var_mult_3 = MyStruct_getp1_var_mult_3(stru, 0);
|
|
255
|
+
double* var_mult_4 = MyStruct_getp1_var_mult_4(stru, 0);
|
|
256
|
+
double y = 0;
|
|
257
|
+
for (int32_t tid=0; tid<n; tid++){
|
|
258
|
+
y+= var_mult_1[tid] * var_mult_2[tid] * var_mult_3[tid] * var_mult_4[tid];
|
|
259
|
+
}
|
|
260
|
+
return y;
|
|
261
|
+
}"""
|
|
262
|
+
]
|
|
263
|
+
|
|
264
|
+
kernel_descriptions = {
|
|
265
|
+
"mul": xo.Kernel(
|
|
266
|
+
args=[xo.Arg(MyStruct, name="stru")],
|
|
267
|
+
ret=xo.Arg(xo.Float64),
|
|
268
|
+
),
|
|
269
|
+
"mult": xo.Kernel(
|
|
270
|
+
c_name="mult",
|
|
271
|
+
args=[xo.Arg(MyStruct, name="stru")],
|
|
272
|
+
ret=xo.Arg(xo.Float64),
|
|
273
|
+
),
|
|
274
|
+
"pyname_mul": xo.Kernel(
|
|
275
|
+
c_name="mult_four",
|
|
276
|
+
args=[xo.Arg(MyStruct, name="stru")],
|
|
277
|
+
ret=xo.Arg(xo.Float64),
|
|
278
|
+
),
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
a1 = np.arange(10.0)
|
|
282
|
+
a2 = np.arange(10.0)
|
|
283
|
+
a3 = np.arange(10.0)
|
|
284
|
+
a4 = np.arange(10.0)
|
|
285
|
+
stru = MyStruct(
|
|
286
|
+
n=10, var_mult_1=a1, var_mult_2=a2, var_mult_3=a3, var_mult_4=a4
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
ctx = stru._context
|
|
290
|
+
ctx.add_kernels(kernels=kernel_descriptions)
|
|
291
|
+
assert "mul" in ctx.kernels
|
|
292
|
+
# assert "mult" in ctx.kernels
|
|
293
|
+
assert "pyname_mul" in ctx.kernels
|
|
294
|
+
|
|
295
|
+
y = ctx.kernels.mul(stru=stru)
|
|
296
|
+
assert y == 285.0
|
|
297
|
+
y = ctx.kernels.mult(stru=stru)
|
|
298
|
+
assert y == 2025.0
|
|
299
|
+
y = ctx.kernels.pyname_mul(stru=stru)
|
|
300
|
+
assert y == 15333.0
|
|
301
|
+
|
|
302
|
+
|
|
216
303
|
@requires_context("ContextCpu")
|
|
217
304
|
def test_compile_kernels_only_if_needed(tmp_path, mocker):
|
|
218
305
|
"""Test the use case of xtrack.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.4.6"
|
|
@@ -398,7 +398,8 @@ class ContextCpu(XContext):
|
|
|
398
398
|
_print("Compiling ContextCpu kernels...")
|
|
399
399
|
|
|
400
400
|
for pyname, kernel in kernel_descriptions.items():
|
|
401
|
-
|
|
401
|
+
# check if kernel not already declared
|
|
402
|
+
if f" {kernel.c_name}(" not in cdefs:
|
|
402
403
|
signature = cdef_from_kernel(kernel, pyname)
|
|
403
404
|
ffi_interface.cdef(signature)
|
|
404
405
|
log.debug(f"cffi def {pyname} {signature}")
|
|
@@ -83,3 +83,23 @@ def requires_context(context_name: str):
|
|
|
83
83
|
return lambda test_function: test_function
|
|
84
84
|
|
|
85
85
|
return pytest.mark.skip(f"{context_name} is unavailable on this platform.")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def fix_random_seed(seed: int):
|
|
89
|
+
"""Decorator to fix the random seed for a test."""
|
|
90
|
+
|
|
91
|
+
def decorator(test_function):
|
|
92
|
+
@wraps(test_function)
|
|
93
|
+
def wrapper(*args, **kwargs):
|
|
94
|
+
import numpy as np
|
|
95
|
+
|
|
96
|
+
rng_state = np.random.get_state()
|
|
97
|
+
try:
|
|
98
|
+
np.random.seed(seed)
|
|
99
|
+
test_function(*args, **kwargs)
|
|
100
|
+
finally:
|
|
101
|
+
np.random.set_state(rng_state)
|
|
102
|
+
|
|
103
|
+
return wrapper
|
|
104
|
+
|
|
105
|
+
return decorator
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.4.5"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xobjects-0.4.5 → xobjects-0.4.6}/tests/__pycache__/test_context.cpython-37-pytest-6.2.1.pyc
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|