imops 0.8.2__cp39-cp39-win32.whl → 0.8.3__cp39-cp39-win32.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.

Potentially problematic release.


This version of imops might be problematic. Click here for more details.

Files changed (48) hide show
  1. _build_utils.py +87 -0
  2. imops/__init__.py +1 -0
  3. imops/__version__.py +1 -1
  4. imops/backend.py +14 -10
  5. imops/crop.py +18 -2
  6. imops/interp1d.py +7 -4
  7. imops/measure.py +7 -7
  8. imops/morphology.py +6 -5
  9. imops/numeric.py +376 -0
  10. imops/pad.py +41 -5
  11. imops/radon.py +7 -5
  12. imops/src/_backprojection.c +83 -83
  13. imops/src/_backprojection.cp39-win32.pyd +0 -0
  14. imops/src/_fast_backprojection.c +96 -96
  15. imops/src/_fast_backprojection.cp39-win32.pyd +0 -0
  16. imops/src/_fast_measure.c +96 -96
  17. imops/src/_fast_measure.cp39-win32.pyd +0 -0
  18. imops/src/_fast_morphology.c +96 -96
  19. imops/src/_fast_morphology.cp39-win32.pyd +0 -0
  20. imops/src/_fast_numeric.c +20545 -4996
  21. imops/src/_fast_numeric.cp39-win32.pyd +0 -0
  22. imops/src/_fast_numeric.pyx +208 -30
  23. imops/src/_fast_radon.c +96 -96
  24. imops/src/_fast_radon.cp39-win32.pyd +0 -0
  25. imops/src/_fast_zoom.c +96 -96
  26. imops/src/_fast_zoom.cp39-win32.pyd +0 -0
  27. imops/src/_measure.c +83 -83
  28. imops/src/_measure.cp39-win32.pyd +0 -0
  29. imops/src/_morphology.c +83 -83
  30. imops/src/_morphology.cp39-win32.pyd +0 -0
  31. imops/src/_numeric.c +20532 -4983
  32. imops/src/_numeric.cp39-win32.pyd +0 -0
  33. imops/src/_numeric.pyx +208 -30
  34. imops/src/_radon.c +83 -83
  35. imops/src/_radon.cp39-win32.pyd +0 -0
  36. imops/src/_zoom.c +83 -83
  37. imops/src/_zoom.cp39-win32.pyd +0 -0
  38. imops/utils.py +65 -12
  39. imops/zoom.py +2 -2
  40. {imops-0.8.2.dist-info → imops-0.8.3.dist-info}/METADATA +3 -2
  41. imops-0.8.3.dist-info/RECORD +60 -0
  42. {imops-0.8.2.dist-info → imops-0.8.3.dist-info}/WHEEL +1 -1
  43. imops-0.8.3.dist-info/top_level.txt +2 -0
  44. _pyproject_build.py +0 -61
  45. imops/_numeric.py +0 -124
  46. imops-0.8.2.dist-info/RECORD +0 -60
  47. imops-0.8.2.dist-info/top_level.txt +0 -2
  48. {imops-0.8.2.dist-info → imops-0.8.3.dist-info}/LICENSE +0 -0
Binary file
imops/utils.py CHANGED
@@ -1,39 +1,92 @@
1
1
  import os
2
+ from contextlib import contextmanager
2
3
  from itertools import permutations
3
4
  from typing import Callable, Optional, Sequence, Tuple, Union
4
5
  from warnings import warn
5
6
 
6
7
  import numpy as np
7
8
 
8
- from .backend import BACKEND2NUM_THREADS_VAR_NAME, SINGLE_THREADED_BACKENDS, Backend
9
+ from .backend import BACKEND_NAME2ENV_NUM_THREADS_VAR_NAME, SINGLE_THREADED_BACKENDS, Backend
9
10
 
10
11
 
11
12
  AxesLike = Union[int, Sequence[int]]
12
13
  AxesParams = Union[float, Sequence[float]]
13
14
 
14
15
  ZOOM_SRC_DIM = 4
16
+ # TODO: define imops-specific environment variable like `OMP_NUM_THREADS`?
17
+ IMOPS_NUM_THREADS = None
15
18
 
16
19
 
17
- def normalize_num_threads(num_threads: int, backend: Backend):
20
+ def set_num_threads(num_threads: int) -> int:
21
+ assert isinstance(num_threads, int) or num_threads is None, 'Number of threads must be int value or None.'
22
+ global IMOPS_NUM_THREADS
23
+ current = IMOPS_NUM_THREADS
24
+ IMOPS_NUM_THREADS = num_threads
25
+ return current
26
+
27
+
28
+ @contextmanager
29
+ def imops_num_threads(num_threads: int):
30
+ previous = set_num_threads(num_threads)
31
+ try:
32
+ yield
33
+ finally:
34
+ set_num_threads(previous)
35
+
36
+
37
+ def normalize_num_threads(num_threads: int, backend: Backend, warn_stacklevel: int = 1) -> int:
38
+ """Calculate the effective number of threads"""
39
+
40
+ global IMOPS_NUM_THREADS
18
41
  if backend.name in SINGLE_THREADED_BACKENDS:
19
42
  if num_threads != -1:
20
- warn(f'"{backend.name}" backend is single-threaded. Setting `num_threads` has no effect.')
43
+ warn(
44
+ f'"{backend.name}" backend is single-threaded. Setting `num_threads` has no effect.',
45
+ stacklevel=warn_stacklevel,
46
+ )
21
47
  return 1
48
+
49
+ env_num_threads_var_name = BACKEND_NAME2ENV_NUM_THREADS_VAR_NAME[backend.name]
50
+ # here we also handle the case `env_num_threads_var_name`=" " gracefully
51
+ env_num_threads = os.environ.get(env_num_threads_var_name, '').strip()
52
+ env_num_threads = int(env_num_threads) if env_num_threads else None
53
+ # TODO: maybe let user set the absolute maximum number of threads?
54
+ num_available_cpus = len(os.sched_getaffinity(0))
55
+
56
+ max_num_threads = min(filter(bool, [IMOPS_NUM_THREADS, env_num_threads, num_available_cpus]))
57
+
22
58
  if num_threads >= 0:
23
59
  # FIXME
24
60
  if backend.name == 'Numba':
25
61
  warn(
26
62
  'Setting `num_threads` has no effect with "Numba" backend. '
27
- 'Use `NUMBA_NUM_THREADS` environment variable.'
63
+ 'Use `NUMBA_NUM_THREADS` environment variable.',
64
+ stacklevel=warn_stacklevel,
28
65
  )
29
- return num_threads
30
-
31
- num_threads_var_name = BACKEND2NUM_THREADS_VAR_NAME[backend.name]
32
- # here we also handle the case `num_threads_var`=" " gracefully
33
- env_num_threads = os.environ.get(num_threads_var_name, '').strip()
34
- max_threads = int(env_num_threads) if env_num_threads else len(os.sched_getaffinity(0))
35
-
36
- return max_threads + num_threads + 1
66
+ return num_threads
67
+
68
+ if num_threads > max_num_threads:
69
+ if max_num_threads == IMOPS_NUM_THREADS:
70
+ warn(
71
+ f'Required number of threads ({num_threads}) is greater than `IMOPS_NUM_THREADS` '
72
+ f'({IMOPS_NUM_THREADS}). Using {IMOPS_NUM_THREADS} threads.',
73
+ stacklevel=warn_stacklevel,
74
+ )
75
+ elif max_num_threads == env_num_threads:
76
+ warn(
77
+ f'Required number of threads ({num_threads}) is greater than `{env_num_threads_var_name}` '
78
+ f'({env_num_threads}). Using {env_num_threads} threads.',
79
+ stacklevel=warn_stacklevel,
80
+ )
81
+ else:
82
+ warn(
83
+ f'Required number of threads ({num_threads}) is greater than number of available CPU-s '
84
+ f'({num_available_cpus}). Using {num_available_cpus} threads.',
85
+ stacklevel=warn_stacklevel,
86
+ )
87
+ return min(num_threads, max_num_threads)
88
+
89
+ return max_num_threads + num_threads + 1
37
90
 
38
91
 
39
92
  def get_c_contiguous_permutaion(array: np.ndarray) -> Optional[np.ndarray]:
imops/zoom.py CHANGED
@@ -208,7 +208,7 @@ def _zoom(
208
208
 
209
209
  See `https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.zoom.html`
210
210
  """
211
- backend = resolve_backend(backend)
211
+ backend = resolve_backend(backend, warn_stacklevel=4)
212
212
  if backend.name not in ('Scipy', 'Numba', 'Cython'):
213
213
  raise ValueError(f'Unsupported backend "{backend.name}".')
214
214
 
@@ -216,7 +216,7 @@ def _zoom(
216
216
  dtype = input.dtype
217
217
  cval = np.dtype(dtype).type(cval)
218
218
  zoom = fill_by_indices(np.ones(input.ndim, 'float64'), zoom, range(input.ndim))
219
- num_threads = normalize_num_threads(num_threads, backend)
219
+ num_threads = normalize_num_threads(num_threads, backend, warn_stacklevel=4)
220
220
 
221
221
  if backend.name == 'Scipy':
222
222
  return scipy_zoom(
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: imops
3
- Version: 0.8.2
3
+ Version: 0.8.3
4
4
  Summary: Efficient parallelizable algorithms for multidimensional arrays to speed up your data pipelines
5
5
  Home-page: https://github.com/neuro-ml/imops
6
- Download-URL: https://github.com/neuro-ml/imops/archive/v0.8.2.tar.gz
6
+ Download-URL: https://github.com/neuro-ml/imops/archive/v0.8.3.tar.gz
7
7
  Author: maxme1, vovaf709, talgat
8
8
  Author-email: maxme1 <maxs987@gmail.com>, vovaf709 <vovaf709@yandex.ru>, talgat <saparov2130@gmail.com>
9
9
  License: MIT License
@@ -45,6 +45,7 @@ Requires-Python: >=3.6
45
45
  Description-Content-Type: text/markdown
46
46
  License-File: LICENSE
47
47
  Requires-Dist: scipy <2.0.0,>=1.0
48
+ Requires-Dist: scikit-image
48
49
  Requires-Dist: connected-components-3d
49
50
  Requires-Dist: fastremap
50
51
  Requires-Dist: dataclasses ; python_version < "3.7"
@@ -0,0 +1,60 @@
1
+ _build_utils.py,sha256=bxDoFEVfZgjl-yxMv5a-A7jncCD362m4RTpn5SyRgB4,3262
2
+ imops/__init__.py,sha256=QAqK6FnQnOjdDwSXzhnJNB2ur3cGUNbP3ZdLc_VoIEY,514
3
+ imops/__version__.py,sha256=lPOlZg8rjdgN8DyBl7I1rkzxiXOhafW_7RzlMGnvNo8,23
4
+ imops/_configs.py,sha256=6hBY2O4YSaQC_avvqI-dmhZkPMl4p39KQIPtqx5MAh0,734
5
+ imops/backend.py,sha256=8x6Zq9hetOt9_RDcytNNBJZBLNXgQd7ob2dh4WQuuqM,2598
6
+ imops/box.py,sha256=NbYsPKQ8fCGxSm5up0TyqERJ-5iWmnzHLo4Smv9eesk,1865
7
+ imops/crop.py,sha256=hCgwxDgNdIo9m0gleMB3oOUNA7tQurhYNhE5S39tMlE,4055
8
+ imops/interp1d.py,sha256=CSPJ77isqGOJTN-_C--iyz-3qJhpL4dE9i5VdJgSFDE,8400
9
+ imops/measure.py,sha256=YJ5hBDH6iW1hgqm6fi6FIURBKmeZjVfr7LSINOHgFrM,8657
10
+ imops/morphology.py,sha256=KG3RCCicsX7WHsBj4mH6iaJ0dy6tW9cGJJvD4fDisBQ,12723
11
+ imops/numeric.py,sha256=yiSjPTUD2w177LOBD_39_BHh9n8uKbSsHJDchNVsKRY,13650
12
+ imops/pad.py,sha256=OXy_r4X7hOPBU4NSH3B-8ZpxfcY1t6FFMgMSopULpv8,9314
13
+ imops/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ imops/radon.py,sha256=TWsgZvWRapBbU7MVr1fRdpVXCvi6-kt8fxroyQc44ek,9211
15
+ imops/testing.py,sha256=Qiy_Qn7bd7MIXoaZr4T_6r0jQWVRJFwR2z12c_Zwt30,1708
16
+ imops/utils.py,sha256=nfrMUU0OhPgK5UapD9GNC1StPxX3cKbob54kiuf4_qs,6890
17
+ imops/zoom.py,sha256=wl8wt7yoX5V4Mn7sMefV1Fy9KEetqMEdRHLdhT90o6o,9955
18
+ imops/src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
+ imops/src/_backprojection.c,sha256=pq-WMMTwAzP0sRV-nlq_kw3u-1153p7XOHNcJCeE7Ak,1025929
20
+ imops/src/_backprojection.cp39-win32.pyd,sha256=fJJORGmnRhCKjusXLpD7ZAjB-G_eX7sKiz5RX53dDTs,133120
21
+ imops/src/_backprojection.pyx,sha256=xngEJtJ6czjoBRBKL6tu5S7nt6ZgcsE82xDGdCIfagE,2724
22
+ imops/src/_fast_backprojection.c,sha256=RQT-htk9qEMUoO5wlf68mvt426Wrrn4X4lXbqVSpr00,1037428
23
+ imops/src/_fast_backprojection.cp39-win32.pyd,sha256=RomJECxsqeeZPAy-kmucz4rMqtr7lhmeDBaAdO6F0nQ,134656
24
+ imops/src/_fast_backprojection.pyx,sha256=xngEJtJ6czjoBRBKL6tu5S7nt6ZgcsE82xDGdCIfagE,2724
25
+ imops/src/_fast_measure.c,sha256=ZHHHZLgH3JEy-XZ2IPNt9YB_nJF2nc6oI4TxllH2ASw,1337706
26
+ imops/src/_fast_measure.cp39-win32.pyd,sha256=FJ28A8pWzG8ATovcZ_CJmQsTfdCWgA72kNPuSAYmBKs,197632
27
+ imops/src/_fast_measure.pyx,sha256=JzZ26PptkVT08OemSFaJakc4jf7xYocPqV8jfrYi_wA,2737
28
+ imops/src/_fast_morphology.c,sha256=KJn6A6JjRfOBThhkakR4lWnG2GWHq8tw8BA4znkWw94,972949
29
+ imops/src/_fast_morphology.cp39-win32.pyd,sha256=k74JarxSViVMtTzl-SH_p0X4yfnSc3iksgGY6OPQziQ,112640
30
+ imops/src/_fast_morphology.pyx,sha256=QwFrPQ6M-bJDVQNCCtKK7FR3KOr5cZSx_CBvxh9THXM,9538
31
+ imops/src/_fast_numeric.c,sha256=_x72YZLaLydcWmCMX04-iOXYWJKKE0xEYd8w0qB0F4Q,2108485
32
+ imops/src/_fast_numeric.cp39-win32.pyd,sha256=p8NvTo6ALhdpmdXTkEG3jlnf3UcCTaqbx9nedJBbYFk,276992
33
+ imops/src/_fast_numeric.pyx,sha256=c8q3KlL8mDe0wsz72ooeqhffk1iqvA0Org7NWW5RbYo,8221
34
+ imops/src/_fast_radon.c,sha256=gum9CME5tsIwuSKC7pzti91KKkesrEEsYGBZOtI34Ss,1191419
35
+ imops/src/_fast_radon.cp39-win32.pyd,sha256=1VX5aM5ibrLCUfbbEoaulCN5bp4Ote8deZ3y2MUTYRA,175616
36
+ imops/src/_fast_radon.pyx,sha256=pu8EZplCjIDz9HqBcAit8nj2lDgXpmdhU61_4CfdGWI,2987
37
+ imops/src/_fast_zoom.c,sha256=iQHQKLzEjREYPMKAzErRKmtWT4qtmCrzSNP0Sagzm_k,2146413
38
+ imops/src/_fast_zoom.cp39-win32.pyd,sha256=1VwQmqUF-0_Hw1Ywy3h69vVY1ALSsYS6TOq_g86Gj6I,294400
39
+ imops/src/_fast_zoom.pyx,sha256=Dd5MDelALAh4-3QhnzfzKTB5Gmi2lVERrbyYj-q8kVQ,23091
40
+ imops/src/_measure.c,sha256=u3o9ozqfWnrn0PxRrY5l7LEvZEEzkfj4JMuTn0MKcSw,1324916
41
+ imops/src/_measure.cp39-win32.pyd,sha256=n9F3sQ2a967f2azNJygs3e1yixTY1s-0RlVhA4B_kYY,196608
42
+ imops/src/_measure.pyx,sha256=JzZ26PptkVT08OemSFaJakc4jf7xYocPqV8jfrYi_wA,2737
43
+ imops/src/_morphology.c,sha256=ntlYexi4kFK85mMvUkWSlKMf-Fwix05M18NvVEVyYAQ,960908
44
+ imops/src/_morphology.cp39-win32.pyd,sha256=H-n9dG69cC4ciAnP9lz7hG_JVbLGa_AHohePJtInZm4,112128
45
+ imops/src/_morphology.pyx,sha256=QwFrPQ6M-bJDVQNCCtKK7FR3KOr5cZSx_CBvxh9THXM,9538
46
+ imops/src/_numba_zoom.py,sha256=OmMj7mCFkV2P0FaWVXFuYpfzMBQ3Ks60YiHQURes5wQ,16857
47
+ imops/src/_numeric.c,sha256=pxoAtM5-ZGaBVyWd8HBARI7_LnX6_n7kNt6vS1p_JmI,2091727
48
+ imops/src/_numeric.cp39-win32.pyd,sha256=re3mW6G68Yy-qbTBjziH-noY2VzXG_Qgw_QtR9wTMjk,275968
49
+ imops/src/_numeric.pyx,sha256=c8q3KlL8mDe0wsz72ooeqhffk1iqvA0Org7NWW5RbYo,8221
50
+ imops/src/_radon.c,sha256=TdmwLBra4NsH9qtX--0OC6XaTfzN8ApZxDovOC3J9kU,1178982
51
+ imops/src/_radon.cp39-win32.pyd,sha256=9Djx05xMeYwRlsRt9oMmKTDU_fJlxex--u5APBfGITA,175104
52
+ imops/src/_radon.pyx,sha256=pu8EZplCjIDz9HqBcAit8nj2lDgXpmdhU61_4CfdGWI,2987
53
+ imops/src/_zoom.c,sha256=Yli60QHVVNFUJ2ycnbEW_Hbnz15-tRcG_J_xg_rCL4U,2126517
54
+ imops/src/_zoom.cp39-win32.pyd,sha256=0c41mhHV_vYpNIsaDuGl_cHQX6adLPlwiqGPOpTxja8,293376
55
+ imops/src/_zoom.pyx,sha256=Dd5MDelALAh4-3QhnzfzKTB5Gmi2lVERrbyYj-q8kVQ,23091
56
+ imops-0.8.3.dist-info/LICENSE,sha256=x7oyYZPKDTt8KoTitcNJLBWhueke5YEOopdr0XjyvBc,1085
57
+ imops-0.8.3.dist-info/METADATA,sha256=tDl7xwD4lJ6Yx_X7wYRKFuv-_QmBlXMHivDQCOnT_K8,9048
58
+ imops-0.8.3.dist-info/WHEEL,sha256=f7KcxEC-t0Gqz4jsLWrEKtFkz8Ns4-1YqJU5A6LXwLY,96
59
+ imops-0.8.3.dist-info/top_level.txt,sha256=jd2uO-zsYvKeqkZbjEjtkGqCca0IEXEiEuoyr3nsHB0,19
60
+ imops-0.8.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.1)
2
+ Generator: bdist_wheel (0.41.2)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp39-cp39-win32
5
5
 
@@ -0,0 +1,2 @@
1
+ _build_utils
2
+ imops
_pyproject_build.py DELETED
@@ -1,61 +0,0 @@
1
- import shutil
2
- from pathlib import Path
3
-
4
- from setuptools import Extension
5
- from setuptools.command.build_py import build_py
6
-
7
-
8
- class NumpyImport(dict):
9
- """Hacky way to return Numpy's include path with lazy import."""
10
-
11
- # Must be json-serializable due to
12
- # https://github.com/cython/cython/blob/6ad6ca0e9e7d030354b7fe7d7b56c3f6e6a4bc23/Cython/Compiler/ModuleNode.py#L773
13
- def __init__(self):
14
- return super().__init__(self, description=self.__doc__)
15
-
16
- # Must be hashable due to
17
- # https://github.com/cython/cython/blob/6ad6ca0e9e7d030354b7fe7d7b56c3f6e6a4bc23/Cython/Compiler/Main.py#L307
18
- def __hash__(self):
19
- return id(self)
20
-
21
- def __repr__(self):
22
- import numpy as np
23
-
24
- return np.get_include()
25
-
26
- __fspath__ = __repr__
27
-
28
-
29
- class PyprojectBuild(build_py):
30
- def run(self):
31
- self.run_command('build_ext')
32
- return super().run()
33
-
34
- def initialize_options(self):
35
- super().initialize_options()
36
-
37
- name = 'imops'
38
- args = ['-fopenmp']
39
-
40
- if self.distribution.ext_modules is None:
41
- self.distribution.ext_modules = []
42
-
43
- # Cython extension and .pyx source file names must be the same to compile
44
- # https://stackoverflow.com/questions/8024805/cython-compiled-c-extension-importerror-dynamic-module-does-not-define-init-fu
45
- modules = ['backprojection', 'measure', 'morphology', 'numeric', 'radon', 'zoom']
46
- for module in modules:
47
- src_dir = Path(__file__).parent / name / 'src'
48
- shutil.copyfile(src_dir / f'_{module}.pyx', src_dir / f'_fast_{module}.pyx')
49
-
50
- for module in modules:
51
- for prefix, additional_args in zip(['', 'fast_'], [[], ['-ffast-math']]):
52
- self.distribution.ext_modules.append(
53
- Extension(
54
- f'{name}.src._{prefix}{module}',
55
- [f'{name}/src/_{prefix}{module}.pyx'],
56
- include_dirs=[NumpyImport()],
57
- extra_compile_args=args + additional_args,
58
- extra_link_args=args + additional_args,
59
- define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')],
60
- )
61
- )
imops/_numeric.py DELETED
@@ -1,124 +0,0 @@
1
- from warnings import warn
2
-
3
- import numpy as np
4
-
5
- from .backend import BackendLike, resolve_backend
6
- from .src._fast_numeric import (
7
- _parallel_pointwise_mul as cython_fast_parallel_pointwise_mul,
8
- _parallel_sum as cython_fast_parallel_sum,
9
- )
10
- from .src._numeric import _parallel_pointwise_mul as cython_parallel_pointwise_mul, _parallel_sum as cython_parallel_sum
11
- from .utils import normalize_num_threads
12
-
13
-
14
- def _sum(nums: np.ndarray, num_threads: int = -1, backend: BackendLike = None) -> float:
15
- """
16
- Parallel sum of flat numpy array
17
-
18
- Parameters
19
- ----------
20
- nums: np.ndarray
21
- 1-dimensional array
22
- num_threads: int
23
- the number of threads to use for computation. Default = the cpu count. If negative value passed
24
- cpu count + num_threads + 1 threads will be used
25
- backend: BackendLike
26
- which backend to use. `cython` and `scipy` (primarly for benchmarking) are available,
27
- `cython` is used by default
28
-
29
- Returns
30
- -------
31
- sum: float
32
-
33
- Examples
34
- --------
35
- >>> s = _sum(x, num_threads=1)
36
- >>> s = _sum(x, num_threads=8, backend=Cython(fast=True)) # ffast-math compiled version
37
- """
38
- ndim = nums.ndim
39
-
40
- if ndim != 1:
41
- raise ValueError(f'Input must be 1-dimensional instead of {ndim}-dimensional.')
42
-
43
- backend = resolve_backend(backend)
44
- if backend.name not in ('Cython', 'Scipy'):
45
- raise ValueError(f'Unsupported backend "{backend.name}"')
46
-
47
- num_threads = normalize_num_threads(num_threads, backend)
48
-
49
- if backend.name == 'Scipy':
50
- return nums.sum()
51
-
52
- if backend.name == 'Cython':
53
- src_parallel_sum = cython_fast_parallel_sum if backend.fast else cython_parallel_sum
54
-
55
- return src_parallel_sum(nums, num_threads)
56
-
57
-
58
- def _mul(nums1: np.ndarray, nums2: np.ndarray, num_threads: int = -1, backend: BackendLike = None) -> np.ndarray:
59
- """
60
- Parallel pointwise multiplication of 2 numpy arrays (aka x * y). Works faster only for ndim <= 3.
61
-
62
- Parameters
63
- ----------
64
- nums1: np.ndarray
65
- nums2: np.ndarray
66
- num_threads: int
67
- the number of threads to use for computation. Default = the cpu count. If negative value passed
68
- cpu count + num_threads + 1 threads will be used
69
- backend: BackendLike
70
- which backend to use. `cython` and `scipy` (primarly for benchmarking) are available,
71
- `cython` is used by default
72
-
73
- Returns
74
- -------
75
- multiplied: np.ndarray
76
- result of nums1 * nums2
77
-
78
- Examples
79
- --------
80
- >>> mul = _mul(nums1, nums2, num_threads=8)
81
- >>> mul = _mul(np.ones((2, 3)), np.ones((1, 3))) # broadcasting, mul.shape == (2, 3)
82
- >>> mul = _mul(nums1, nums2, backend=Cython(fast=True)) # ffast-math compiled version
83
- """
84
- if not nums1.size and not nums2.size:
85
- return np.array([], dtype=nums1.dtype)
86
- if bool(nums1.size) ^ bool(nums2.size):
87
- raise ValueError('One of the arrays is empty, hence pointwise multiplication cannot be performed.')
88
- if len(nums1.shape) != len(nums2.shape):
89
- raise ValueError('Both arrays must have the same number of dimensions for pointwise multiplication.')
90
- for dim1, dim2 in zip(nums1.shape, nums2.shape):
91
- if dim1 != dim2 and dim1 != 1 and dim2 != 1:
92
- raise ValueError(f'Arrays of shapes {nums1.shape} and {nums2.shape} are not broadcastable.')
93
-
94
- if nums1.ndim > 3:
95
- warn('Parallel pointwise multiplication is only supported for ndim<=3. Falling back to naive x * y.')
96
-
97
- return nums1 * nums2
98
-
99
- backend = resolve_backend(backend)
100
- if backend.name not in ('Cython', 'Scipy'):
101
- raise ValueError(f'Unsupported backend "{backend.name}"')
102
-
103
- num_threads = normalize_num_threads(num_threads, backend)
104
-
105
- if backend.name == 'Scipy':
106
- return nums1 * nums2
107
-
108
- if backend.name == 'Cython':
109
- src_parallel_pointwise_mul = (
110
- cython_fast_parallel_pointwise_mul if backend.fast else cython_parallel_pointwise_mul
111
- )
112
-
113
- n_dummy = 3 - nums1.ndim
114
-
115
- if n_dummy:
116
- nums1 = nums1[(None,) * n_dummy]
117
- nums2 = nums2[(None,) * n_dummy]
118
-
119
- out = src_parallel_pointwise_mul(nums1, nums2, np.maximum(nums1.shape, nums2.shape), num_threads)
120
-
121
- if n_dummy:
122
- out = out[(0,) * n_dummy]
123
-
124
- return out
@@ -1,60 +0,0 @@
1
- _pyproject_build.py,sha256=uSukihAHOd50LUBHTTBCCQ3oi-95bBk01Q4Y6KrXTF8,2297
2
- imops/__init__.py,sha256=DH8Dp0MIEq8j_taTwUMXKqoY3WjdVdBbMnNdKHx_qes,459
3
- imops/__version__.py,sha256=XhFj_ipJJJgnq-LMeWY_tqb7jCV62Abi98yRdQ0le8U,23
4
- imops/_configs.py,sha256=6hBY2O4YSaQC_avvqI-dmhZkPMl4p39KQIPtqx5MAh0,734
5
- imops/_numeric.py,sha256=XfKU5mNGRAAoEKtJ9xrYTxpxNFZv0abHvoolEUVeVdo,4383
6
- imops/backend.py,sha256=lt3BrosqmxFh7BA-rYwYAer3XMdBTPS-pBIR5hHDNa0,2368
7
- imops/box.py,sha256=NbYsPKQ8fCGxSm5up0TyqERJ-5iWmnzHLo4Smv9eesk,1865
8
- imops/crop.py,sha256=hDrPNVFU3vV758KTwZmZxHzm4XgUkLQLSqJOYQHG4P0,3446
9
- imops/interp1d.py,sha256=55NFTGgYUDlcndRvPqKLLPpFe6U0K8B-so8yUgBbK3c,8183
10
- imops/measure.py,sha256=NqCsj2yxuUEfpPmGmOL-YSvI_2rrYUWJyzaSCPoOe90,8575
11
- imops/morphology.py,sha256=GDVnLjGjTZJgcGNyFXPn3BMM7WHZZQeg-i24ci6uCdQ,12625
12
- imops/pad.py,sha256=SAPJQwnuKosPoiCU26YPE4cyRPNrskwfzNOrT3KqSuk,7447
13
- imops/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- imops/radon.py,sha256=C643fB9tzqK0_RyhH9EzQBfHAeEqjbnbGKDT485k5pk,9008
15
- imops/testing.py,sha256=Qiy_Qn7bd7MIXoaZr4T_6r0jQWVRJFwR2z12c_Zwt30,1708
16
- imops/utils.py,sha256=9XoA8qywuuSTluGDf1aEa_zP2Ixu2pNYQnBbWhy92T4,4720
17
- imops/zoom.py,sha256=g7lgv8Z51tNCYfAyQnLlA187QgDzyQHxckEY9Uu9EKY,9917
18
- imops/src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
- imops/src/_backprojection.c,sha256=5XoMEZSqTNf01oDcfOnFJhjl8qnfCjhnP4seUv9FADk,1025929
20
- imops/src/_backprojection.cp39-win32.pyd,sha256=3tGsJYGutX5ChjJ-RtlxVkltylzEAbTQJAahgB3SLdM,132096
21
- imops/src/_backprojection.pyx,sha256=xngEJtJ6czjoBRBKL6tu5S7nt6ZgcsE82xDGdCIfagE,2724
22
- imops/src/_fast_backprojection.c,sha256=951yGc-SgIDiVjtBgU3TEqDec8ItUVqUXV8eOZqq4X4,1037428
23
- imops/src/_fast_backprojection.cp39-win32.pyd,sha256=wqqvIGCEoj1E_9onsytl13eFflr0DDR3H2jWz51U2S0,132608
24
- imops/src/_fast_backprojection.pyx,sha256=xngEJtJ6czjoBRBKL6tu5S7nt6ZgcsE82xDGdCIfagE,2724
25
- imops/src/_fast_measure.c,sha256=oHJVtHGBlx6Hfp26Uvk6rCYTKYveee0AYvLYLvqsIXk,1337706
26
- imops/src/_fast_measure.cp39-win32.pyd,sha256=EHVYrpxls48rpe4tYZEcQX09YfKIM513kHJ8y9GtspY,196096
27
- imops/src/_fast_measure.pyx,sha256=JzZ26PptkVT08OemSFaJakc4jf7xYocPqV8jfrYi_wA,2737
28
- imops/src/_fast_morphology.c,sha256=6QtIiJwX7QaGbLN-mxnkNYr7P-E0XQLZAQUKxp7MFPI,972949
29
- imops/src/_fast_morphology.cp39-win32.pyd,sha256=XYN6o5l9U9Xm7KWnc4lRIlPYyyw_Bd0-WIKGss0TIbo,112128
30
- imops/src/_fast_morphology.pyx,sha256=QwFrPQ6M-bJDVQNCCtKK7FR3KOr5cZSx_CBvxh9THXM,9538
31
- imops/src/_fast_numeric.c,sha256=DE-EqVxJ7H_2JHmAPUvbpOmqHaZUpWJO1gFhTIbAHrw,1316648
32
- imops/src/_fast_numeric.cp39-win32.pyd,sha256=wbkbBPAECNgbOoxXcZVN65ZW7xBJWM17fwaX5gus2DM,186368
33
- imops/src/_fast_numeric.pyx,sha256=bXv4qBx_k6B6INNR0r49HU2a8UNnpt-mCS19TczcU38,1919
34
- imops/src/_fast_radon.c,sha256=bBaQ82EtE5myelucU55DZKEbWqI58XWd8jL4vyNF_Js,1191419
35
- imops/src/_fast_radon.cp39-win32.pyd,sha256=4BJyH12ukVYR3AGQmPmutQDBxacKqvRAp9CYi3mUQ_E,174080
36
- imops/src/_fast_radon.pyx,sha256=pu8EZplCjIDz9HqBcAit8nj2lDgXpmdhU61_4CfdGWI,2987
37
- imops/src/_fast_zoom.c,sha256=axitDiC76XZHFD3kBZV-21EltPHbzuo6qIFX5MnfbwE,2146413
38
- imops/src/_fast_zoom.cp39-win32.pyd,sha256=C4bYz2Uy5C-WYxrPAD7BOQTdN_9Vr_ayVNEMX3KUVpg,286720
39
- imops/src/_fast_zoom.pyx,sha256=Dd5MDelALAh4-3QhnzfzKTB5Gmi2lVERrbyYj-q8kVQ,23091
40
- imops/src/_measure.c,sha256=UM3FmYicJKg7LuUgWDfAjegfiVYkHBcfJ25sYt5yUgI,1324916
41
- imops/src/_measure.cp39-win32.pyd,sha256=qW68jMqvC-zKCN0wWyH6W9IcwXGqblKU6AXbbi5N9SY,195584
42
- imops/src/_measure.pyx,sha256=JzZ26PptkVT08OemSFaJakc4jf7xYocPqV8jfrYi_wA,2737
43
- imops/src/_morphology.c,sha256=DbXmz3xdWnjKVSCE2VUOSmdeX5Rmzyrjl8MAa5I0v8g,960908
44
- imops/src/_morphology.cp39-win32.pyd,sha256=mkfoGsIrcI3a7WjJOfkuGgYfbuHRafvEz9udcVWxBZ0,111104
45
- imops/src/_morphology.pyx,sha256=QwFrPQ6M-bJDVQNCCtKK7FR3KOr5cZSx_CBvxh9THXM,9538
46
- imops/src/_numba_zoom.py,sha256=OmMj7mCFkV2P0FaWVXFuYpfzMBQ3Ks60YiHQURes5wQ,16857
47
- imops/src/_numeric.c,sha256=uxea9Ex1oDrkmZd56CjX9HCmcPLmEXXVcItMQX2W6lY,1304396
48
- imops/src/_numeric.cp39-win32.pyd,sha256=Ma_foIYe9xMdZ_hoYSwXb8sTlHZheXjQEPdRGTI6ORQ,185856
49
- imops/src/_numeric.pyx,sha256=bXv4qBx_k6B6INNR0r49HU2a8UNnpt-mCS19TczcU38,1919
50
- imops/src/_radon.c,sha256=xTkrtTvqJahQaAqkr3_n46cBlFAp4EsZjbPuai1ngMU,1178982
51
- imops/src/_radon.cp39-win32.pyd,sha256=O2M1rZPTteDeDp886GnMrpECt-yS-wvHkdIWQzwG2c0,173056
52
- imops/src/_radon.pyx,sha256=pu8EZplCjIDz9HqBcAit8nj2lDgXpmdhU61_4CfdGWI,2987
53
- imops/src/_zoom.c,sha256=l20RSfpVYnQ4OsGhXIgTfu7pk1Zx3FpO_ILPN4eKAV4,2126517
54
- imops/src/_zoom.cp39-win32.pyd,sha256=G-CFY0PjeKd_rg1YClWe24IHpNbQFE2-oE4pLpJsVsA,286208
55
- imops/src/_zoom.pyx,sha256=Dd5MDelALAh4-3QhnzfzKTB5Gmi2lVERrbyYj-q8kVQ,23091
56
- imops-0.8.2.dist-info/LICENSE,sha256=x7oyYZPKDTt8KoTitcNJLBWhueke5YEOopdr0XjyvBc,1085
57
- imops-0.8.2.dist-info/METADATA,sha256=e7IeHhaE0H-Aycd7_5C855KnzGRa8K3ILrXHHXslxkQ,9019
58
- imops-0.8.2.dist-info/WHEEL,sha256=7ZXx6xbfqHPd62Znb0xrpRpdgnbHbS6AovUcQnLmei8,96
59
- imops-0.8.2.dist-info/top_level.txt,sha256=N1kO5Q0hGO9R4DFsT_VsHcDKv2KQSsrBF4eQd2ZeURA,23
60
- imops-0.8.2.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- _pyproject_build
2
- imops
File without changes