c2ImageD11 0.4.0__py2.py3-none-win_amd64.whl

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.
c2ImageD11/__init__.py ADDED
@@ -0,0 +1,175 @@
1
+ """
2
+ c2ImageD11 - compiled C extensions for ImageD11, built with c2py23.
3
+
4
+ Provides:
5
+ - All C functions re-exported from the arch-named .so
6
+ - Blob property constants (s_1, s_I, NPROPERTY, etc.)
7
+ - Allocation wrappers for f2py-compatible tuple returns
8
+ - __version__
9
+ """
10
+
11
+ from __future__ import absolute_import, division, print_function, unicode_literals
12
+
13
+
14
+ # start delvewheel patch
15
+ def _delvewheel_patch_1_13_0():
16
+ import ctypes
17
+ import os
18
+ import platform
19
+ import sys
20
+ libs_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'c2imaged11.libs'))
21
+ is_conda_cpython = platform.python_implementation() == 'CPython' and (hasattr(ctypes.pythonapi, 'Anaconda_GetVersion') or 'packaged by conda-forge' in sys.version)
22
+ if sys.version_info[:2] >= (3, 8) and not is_conda_cpython or sys.version_info[:2] >= (3, 10):
23
+ if os.path.isdir(libs_dir):
24
+ os.add_dll_directory(libs_dir)
25
+ else:
26
+ load_order_filepath = os.path.join(libs_dir, '.load-order-c2imaged11-0.4.0')
27
+ if os.path.isfile(load_order_filepath):
28
+ import ctypes.wintypes
29
+ with open(os.path.join(libs_dir, '.load-order-c2imaged11-0.4.0')) as file:
30
+ load_order = file.read().split()
31
+ kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
32
+ kernel32.LoadLibraryExW.restype = ctypes.wintypes.HMODULE
33
+ kernel32.LoadLibraryExW.argtypes = ctypes.wintypes.LPCWSTR, ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD
34
+ for lib in load_order:
35
+ lib_path = os.path.join(os.path.join(libs_dir, lib))
36
+ if os.path.isfile(lib_path) and not kernel32.LoadLibraryExW(lib_path, None, 8):
37
+ raise OSError('Error loading {}; {}'.format(lib, ctypes.FormatError(ctypes.get_last_error())))
38
+
39
+
40
+ _delvewheel_patch_1_13_0()
41
+ del _delvewheel_patch_1_13_0
42
+ # end delvewheel patch
43
+
44
+ __version__ = "0.4.0"
45
+
46
+ import os
47
+ import platform
48
+ import sys
49
+ import warnings
50
+
51
+ # ---------------------------------------------------------------------------
52
+ # Arch-aware .so loader
53
+ #
54
+ # The .so files in this directory follow the naming convention:
55
+ # _cImageD11_{arch}.so (Linux)
56
+ # _cImageD11_{arch}.pyd (Windows)
57
+ #
58
+ # Where {arch} matches platform.machine() output:
59
+ # x86_64, aarch64, ppc64le, AMD64 (Windows), arm64 (Windows)
60
+ #
61
+ # The same binary works across Python 2.7-3.14 because c2py23 emits both
62
+ # init_cImageD11 (Py2) and PyInit__cImageD11 (Py3) entry points.
63
+ # ---------------------------------------------------------------------------
64
+
65
+ _here = os.path.dirname(__file__)
66
+ _arch = platform.machine()
67
+ _ext = ".pyd" if sys.platform == "win32" else ".so"
68
+ _lib_name = "_cImageD11_{}{}".format(_arch, _ext)
69
+ _lib_path = os.path.join(_here, _lib_name)
70
+
71
+ # Fallback: plain name _cImageD11.so (no arch suffix)
72
+ if not os.path.exists(_lib_path):
73
+ _lib_path = os.path.join(_here, "_cImageD11" + _ext)
74
+
75
+ if not os.path.exists(_lib_path):
76
+ # .so not built yet (e.g. during setuptools metadata reading).
77
+ # __version__ is still available; C functions will not be.
78
+ _mod = None
79
+ else:
80
+ if sys.version_info[0] >= 3:
81
+ import importlib.util
82
+ _spec = importlib.util.spec_from_file_location(
83
+ "c2ImageD11._cImageD11", _lib_path)
84
+ _mod = importlib.util.module_from_spec(_spec)
85
+ sys.modules["c2ImageD11._cImageD11"] = _mod
86
+ _spec.loader.exec_module(_mod)
87
+ else:
88
+ import imp
89
+ _mod = imp.load_dynamic("c2ImageD11._cImageD11", _lib_path)
90
+
91
+ if _mod is not None:
92
+ # Make _cImageD11 importable as c2ImageD11._cImageD11
93
+ sys.modules[__name__]._cImageD11 = _mod
94
+
95
+ # Save raw C functions before any overwrites
96
+ _blobproperties_c = _mod.blobproperties
97
+ _sparse_blob2Dproperties_c = _mod.sparse_blob2Dproperties
98
+
99
+ # Re-export all non-private names from the loaded module
100
+ for _k in dir(_mod):
101
+ if not _k.startswith("_"):
102
+ globals()[_k] = getattr(_mod, _k)
103
+
104
+ # ---- score_and_refine: single entry point, AoS/SoA dispatch in c2py23 wrapper ----
105
+
106
+ import numpy as np
107
+
108
+ def blobproperties(data, labels, npk, omega=0.0, verbose=0):
109
+ """Allocate results and call C blobproperties, matching f2py convention."""
110
+ results = np.zeros((npk, 36), dtype=np.float64)
111
+ _blobproperties_c(data, labels, npk, results, omega, verbose)
112
+ return results
113
+
114
+ def sparse_blob2Dproperties(v, i, j, labels, npk):
115
+ """Allocate results and call C sparse_blob2Dproperties, matching f2py convention."""
116
+ results = np.zeros((npk, 11), dtype=np.float64)
117
+ _sparse_blob2Dproperties_c(v, i, j, labels, npk, results)
118
+ return results
119
+
120
+ # Replace raw C functions on submodule with wrappers
121
+ _mod.blobproperties = blobproperties
122
+ _mod.sparse_blob2Dproperties = sparse_blob2Dproperties
123
+
124
+ # -----------------------------------------------------------------------
125
+ # OpenMP minimum ng threshold. Must match the `ng > 50000` guard in
126
+ # lib/functions/score_and_refine/score_and_refine.hpp. Measured cutoff:
127
+ # ng <= 10000 | single-thread; ng > 10000 | ~2x speedup on x86_64.
128
+ # -----------------------------------------------------------------------
129
+ OMP_MIN_NG = 10000
130
+
131
+
132
+ # -----------------------------------------------------------------------
133
+ # OpenMP safety
134
+ # -----------------------------------------------------------------------
135
+
136
+ def _check_multiprocessing(patch=False):
137
+ """Warn about fork+threads interaction with OpenMP.
138
+
139
+ You cannot safely use os.fork together with threads.
140
+ But the cImageD11 codes uses threads via openmp, and you are importing them.
141
+ So please use forkserver or spawn for multiprocessing.
142
+ """
143
+ if not hasattr(os, "fork"):
144
+ return
145
+ import multiprocessing
146
+ if not hasattr(multiprocessing, "get_start_method"):
147
+ warnings.warn(
148
+ "python2.7 with c2ImageD11: for multiprocessing use spawn\n"
149
+ )
150
+ return
151
+ method = multiprocessing.get_start_method(allow_none=True)
152
+ if method == "fork":
153
+ warnings.warn(_check_multiprocessing.__doc__)
154
+ parent = None
155
+ if hasattr(multiprocessing, "parent_process"):
156
+ parent = multiprocessing.parent_process()
157
+ if parent is not None:
158
+ if "OMP_NUM_THREADS" not in os.environ:
159
+ cimaged11_omp_set_num_threads(1)
160
+
161
+
162
+ check_multiprocessing = _check_multiprocessing # public alias (f2py compat)
163
+
164
+ if cimaged11_omp_get_max_threads() == 0:
165
+ OPENMP = False
166
+ else:
167
+ OPENMP = True
168
+ _check_multiprocessing()
169
+
170
+
171
+ # -----------------------------------------------------------------------
172
+ # Sanity check
173
+ # -----------------------------------------------------------------------
174
+
175
+ assert verify_rounding(20) == 0, "Problem with cImageD11 fast rounding code"
Binary file
@@ -0,0 +1,2 @@
1
+ Version: 1.13.0
2
+ Arguments: ['C:\\hostedtoolcache\\windows\\Python\\3.12.10\\x64\\Scripts\\delvewheel', 'repair', '-w', 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\wheelhouse', 'dist\\c2imaged11-0.4.0-py2.py3-none-win_amd64.whl']
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.4
2
+ Name: c2ImageD11
3
+ Version: 0.4.0
4
+ Summary: C extensions for ImageD11 (c2py23 binding)
5
+ Author-email: Jon Wright <wright@esrf.fr>
6
+ Project-URL: Homepage, https://github.com/jonwright/c2ImageD11
7
+ Project-URL: Source, https://github.com/jonwright/c2ImageD11
8
+ Project-URL: Bug tracker, https://github.com/jonwright/c2ImageD11/issues
9
+ Keywords: imageD11,diffraction,xray,crystallography
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
13
+ Classifier: Programming Language :: Python :: 2.7
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: C
16
+ Classifier: Topic :: Scientific/Engineering :: Physics
17
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
18
+ Requires-Python: >=2.7
19
+ Description-Content-Type: text/markdown
20
+ Requires-Dist: numpy
21
+
22
+ # c2ImageD11
23
+
24
+ > All code in this repository was generated by [DeepSeek V4](https://deepseek.com)
25
+ > and other large language models, in collaboration with jonwright.
26
+
27
+ Standalone C extensions for ImageD11, ported from f2py to **c2py23**.
28
+ C functions are exposed by a generated CPython extension wrapper.
29
+ Two functions (`blobproperties`, `sparse_blob2Dproperties`) have thin
30
+ Python allocation wrappers in `__init__.py` to match f2py's convention
31
+ of auto-allocating output arrays.
32
+
33
+ ## Build
34
+
35
+ A normal build needs only meson + ninja + a C compiler. The generated
36
+ files in `lib/interface/` are checked into git, so c2py23 is **not**
37
+ required.
38
+
39
+ ```bash
40
+ mkdir -p build/libc2ImageD11
41
+ cd build/libc2ImageD11
42
+ meson setup ../../lib
43
+ ninja
44
+ cp _cImageD11.so ../../c2ImageD11/
45
+ ```
46
+
47
+ ## Regenerate `lib/interface/`
48
+
49
+ Run this when C2PY_BLOCKs change or c2py23 is updated (requires c2py23):
50
+
51
+ ```bash
52
+ python3 tools/harvester.py --output-dir lib/interface
53
+ ```
54
+
55
+ ## Test
56
+
57
+ ```bash
58
+ python3 -m pytest tests/
59
+ ```
60
+
61
+ ## Distributing
62
+
63
+ Copy `_cImageD11.so` into `c2ImageD11/` and the package is ready --
64
+ same pattern as a ctypes library.
@@ -0,0 +1,10 @@
1
+ c2ImageD11/_cImageD11_AMD64.pyd,sha256=9D5HTghDNijqaBAuWoBQ68tgUEQ4BoosIQmfRLEhIqs,711680
2
+ c2ImageD11/__init__.py,sha256=g3wSqmcSbzL8D32ZBgZUKeWsAtASbv3qrEv0kHukhSw,7083
3
+ c2imaged11-0.4.0.dist-info/DELVEWHEEL,sha256=iRQPjsqArjusY3u1iCH-sW4on-c4DmXCH8z0I2DvsS8,229
4
+ c2imaged11-0.4.0.dist-info/METADATA,sha256=xXr9iIZUgmkS32vPVrt0vGbUn7azW_EYvtQRYZ7Pogg,2080
5
+ c2imaged11-0.4.0.dist-info/RECORD,,
6
+ c2imaged11-0.4.0.dist-info/top_level.txt,sha256=Zisg4zXBajKHAbtdPf0ik4OXFXJvGCq7GfSjomZw478,11
7
+ c2imaged11-0.4.0.dist-info/WHEEL,sha256=BgvlLX5QPcIUApMMGJ8sIcQKn1djXdBwESh04j0IBQU,122
8
+ c2imaged11.libs/.load-order-c2imaged11-0.4.0,sha256=itUAVgurK8BVFTvlvrNUGCnz1DP3lfluDCnSXl1U_mY,96
9
+ c2imaged11.libs/vcomp140-f96f3a14d88d8846f31f3ab38a490304.dll,sha256=-W86FNiNiEbzHzqzikkDBM59bk9w-uQwTGPlnHrqLTA,213072
10
+ c2imaged11.libs/vcruntime140-052ad6a20d375957e82aa6a3c441ea54.dll,sha256=BSrWog03WVfoKqajxEHqVI2JvgmBUWyn6zBuBj1QJ_Q,120400
@@ -0,0 +1,6 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (83.0.0)
3
+ Root-Is-Purelib: false
4
+ Tag: py2-none-win_amd64
5
+ Tag: py3-none-win_amd64
6
+
@@ -0,0 +1 @@
1
+ c2ImageD11
@@ -0,0 +1,2 @@
1
+ vcomp140-f96f3a14d88d8846f31f3ab38a490304.dll
2
+ vcruntime140-052ad6a20d375957e82aa6a3c441ea54.dll