xobjects 0.5.4__tar.gz → 0.5.5__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.5.4/xobjects.egg-info → xobjects-0.5.5}/PKG-INFO +1 -1
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_buffer.py +7 -5
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_hybrid_class.py +75 -0
- xobjects-0.5.4/tests/test_to_json.py → xobjects-0.5.5/tests/test_to_dict.py +4 -4
- xobjects-0.5.5/xobjects/_version.py +1 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/array.py +5 -2
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/context_cupy.py +5 -1
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/hybrid_class.py +10 -2
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/ref.py +5 -2
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/struct.py +5 -5
- {xobjects-0.5.4 → xobjects-0.5.5/xobjects.egg-info}/PKG-INFO +1 -1
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects.egg-info/SOURCES.txt +1 -1
- xobjects-0.5.4/xobjects/_version.py +0 -1
- {xobjects-0.5.4 → xobjects-0.5.5}/LICENSE +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/pyproject.toml +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/setup.cfg +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/setup.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_align.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_array.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_capi.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_chunk.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_context_opencl.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_kernel.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_linked_array.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_nplike_arrays.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_ref.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_scalars.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_shared_memory.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_strides.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_string.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_struct.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_typeutils.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/tests/test_unionref.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/__init__.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/_patch_pyopencl_array.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/capi.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/context.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/context_cpu.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/context_pyopencl.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/general.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/linkedarray.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/scalar.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/specialize_source.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/string.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/test_helpers.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/typeutils.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects/union.py +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects.egg-info/dependency_links.txt +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects.egg-info/requires.txt +0 -0
- {xobjects-0.5.4 → xobjects-0.5.5}/xobjects.egg-info/top_level.txt +0 -0
|
@@ -95,10 +95,12 @@ def test_free_simple(test_context):
|
|
|
95
95
|
ch.free_string(offset)
|
|
96
96
|
ch.check()
|
|
97
97
|
|
|
98
|
+
|
|
98
99
|
@for_all_test_contexts
|
|
99
100
|
def test_free(test_context):
|
|
100
101
|
class CheckFree(xo.Struct):
|
|
101
102
|
a = xo.Float64
|
|
103
|
+
|
|
102
104
|
ch = CheckFree(a=5, _context=test_context)
|
|
103
105
|
assert ch._buffer.capacity == 8
|
|
104
106
|
assert ch._buffer.chunks == []
|
|
@@ -107,17 +109,17 @@ def test_free(test_context):
|
|
|
107
109
|
with pytest.raises(ValueError, match="Cannot free outside of buffer"):
|
|
108
110
|
ch._buffer.free(0, 10)
|
|
109
111
|
with pytest.raises(ValueError, match="Cannot free outside of buffer"):
|
|
110
|
-
ch._buffer.free(7,2)
|
|
111
|
-
ch._buffer.free(0,4)
|
|
112
|
+
ch._buffer.free(7, 2)
|
|
113
|
+
ch._buffer.free(0, 4)
|
|
112
114
|
assert len(ch._buffer.chunks) == 1
|
|
113
115
|
assert ch._buffer.chunks[0].start == 0
|
|
114
116
|
assert ch._buffer.chunks[0].end == 4
|
|
115
|
-
ch._buffer.free(0,4) # Does nothing
|
|
116
|
-
ch._buffer.free(2,4) # Increases free chunk
|
|
117
|
+
ch._buffer.free(0, 4) # Does nothing
|
|
118
|
+
ch._buffer.free(2, 4) # Increases free chunk
|
|
117
119
|
assert len(ch._buffer.chunks) == 1
|
|
118
120
|
assert ch._buffer.chunks[0].start == 0
|
|
119
121
|
assert ch._buffer.chunks[0].end == 6
|
|
120
|
-
ch._buffer.free(7,1)
|
|
122
|
+
ch._buffer.free(7, 1)
|
|
121
123
|
assert len(ch._buffer.chunks) == 2
|
|
122
124
|
assert ch._buffer.chunks[0].start == 0
|
|
123
125
|
assert ch._buffer.chunks[0].end == 6
|
|
@@ -330,3 +330,78 @@ def test_to_json_defaults():
|
|
|
330
330
|
assert np.all(b_dict.pop("a") == [1, 2, 3])
|
|
331
331
|
assert b_dict.pop("d") == 8
|
|
332
332
|
assert b_dict == {}
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def test_to_dict_python_vars():
|
|
336
|
+
class TD(xo.HybridClass):
|
|
337
|
+
_xofields = {
|
|
338
|
+
"_a": xo.Float64[3],
|
|
339
|
+
"_b": xo.Int64,
|
|
340
|
+
}
|
|
341
|
+
_skip_in_to_dict = ["_a", "_b"]
|
|
342
|
+
_store_in_to_dict = ["a", "b", "c"]
|
|
343
|
+
|
|
344
|
+
def __init__(self, **kwargs):
|
|
345
|
+
if "_xobject" in kwargs and kwargs["_xobject"] is not None:
|
|
346
|
+
self.xoinitialize(**kwargs)
|
|
347
|
+
return
|
|
348
|
+
kwargs["_a"] = kwargs.pop("a", [1.0, 2.0, 3.0])
|
|
349
|
+
kwargs["_b"] = kwargs.pop("b", 0)
|
|
350
|
+
self._initialize(**kwargs)
|
|
351
|
+
|
|
352
|
+
def _initialize(self, **kwargs):
|
|
353
|
+
# Need to handle non-xofields manually
|
|
354
|
+
c = kwargs.pop("c", -9)
|
|
355
|
+
super().__init__(**kwargs)
|
|
356
|
+
self._c = c
|
|
357
|
+
|
|
358
|
+
@property
|
|
359
|
+
def a(self):
|
|
360
|
+
return self._a
|
|
361
|
+
|
|
362
|
+
@property
|
|
363
|
+
def b(self):
|
|
364
|
+
return self._b
|
|
365
|
+
|
|
366
|
+
@property
|
|
367
|
+
def c(self):
|
|
368
|
+
return self._c
|
|
369
|
+
|
|
370
|
+
# Verify that to_dict has all fields, including python-only ones,
|
|
371
|
+
# for default initialisation
|
|
372
|
+
td1 = TD()
|
|
373
|
+
td1_dict = td1.to_dict()
|
|
374
|
+
assert td1_dict.pop("__class__") == "TD"
|
|
375
|
+
assert all(td1_dict.pop("a") == [1, 2, 3])
|
|
376
|
+
assert td1_dict.pop("b") == 0
|
|
377
|
+
assert td1_dict.pop("c") == -9
|
|
378
|
+
assert td1_dict == {}
|
|
379
|
+
|
|
380
|
+
# Verify that to_dict has all fields, including python-only ones,
|
|
381
|
+
# for custom initialisation
|
|
382
|
+
td2 = TD(a=[8, 9, 10], b=40, c=20)
|
|
383
|
+
td2_dict = td2.to_dict()
|
|
384
|
+
assert td2_dict.pop("__class__") == "TD"
|
|
385
|
+
assert all(td2_dict.pop("a") == [8, 9, 10])
|
|
386
|
+
assert td2_dict.pop("b") == 40
|
|
387
|
+
assert td2_dict.pop("c") == 20
|
|
388
|
+
assert td2_dict == {}
|
|
389
|
+
|
|
390
|
+
# Verify that from_dict works correctly
|
|
391
|
+
td2_dict = td2.to_dict()
|
|
392
|
+
td3 = TD.from_dict(td2_dict)
|
|
393
|
+
assert all(td3.a == td2.a)
|
|
394
|
+
assert td3.b == td2.b
|
|
395
|
+
assert td3.c == td2.c
|
|
396
|
+
|
|
397
|
+
# Verify that copy works correctly
|
|
398
|
+
td4 = td3.copy()
|
|
399
|
+
assert all(td4.a == td2.a)
|
|
400
|
+
assert td4.b == td2.b
|
|
401
|
+
assert td4.c == td2.c
|
|
402
|
+
|
|
403
|
+
# Verify that move works correctly
|
|
404
|
+
td3.move(_context=xo.ContextCpu(omp_num_threads="auto"))
|
|
405
|
+
assert all(td3.a == td2.a)
|
|
406
|
+
assert td3.b == td2.b
|
|
407
|
+
assert td3.c == td2.c
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import xobjects as xo
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
def
|
|
4
|
+
def test_to_dict():
|
|
5
5
|
class A(xo.Struct):
|
|
6
6
|
a = xo.Float64[:]
|
|
7
7
|
b = xo.Int64
|
|
@@ -11,14 +11,14 @@ def test_to_json():
|
|
|
11
11
|
|
|
12
12
|
x = A(a=[2, 3], b=1)
|
|
13
13
|
u = Uref(x)
|
|
14
|
-
v = Uref(*u.
|
|
14
|
+
v = Uref(*u._to_dict())
|
|
15
15
|
|
|
16
16
|
assert v.get().a[0] == 2
|
|
17
17
|
assert v.get().a[1] == 3
|
|
18
18
|
assert v.get().b == 1
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
def
|
|
21
|
+
def test_to_dict_array():
|
|
22
22
|
class A(xo.Struct):
|
|
23
23
|
a = xo.Float64[:]
|
|
24
24
|
|
|
@@ -35,7 +35,7 @@ def test_to_json_array():
|
|
|
35
35
|
a[1] = A(a=[3])
|
|
36
36
|
a[5] = B(c=2, d=1)
|
|
37
37
|
|
|
38
|
-
b = AUref(a.
|
|
38
|
+
b = AUref(a._to_dict())
|
|
39
39
|
|
|
40
40
|
assert b[1].a[0] == 3
|
|
41
41
|
assert b[5].d == 1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.5.5"
|
|
@@ -690,10 +690,13 @@ class Array(metaclass=MetaArray):
|
|
|
690
690
|
return [cls._itemtype]
|
|
691
691
|
|
|
692
692
|
def _to_json(self):
|
|
693
|
+
raise NameError("`_to_json` has been removed. Use `_to_dict` instead.")
|
|
694
|
+
|
|
695
|
+
def _to_dict(self):
|
|
693
696
|
out = []
|
|
694
697
|
for v in self: # TODO does not support multidimensional arrays
|
|
695
|
-
if hasattr(v, "
|
|
696
|
-
vdata = v.
|
|
698
|
+
if hasattr(v, "_to_dict"):
|
|
699
|
+
vdata = v._to_dict()
|
|
697
700
|
else:
|
|
698
701
|
vdata = v
|
|
699
702
|
if self._has_refs and v is not None:
|
|
@@ -457,7 +457,11 @@ class ContextCupy(XContext):
|
|
|
457
457
|
|
|
458
458
|
extra_include_paths = self.get_installed_c_source_paths()
|
|
459
459
|
include_flags = [f"-I{path}" for path in extra_include_paths]
|
|
460
|
-
extra_compile_args = (
|
|
460
|
+
extra_compile_args = (
|
|
461
|
+
*extra_compile_args,
|
|
462
|
+
*include_flags,
|
|
463
|
+
"-DXO_CONTEXT_CUDA",
|
|
464
|
+
)
|
|
461
465
|
|
|
462
466
|
module = cupy.RawModule(
|
|
463
467
|
code=specialized_source, options=extra_compile_args
|
|
@@ -340,10 +340,18 @@ class HybridClass(metaclass=MetaHybridClass):
|
|
|
340
340
|
if _context is None and _buffer is None:
|
|
341
341
|
_context = self._xobject._buffer.context
|
|
342
342
|
# This makes a copy of the xobject
|
|
343
|
-
|
|
343
|
+
new_xobject = self._XoStruct(
|
|
344
344
|
self._xobject, _context=_context, _buffer=_buffer, _offset=_offset
|
|
345
345
|
)
|
|
346
|
-
|
|
346
|
+
new = self.__class__.__new__(self.__class__)
|
|
347
|
+
new.__dict__.update(self.__dict__)
|
|
348
|
+
for kk, vv in new.__dict__.items():
|
|
349
|
+
if kk == "_xobject":
|
|
350
|
+
continue
|
|
351
|
+
if hasattr(vv, "copy"):
|
|
352
|
+
new.__dict__[kk] = vv.copy()
|
|
353
|
+
new._xobject = new_xobject
|
|
354
|
+
return new
|
|
347
355
|
|
|
348
356
|
@property
|
|
349
357
|
def _buffer(self):
|
|
@@ -294,10 +294,13 @@ class UnionRef(metaclass=MetaUnionRef):
|
|
|
294
294
|
return cls._reftypes
|
|
295
295
|
|
|
296
296
|
def _to_json(self):
|
|
297
|
+
raise NameError("`_to_json` has been removed. Use `_to_dict` instead.")
|
|
298
|
+
|
|
299
|
+
def _to_dict(self):
|
|
297
300
|
v = self.get()
|
|
298
301
|
classname = v.__class__.__name__
|
|
299
|
-
if hasattr(v, "
|
|
300
|
-
v = v.
|
|
302
|
+
if hasattr(v, "_to_dict"):
|
|
303
|
+
v = v._to_dict()
|
|
301
304
|
return (classname, v)
|
|
302
305
|
|
|
303
306
|
|
|
@@ -366,15 +366,15 @@ class Struct(metaclass=MetaStruct):
|
|
|
366
366
|
foffset = offset + cls._fields[index].offset
|
|
367
367
|
Int64._to_buffer(buffer, foffset, data_offset)
|
|
368
368
|
|
|
369
|
-
def _to_dict(self):
|
|
370
|
-
return {field.name: field.__get__(self) for field in self._fields}
|
|
371
|
-
|
|
372
369
|
def _to_json(self):
|
|
370
|
+
raise NameError("`_to_json` has been removed. Use `_to_dict` instead.")
|
|
371
|
+
|
|
372
|
+
def _to_dict(self):
|
|
373
373
|
out = {}
|
|
374
374
|
for field in self._fields:
|
|
375
375
|
v = field.__get__(self)
|
|
376
|
-
if hasattr(v, "
|
|
377
|
-
v = v.
|
|
376
|
+
if hasattr(v, "_to_dict"):
|
|
377
|
+
v = v._to_dict()
|
|
378
378
|
out[field.name] = v
|
|
379
379
|
return out
|
|
380
380
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.5.4"
|
|
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
|