xobjects 0.7.0__tar.gz → 0.7.2__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.
Files changed (100) hide show
  1. {xobjects-0.7.0/xobjects.egg-info → xobjects-0.7.2}/PKG-INFO +2 -1
  2. {xobjects-0.7.0 → xobjects-0.7.2}/pyproject.toml +1 -0
  3. {xobjects-0.7.0 → xobjects-0.7.2}/setup.py +1 -1
  4. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_hybrid_class.py +22 -0
  5. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_kernel.py +10 -1
  6. xobjects-0.7.2/xobjects/_version.py +1 -0
  7. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/context_cpu.py +2 -0
  8. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/hybrid_class.py +7 -1
  9. {xobjects-0.7.0 → xobjects-0.7.2/xobjects.egg-info}/PKG-INFO +2 -1
  10. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects.egg-info/SOURCES.txt +0 -39
  11. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects.egg-info/requires.txt +1 -0
  12. xobjects-0.7.0/.github/workflows/black.yml +0 -10
  13. xobjects-0.7.0/.gitignore +0 -13
  14. xobjects-0.7.0/.pre-commit-config.yaml +0 -12
  15. xobjects-0.7.0/.readthedocs.yaml +0 -20
  16. xobjects-0.7.0/contributors_and_credits.txt +0 -7
  17. xobjects-0.7.0/docs/Makefile +0 -20
  18. xobjects-0.7.0/docs/architecture/contexts.rst +0 -164
  19. xobjects-0.7.0/docs/architecture/types.rst +0 -179
  20. xobjects-0.7.0/docs/architecture.rst +0 -16
  21. xobjects-0.7.0/docs/conf.py +0 -278
  22. xobjects-0.7.0/docs/index.rst +0 -79
  23. xobjects-0.7.0/docs/make.bat +0 -35
  24. xobjects-0.7.0/docs/quickstart.rst +0 -2
  25. xobjects-0.7.0/docs/reference.rst +0 -8
  26. xobjects-0.7.0/examples/api_def.py +0 -28
  27. xobjects-0.7.0/examples/api_init.py +0 -101
  28. xobjects-0.7.0/examples/capi_example.c +0 -100
  29. xobjects-0.7.0/examples/check_assembly.c +0 -101
  30. xobjects-0.7.0/examples/ex_array_init_perf.py +0 -42
  31. xobjects-0.7.0/examples/ex_cpugpu.py +0 -46
  32. xobjects-0.7.0/examples/ex_nested_ref.py +0 -49
  33. xobjects-0.7.0/examples/ex_ref_cpu.py +0 -52
  34. xobjects-0.7.0/examples/ex_struct_cpu.py +0 -39
  35. xobjects-0.7.0/examples/ex_unionref_cpu.py +0 -49
  36. xobjects-0.7.0/examples/ex_unionref_method.py +0 -120
  37. xobjects-0.7.0/examples/init_soa.py +0 -67
  38. xobjects-0.7.0/examples/issue_with_two_pyopencl_contexts.py +0 -18
  39. xobjects-0.7.0/examples/kernel_basics/kernel_cffi.py +0 -54
  40. xobjects-0.7.0/examples/kernel_basics/kernel_cupy.py +0 -42
  41. xobjects-0.7.0/examples/kernel_basics/kernel_pyopencl.py +0 -48
  42. xobjects-0.7.0/examples/opencl_offsets.py +0 -38
  43. xobjects-0.7.0/examples/simple_kernel.py +0 -59
  44. xobjects-0.7.0/examples/sixtracklib.py +0 -80
  45. xobjects-0.7.0/mktest +0 -1
  46. xobjects-0.7.0/release.sh +0 -20
  47. xobjects-0.7.0/requirements.txt +0 -3
  48. xobjects-0.7.0/tests/__init__.py +0 -4
  49. xobjects-0.7.0/tests/notest_capi.py +0 -208
  50. xobjects-0.7.0/update_cprght_statement.py +0 -49
  51. xobjects-0.7.0/xobjects/_version.py +0 -1
  52. {xobjects-0.7.0 → xobjects-0.7.2}/Architecture.md +0 -0
  53. {xobjects-0.7.0 → xobjects-0.7.2}/LICENSE +0 -0
  54. {xobjects-0.7.0 → xobjects-0.7.2}/MANIFEST.in +0 -0
  55. {xobjects-0.7.0 → xobjects-0.7.2}/README.md +0 -0
  56. {xobjects-0.7.0 → xobjects-0.7.2}/setup.cfg +0 -0
  57. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_align.py +0 -0
  58. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_array.py +0 -0
  59. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_buffer.py +0 -0
  60. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_capi.py +0 -0
  61. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_chunk.py +0 -0
  62. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_common.py +0 -0
  63. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_context_opencl.py +0 -0
  64. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_general.py +0 -0
  65. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_linked_array.py +0 -0
  66. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_nplike_arrays.py +0 -0
  67. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_raw_union.py +0 -0
  68. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_ref.py +0 -0
  69. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_scalars.py +0 -0
  70. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_shared_memory.py +0 -0
  71. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_strides.py +0 -0
  72. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_string.py +0 -0
  73. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_struct.py +0 -0
  74. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_to_dict.py +0 -0
  75. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_typeutils.py +0 -0
  76. {xobjects-0.7.0 → xobjects-0.7.2}/tests/test_unionref.py +0 -0
  77. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/__init__.py +0 -0
  78. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/_patch_pyopencl_array.py +0 -0
  79. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/array.py +0 -0
  80. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/capi.py +0 -0
  81. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/context.py +0 -0
  82. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/context_cupy.py +0 -0
  83. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/context_pyopencl.py +0 -0
  84. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/general.py +0 -0
  85. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/headers/atomicadd.h +0 -0
  86. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/headers/common.h +0 -0
  87. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/linkedarray.py +0 -0
  88. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/raw_union.py +0 -0
  89. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/ref.py +0 -0
  90. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/scalar.py +0 -0
  91. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/settings.py +0 -0
  92. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/specialize_source.py +0 -0
  93. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/string.py +0 -0
  94. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/struct.py +0 -0
  95. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/test_helpers.py +0 -0
  96. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/typeutils.py +0 -0
  97. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects/union.py +0 -0
  98. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects.egg-info/dependency_links.txt +0 -0
  99. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects.egg-info/entry_points.txt +0 -0
  100. {xobjects-0.7.0 → xobjects-0.7.2}/xobjects.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xobjects
3
- Version: 0.7.0
3
+ Version: 0.7.2
4
4
  Summary: In-memory serialization and code generator for CPU and GPU
5
5
  Home-page: https://xsuite.readthedocs.io/
6
6
  Download-URL: https://pypi.python.org/pypi/xobjects
@@ -17,6 +17,7 @@ Description-Content-Type: text/markdown
17
17
  License-File: LICENSE
18
18
  Requires-Dist: numpy
19
19
  Requires-Dist: cffi
20
+ Requires-Dist: setuptools
20
21
  Requires-Dist: scipy
21
22
  Provides-Extra: tests
22
23
  Requires-Dist: pytest; extra == "tests"
@@ -17,6 +17,7 @@ requires-python = ">=3.9"
17
17
  dependencies = [
18
18
  "numpy",
19
19
  "cffi",
20
+ "setuptools",
20
21
  "scipy"
21
22
  ]
22
23
  [project.urls]
@@ -23,7 +23,7 @@ setup(
23
23
  url="https://xsuite.readthedocs.io/",
24
24
  python_requires=">=3.7",
25
25
  setup_requires=[],
26
- install_requires=["numpy", "cffi", "scipy"],
26
+ install_requires=["numpy", "cffi", "setuptools", "scipy"],
27
27
  packages=["xobjects"],
28
28
  license="Apache 2.0",
29
29
  download_url="https://pypi.python.org/pypi/xobjects",
@@ -332,6 +332,28 @@ def test_to_json_defaults():
332
332
  assert b_dict == {}
333
333
 
334
334
 
335
+ def test_to_dict_scalar_raw_union_defaults():
336
+ class ScalarUnion(xo.RawUnion):
337
+ scalar = xo.Float64
338
+ bits = xo.UInt64
339
+
340
+ @classmethod
341
+ def _from_buffer(cls, buffer, offset=0, container=None):
342
+ return xo.Float64._from_buffer(buffer, offset)
343
+
344
+ class A(xo.HybridClass):
345
+ _xofields = {
346
+ "a": ScalarUnion,
347
+ "b": xo.Field(ScalarUnion, default=2.5),
348
+ "c": xo.Field(ScalarUnion, default_factory=lambda: 3.5),
349
+ }
350
+
351
+ assert A().to_dict() == {"__class__": "A"}
352
+ values = {"__class__": "A", "a": 1.5, "b": 0.0, "c": 0.0}
353
+ for copy_to_cpu in (True, False):
354
+ assert A.from_dict(values).to_dict(copy_to_cpu=copy_to_cpu) == values
355
+
356
+
335
357
  def test_to_dict_python_vars():
336
358
  class TD(xo.HybridClass):
337
359
  _xofields = {
@@ -4,6 +4,7 @@
4
4
  # ########################################### #
5
5
 
6
6
  import cffi
7
+ import pickle
7
8
  import pytest
8
9
  import sysconfig
9
10
  from pathlib import Path
@@ -14,7 +15,8 @@ import xobjects as xo
14
15
  from xobjects.test_helpers import for_all_test_contexts, requires_context
15
16
 
16
17
 
17
- def test_kernel_cpu():
18
+ @pytest.mark.parametrize('pickle_context', [False, True])
19
+ def test_kernel_cpu(pickle_context):
18
20
  ctx = xo.ContextCpu()
19
21
  src_code = r"""
20
22
  double my_mul(const int n, const double* x1,
@@ -45,6 +47,13 @@ double my_mul(const int n, const double* x1,
45
47
 
46
48
  assert y == 285.0
47
49
 
50
+ if pickle_context:
51
+ restored = pickle.loads(pickle.dumps(ctx))
52
+ assert not restored.kernels
53
+ assert ctx.kernels.my_mul(n=len(a1), x1=a1, x2=a2) == 285.0
54
+ restored.add_kernels(sources=[src_code], kernels=kernel_descriptions)
55
+ assert restored.kernels.my_mul(n=len(a1), x1=a1, x2=a2) == 285.0
56
+
48
57
 
49
58
  @for_all_test_contexts
50
59
  def test_kernel_pointer_none_maps_to_null(test_context):
@@ -0,0 +1 @@
1
+ __version__ = "0.7.2"
@@ -96,6 +96,7 @@ def kernel_compilation_help_message():
96
96
 
97
97
  from .context import (
98
98
  Kernel,
99
+ KernelDict,
99
100
  ModuleNotAvailable,
100
101
  SourceType,
101
102
  XBuffer,
@@ -821,6 +822,7 @@ class ContextCpu(XContext):
821
822
 
822
823
  def __setstate__(self, state):
823
824
  self.__dict__.update(state)
825
+ self._kernels = KernelDict(self._kernels)
824
826
  self._buffers = weakref.WeakSet()
825
827
 
826
828
 
@@ -10,6 +10,7 @@ import numpy as np
10
10
  from .struct import Struct
11
11
  from .typeutils import context_default
12
12
  from .ref import Ref
13
+ from .raw_union import RawUnion
13
14
 
14
15
 
15
16
  class _FieldOfDressed:
@@ -297,7 +298,12 @@ class HybridClass(metaclass=MetaHybridClass):
297
298
  defaults[field.name] = dft
298
299
  continue
299
300
  try:
300
- defaults[field.name] = field.get_default()
301
+ default = field.get_default()
302
+ if isinstance(default, RawUnion):
303
+ # A raw union can expose a scalar when read as a field.
304
+ default = type(default)._from_buffer(
305
+ default._buffer, default._offset)
306
+ defaults[field.name] = default
301
307
  except (TypeError, ValueError):
302
308
  # The above can fail with different error types
303
309
  # if a field type is dynamic.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xobjects
3
- Version: 0.7.0
3
+ Version: 0.7.2
4
4
  Summary: In-memory serialization and code generator for CPU and GPU
5
5
  Home-page: https://xsuite.readthedocs.io/
6
6
  Download-URL: https://pypi.python.org/pypi/xobjects
@@ -17,6 +17,7 @@ Description-Content-Type: text/markdown
17
17
  License-File: LICENSE
18
18
  Requires-Dist: numpy
19
19
  Requires-Dist: cffi
20
+ Requires-Dist: setuptools
20
21
  Requires-Dist: scipy
21
22
  Provides-Extra: tests
22
23
  Requires-Dist: pytest; extra == "tests"
@@ -1,49 +1,10 @@
1
- .gitignore
2
- .pre-commit-config.yaml
3
- .readthedocs.yaml
4
1
  Architecture.md
5
2
  LICENSE
6
3
  MANIFEST.in
7
4
  README.md
8
- contributors_and_credits.txt
9
- mktest
10
5
  pyproject.toml
11
- release.sh
12
- requirements.txt
13
6
  setup.cfg
14
7
  setup.py
15
- update_cprght_statement.py
16
- .github/workflows/black.yml
17
- docs/Makefile
18
- docs/architecture.rst
19
- docs/conf.py
20
- docs/index.rst
21
- docs/make.bat
22
- docs/quickstart.rst
23
- docs/reference.rst
24
- docs/architecture/contexts.rst
25
- docs/architecture/types.rst
26
- examples/api_def.py
27
- examples/api_init.py
28
- examples/capi_example.c
29
- examples/check_assembly.c
30
- examples/ex_array_init_perf.py
31
- examples/ex_cpugpu.py
32
- examples/ex_nested_ref.py
33
- examples/ex_ref_cpu.py
34
- examples/ex_struct_cpu.py
35
- examples/ex_unionref_cpu.py
36
- examples/ex_unionref_method.py
37
- examples/init_soa.py
38
- examples/issue_with_two_pyopencl_contexts.py
39
- examples/opencl_offsets.py
40
- examples/simple_kernel.py
41
- examples/sixtracklib.py
42
- examples/kernel_basics/kernel_cffi.py
43
- examples/kernel_basics/kernel_cupy.py
44
- examples/kernel_basics/kernel_pyopencl.py
45
- tests/__init__.py
46
- tests/notest_capi.py
47
8
  tests/test_align.py
48
9
  tests/test_array.py
49
10
  tests/test_buffer.py
@@ -1,5 +1,6 @@
1
1
  numpy
2
2
  cffi
3
+ setuptools
3
4
  scipy
4
5
 
5
6
  [tests]
@@ -1,10 +0,0 @@
1
- name: Lint
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- lint:
7
- runs-on: ubuntu-latest
8
- steps:
9
- - uses: actions/checkout@v2
10
- - uses: pre-commit/action@v3.0.1
xobjects-0.7.0/.gitignore DELETED
@@ -1,13 +0,0 @@
1
- __pycache__/
2
- *.pyc
3
- *.pyo
4
- *.swp
5
- *.egg-info/
6
- docs/_build
7
- cov_html
8
- .vscode
9
- .pytest_cache
10
- .coverage
11
- .idea
12
- *.c
13
- **/.DS_Store
@@ -1,12 +0,0 @@
1
- repos:
2
- - repo: https://github.com/pre-commit/pre-commit-hooks
3
- rev: v4.5.0
4
- hooks:
5
- - id: check-yaml
6
- - id: end-of-file-fixer
7
- - id: trailing-whitespace
8
- - repo: https://github.com/psf/black-pre-commit-mirror
9
- rev: 26.3.1
10
- hooks:
11
- - id: black
12
- language_version: python3
@@ -1,20 +0,0 @@
1
- # .readthedocs.yaml
2
- # Read the Docs configuration file
3
- # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4
-
5
- # Required
6
- version: 2
7
-
8
- # Build documentation in the docs/ directory with Sphinx
9
- sphinx:
10
- configuration: docs/conf.py
11
-
12
- # Optionally build your docs in additional formats such as PDF
13
- formats:
14
- - pdf
15
-
16
- # Optionally set the version of Python and requirements required to build your docs
17
- python:
18
- version: 3.7
19
- # install:
20
- # - requirements: docs/requirements.txt
@@ -1,7 +0,0 @@
1
- The following people contributed to the development of this package:
2
-
3
- CERN contributors:
4
- - R. De Maria
5
- - G. Iadarola
6
- - P. Kiksiny
7
- - S. Lopaciuk
@@ -1,20 +0,0 @@
1
- # Minimal makefile for Sphinx documentation
2
- #
3
-
4
- # You can set these variables from the command line, and also
5
- # from the environment for the first two.
6
- SPHINXOPTS ?=
7
- SPHINXBUILD ?= sphinx-build
8
- SOURCEDIR = .
9
- BUILDDIR = _build
10
-
11
- # Put it first so that "make" without argument is like "make help".
12
- help:
13
- @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14
-
15
- .PHONY: help Makefile
16
-
17
- # Catch-all target: route all unknown targets to Sphinx using the new
18
- # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19
- %: Makefile
20
- @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@@ -1,164 +0,0 @@
1
- Contexts
2
- ========
3
-
4
- Devices
5
- -------
6
-
7
-
8
- Buffers
9
- -------
10
-
11
- Buffers are able to store data in the host or device from several object types and return data in device or host.
12
-
13
-
14
- Instance methods:
15
-
16
- * write(self, source, offset, nbytes): write nbytes from source that can be a np-like array, bytearray, bytes or another buffer
17
- * to_nplike(self,dtype,shape,offset): return a view of the data in a np-like arrays
18
- * to_bytearray(self,offset,count): return
19
-
20
- .. code::
21
-
22
- def update_from_xbuffer(self,offset, source, source_offset, nbytes):
23
- "update from any xbuffer, don't pass through gpu if possible"
24
-
25
- def update_from_buffer(self, offset, buffer):
26
- """source is python buffer such as bytearray, numpy array .data"""
27
-
28
- def copy_native(self,offset,nbytes):
29
- """return native data with content at from offset and nbytes
30
- return native_data
31
-
32
- def update_from_native(self, offset, source, source_offset, nbytes):
33
- """update native source into buffer usef in update_from_xbuffer"""
34
-
35
- def to_nplike(self,offset,shape,dtype)
36
- """view in nplike"""
37
-
38
- def to_bytearray(self,offset,nbytes)
39
- """copy in byte array: used in update_from_xbuffer"""
40
-
41
- def to_pointer_arg(self,offset,nbytes):
42
- return self.data[offset:offset+nbytes] #offset can lead to alignement error in opencl if not multiple of 4 bytes
43
-
44
-
45
-
46
- Arguments for kernels:
47
-
48
- - CPU:
49
- - numpy array -> ``ffi.cast("double *", ffi.from_buffer(arr))``
50
- - numpy scalar -> no change
51
- - s string -> ``ss.decode("utf8")``
52
-
53
- - PyOpenCL:
54
- - pyopencl.Buffer: [offset:offset+nbytes] or copy back and fort if needs to be aligned
55
- - pyopencl.array: arr.base_data[arr.offset:arr.offset+arr.nbytes] or copy back and fort
56
-
57
- - cuda:
58
- - pycuda.array: arr or arr.data
59
-
60
-
61
- nparray.data: python buffer pointing to start of the array arrays
62
- clarray.data: Optional Opencl buffer pointing to the start of the array
63
- clarray.base_data,clarray.base_data: Optional Opencl buffer and offset from where the pointer start
64
- cupyaray.
65
-
66
-
67
- clarray.base_data[]:
68
-
69
- Code generation
70
- ---------------
71
-
72
- Each context is able to compile source code and make available python callable functions.
73
-
74
- The callable functions can take as arguments Python numbers, strings,
75
- numpy-like arrays (depending on the context) and xobject allocated in the same
76
- contexts (if not copies will be done).
77
-
78
- Source code is optionally pre-processed to adapt it to the context.
79
-
80
- The callable functions are defined by:
81
- * the name of the function in the source code
82
- * the type of parameters
83
- * how to pass parallalization instruction (threads for openmp, grid for GPU)
84
-
85
- The callable functions are parametrized by name and argument types.
86
-
87
- Each xobject type can provide the API source code the ``_get_c_api()`` class method.
88
-
89
-
90
-
91
- C Api
92
- ^^^^^^^^^^^^^^^^^^^
93
-
94
- General:
95
-
96
- - ``<pointer type> <typename>_getp_<field_names>(<typename> obj, <indexes>)``
97
- - ``<scalar type> <typename>_get_<field_names>(<typename> obj, <indexes>)``
98
- - ``<typename>_set_<field_names>(<typename> obj, <indexes>, <scalar_type> value)``
99
- - ``<int64> <typename>_size_<field_names>(<typename> obj,<indexes>)``
100
-
101
- Array:
102
- - ``<int64> <typename>_len...(<typename> obj) : number of itemns``
103
- - ``<int64> <typename>_dim...(<typename> obj, int index): size of dimension``
104
- - ``<int64> <typename>_ndim...(<typename> obj): number of dimensions``
105
- - ``void <typename>_strides(int* result)``
106
-
107
- UnionRef:
108
- - ``<int64> <typename>_typeid...(<typename> obj) : get member
109
- - ``void* <typename>_member...(int* result)``
110
-
111
-
112
- Kernels and Functions
113
- ^^^^^^^^^^^^^^^^^^^^^
114
-
115
- Context can execute:
116
-
117
- - kernels: no return function and executed on a grid
118
- - functions: only for cpu kernels
119
-
120
-
121
- .. code:: python
122
- Kernel(
123
- cname,
124
- args=Arg(dtype, name: String, const: Boolean)
125
- grid=integer, string or list of string or functions of arguments
126
- ret=None)
127
-
128
-
129
- Arg:
130
-
131
- * atype: argument type:
132
- - provide validation function: cls._validate(value) or atype(value)
133
- - provide C-type name: atype._get_ctype() or dtype -> converted to c types,
134
- - generate raw argument from value .atype._get_carg() for the interface
135
- * name: optional, String needed for the grid
136
- * const: boolean (used in case of copy back)
137
-
138
- Code:
139
-
140
- * define sources, list of string or files
141
- * define kernels to expose, list of kernels
142
- * define preprocessors
143
- * attach callable kernels to context
144
- * to be used by CMethod or CProperty
145
-
146
- .. code::
147
- double x -> Arg(dtype=xo.Float64,name='x'): takes python scalar and np scalar
148
- double *restrict x -> Arg(dtype=xo.Float64,pointer=True,const=False,name='x'): takes np.array, xo.Float64 arrays
149
- const double *restrict x -> Arg(dtype=xo.Float64,pointer=True,const=True,name='x'): takes np.array, xo.Float64 arrays
150
- const Float64_N -> Arg(dtype=xo.Float64[:],const=True,name='x'): takes xo.Float64[:]
151
- const Float64_6by6 -> Arg(dtype=xo.Float64[6,6],const=True,name='x'): takes xo.Float64[6,6]
152
-
153
-
154
-
155
-
156
-
157
- * function: general function
158
- * method: implies first attribute is the instance of the class where it is defined
159
- * kernel: implies some iteration and no return type
160
-
161
- The function can be defined using:
162
- * header
163
- * source
164
- * body
@@ -1,179 +0,0 @@
1
- Types
2
- =====
3
-
4
- Introduction
5
- -------------
6
-
7
-
8
- Data layout and API can be defined by a composition of:
9
- * Scalars: Int8, Int16, Int32, Int64, Float32, Float64
10
- * Compounds: Struct, Array, Ref
11
-
12
- Types can have a fixed size (*static types*) or a variable size (*dynamic size*).
13
- The size of one instance cannot change after creation, but their content can.
14
-
15
-
16
- Data Layout
17
- -------------
18
-
19
- Data structure is organized in 64bit slots.
20
-
21
- Table indicates slot size and the description.
22
-
23
- Scalar
24
-
25
- ===== ===========
26
- Slots Description
27
- ===== ===========
28
- 8 Data
29
- ===== ===========
30
-
31
- String of n-bytes
32
-
33
- ============= ===============================
34
- Slots Description
35
- ============= ===============================
36
- 8 Size in bytes
37
- ceil((n+1)/8) Data in UTF-8 null terminated
38
- ============= ===============================
39
-
40
-
41
- Struct with static and *n* dynamical fields
42
-
43
- ======= ===============================
44
- Slots Description
45
- ======= ===============================
46
- 8 Optional: size if n>0
47
- ... Fixed-size field data
48
- 8*(n-1) Optional: Offsets of the 2nd to n-th last variable sized
49
- ... Optional: Variable sized data
50
- ======= ===============================
51
-
52
- Array with n dimensions, whose l are dynamic of *m* items.
53
-
54
- ======= ===============================
55
- Slots Description
56
- ======= ===============================
57
- 8 Optional: size
58
- 8*l Optional: size of l-variable dimensions
59
- 8*n Optional: strides for n-dimensions larger than 2
60
- m*s Data or offsets for m-items (s is the item-size or 8)
61
- ... Optional: Items data if the item type is dynamic
62
- ======= ===============================
63
-
64
- Union
65
-
66
- ======= ===============================
67
- Slots Description
68
- ======= ===============================
69
- 8 Type id
70
- ... Item data
71
- ======= ===============================
72
-
73
-
74
- Ref
75
-
76
- ======= ======================================
77
- Slots Description
78
- ======= ======================================
79
- 8 Offset from start of the buffer
80
- 8 Optional: typeid
81
- ======= ======================================
82
-
83
-
84
- Python type interface
85
- ----------------------
86
-
87
- The following describe the generic interface
88
-
89
- Class variables:
90
-
91
- ============== ===============================
92
- name Description
93
- ============== ===============================
94
- _size Size in bytes, None if not static size
95
- ============== ===============================
96
-
97
- Class methods:
98
-
99
- ============= ============== ============ ============================================
100
- name args return Description
101
- ============= ============== ============ ============================================
102
- _inspect_args *args, Info Return at least info.size and optionally
103
- *kwargs other metadata to build objects in memory
104
- from python objects. Args are propocessed
105
- by _pre_init
106
- _pre_init *args, args, Preprocess arguments and generate standard
107
- *kwargs kwargs values
108
- _to_buffer buffer None Serialize python in buffer from offset.
109
- offset Assume sufficient size is available
110
- value
111
- _from_buffer buffer instance Return Python instance from buffer and
112
- offset and offset
113
- _to_schema string TODO String representation of the type to
114
- deserialize objects
115
- ============= ============== ============ ============================================
116
-
117
-
118
- Instance variables:
119
-
120
- ============= ========================================
121
- name Description
122
- ============= ========================================
123
- _size Optional: size in bytes for dynamic-size
124
- ============= ========================================
125
-
126
-
127
- Class methods:
128
-
129
- ============= ============== ============ ============================================
130
- name args return Description
131
- ============= ============== ============ ============================================
132
- _post_init Run after object creation in __init__
133
- copy buffer or None TODO Return a copy into a buffer
134
- context Assume sufficient size is available
135
- _update value instance Update values of an exsiting objec
136
- _to_json json TODO json
137
- ============= ============== ============ ============================================
138
-
139
-
140
-
141
- **__init__**
142
-
143
- init is used to create a new xobject by allocating memory on the buffer.
144
- Ref and Scalars cannot be initialized alone (maybe temporarily)
145
-
146
- Init can take by default:
147
-
148
- * a json object:
149
- * dict for Struct
150
- * list for Array,
151
- * number of Scalars
152
- * String for String
153
- * (Typename, {}) for Ref of multiple types
154
- * dimensions (for string or arrays)
155
- * an xobject of the correct type
156
- * None for Ref
157
-
158
- The data is dispatched to _pre_init using the following convetion:
159
- * a dict is passed with **
160
- * a tuple is passed with *
161
- * any other object is passed verbatim
162
-
163
- Init uses the following steps:
164
-
165
- * pre_init to pre_process input
166
- * inspect_args to calculate sizes and collect metadata
167
- * get_a_buffer to allocate space
168
- * _to_buffer to write to memory
169
- * _from_buffer to build a python object
170
- * post_init
171
-
172
- **_from_buffer**
173
-
174
- When accessing data inside compound object the _from_buffer method is used.
175
- For scalar and string, python data is returned. For coumpund object,
176
- XObjects are returned
177
-
178
- **setters**
179
- Setters uses to_buffer or _update to update existing data.
@@ -1,16 +0,0 @@
1
- Architecture
2
- ==============
3
-
4
-
5
-
6
- The architucture is based on
7
-
8
- * Context managers implementing buffer, compilation, running
9
- * Type system to specify data layout and user API
10
-
11
-
12
- .. toctree::
13
- :maxdepth: 2
14
-
15
- architecture/contexts
16
- architecture/types