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.
- _build_utils.py +87 -0
- imops/__init__.py +1 -0
- imops/__version__.py +1 -1
- imops/backend.py +14 -10
- imops/crop.py +18 -2
- imops/interp1d.py +7 -4
- imops/measure.py +7 -7
- imops/morphology.py +6 -5
- imops/numeric.py +376 -0
- imops/pad.py +41 -5
- imops/radon.py +7 -5
- imops/src/_backprojection.c +83 -83
- imops/src/_backprojection.cp39-win32.pyd +0 -0
- imops/src/_fast_backprojection.c +96 -96
- imops/src/_fast_backprojection.cp39-win32.pyd +0 -0
- imops/src/_fast_measure.c +96 -96
- imops/src/_fast_measure.cp39-win32.pyd +0 -0
- imops/src/_fast_morphology.c +96 -96
- imops/src/_fast_morphology.cp39-win32.pyd +0 -0
- imops/src/_fast_numeric.c +20545 -4996
- imops/src/_fast_numeric.cp39-win32.pyd +0 -0
- imops/src/_fast_numeric.pyx +208 -30
- imops/src/_fast_radon.c +96 -96
- imops/src/_fast_radon.cp39-win32.pyd +0 -0
- imops/src/_fast_zoom.c +96 -96
- imops/src/_fast_zoom.cp39-win32.pyd +0 -0
- imops/src/_measure.c +83 -83
- imops/src/_measure.cp39-win32.pyd +0 -0
- imops/src/_morphology.c +83 -83
- imops/src/_morphology.cp39-win32.pyd +0 -0
- imops/src/_numeric.c +20532 -4983
- imops/src/_numeric.cp39-win32.pyd +0 -0
- imops/src/_numeric.pyx +208 -30
- imops/src/_radon.c +83 -83
- imops/src/_radon.cp39-win32.pyd +0 -0
- imops/src/_zoom.c +83 -83
- imops/src/_zoom.cp39-win32.pyd +0 -0
- imops/utils.py +65 -12
- imops/zoom.py +2 -2
- {imops-0.8.2.dist-info → imops-0.8.3.dist-info}/METADATA +3 -2
- imops-0.8.3.dist-info/RECORD +60 -0
- {imops-0.8.2.dist-info → imops-0.8.3.dist-info}/WHEEL +1 -1
- imops-0.8.3.dist-info/top_level.txt +2 -0
- _pyproject_build.py +0 -61
- imops/_numeric.py +0 -124
- imops-0.8.2.dist-info/RECORD +0 -60
- imops-0.8.2.dist-info/top_level.txt +0 -2
- {imops-0.8.2.dist-info → imops-0.8.3.dist-info}/LICENSE +0 -0
|
Binary file
|
imops/src/_fast_numeric.pyx
CHANGED
|
@@ -8,10 +8,19 @@
|
|
|
8
8
|
import numpy as np
|
|
9
9
|
|
|
10
10
|
cimport numpy as np
|
|
11
|
+
from libc.stdint cimport uint16_t
|
|
11
12
|
|
|
12
13
|
from cython.parallel import prange
|
|
13
14
|
|
|
14
15
|
|
|
16
|
+
# https://stackoverflow.com/questions/47421443/using-half-precision-numpy-floats-in-cython
|
|
17
|
+
cdef extern from "numpy/halffloat.h":
|
|
18
|
+
ctypedef uint16_t npy_half
|
|
19
|
+
|
|
20
|
+
float npy_half_to_float(npy_half h) nogil
|
|
21
|
+
npy_half npy_float_to_half(float f) nogil
|
|
22
|
+
|
|
23
|
+
|
|
15
24
|
ctypedef fused NUM:
|
|
16
25
|
short
|
|
17
26
|
int
|
|
@@ -20,45 +29,214 @@ ctypedef fused NUM:
|
|
|
20
29
|
double
|
|
21
30
|
|
|
22
31
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
ctypedef fused NUM_AND_NPY_HALF:
|
|
33
|
+
NUM
|
|
34
|
+
npy_half
|
|
26
35
|
|
|
27
|
-
for i in prange(len_nums, num_threads=num_threads, nogil=True):
|
|
28
|
-
res += nums[i]
|
|
29
36
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def _parallel_pointwise_mul(
|
|
37
|
+
# TODO: Generalize code below to n-d
|
|
38
|
+
def _pointwise_add_array_3d(
|
|
34
39
|
NUM[:, :, :] nums1,
|
|
35
40
|
NUM[:, :, :] nums2,
|
|
36
|
-
|
|
37
|
-
Py_ssize_t num_threads
|
|
41
|
+
NUM[:, :, :] out,
|
|
42
|
+
Py_ssize_t num_threads,
|
|
38
43
|
) -> np.ndarray:
|
|
39
|
-
cdef
|
|
40
|
-
cdef Py_ssize_t
|
|
44
|
+
cdef Py_ssize_t rows = out.shape[0], cols = out.shape[1], dims = out.shape[2]
|
|
45
|
+
cdef Py_ssize_t i, j, k
|
|
46
|
+
|
|
47
|
+
for i in prange(rows, nogil=True, num_threads=num_threads):
|
|
48
|
+
for j in prange(cols):
|
|
49
|
+
for k in prange(dims):
|
|
50
|
+
out[i, j, k] = nums1[i, j, k] + nums2[i, j, k]
|
|
51
|
+
|
|
52
|
+
return np.asarray(out)
|
|
41
53
|
|
|
42
|
-
cdef char[:] broadcast_mask1 = np.array([x == y for x, y in zip(res_shape, nums1.shape)], dtype=np.int8)
|
|
43
|
-
cdef char[:] broadcast_mask2 = np.array([x == y for x, y in zip(res_shape, nums2.shape)], dtype=np.int8)
|
|
44
54
|
|
|
45
|
-
|
|
55
|
+
def _pointwise_add_array_4d(
|
|
56
|
+
NUM[:, :, :, :] nums1,
|
|
57
|
+
NUM[:, :, :, :] nums2,
|
|
58
|
+
NUM[:, :, :, :] out,
|
|
59
|
+
Py_ssize_t num_threads,
|
|
60
|
+
) -> np.ndarray:
|
|
61
|
+
cdef Py_ssize_t dim1 = out.shape[0], dim2 = out.shape[1], dim3 = out.shape[2], dim4 = out.shape[3]
|
|
62
|
+
cdef Py_ssize_t i1, i2, i3, i4
|
|
63
|
+
|
|
64
|
+
for i1 in prange(dim1, nogil=True, num_threads=num_threads):
|
|
65
|
+
for i2 in prange(dim2):
|
|
66
|
+
for i3 in prange(dim3):
|
|
67
|
+
for i4 in prange(dim4):
|
|
68
|
+
out[i1, i2, i3, i4] = nums1[i1, i2, i3, i4] + nums2[i1, i2, i3, i4]
|
|
69
|
+
|
|
70
|
+
return np.asarray(out)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _pointwise_add_value_3d(
|
|
74
|
+
NUM[:, :, :] nums,
|
|
75
|
+
NUM value,
|
|
76
|
+
NUM[:, :, :] out,
|
|
77
|
+
Py_ssize_t num_threads,
|
|
78
|
+
) -> np.ndarray:
|
|
79
|
+
cdef Py_ssize_t rows = out.shape[0], cols = out.shape[1], dims = out.shape[2]
|
|
46
80
|
cdef Py_ssize_t i, j, k
|
|
47
81
|
|
|
48
82
|
for i in prange(rows, nogil=True, num_threads=num_threads):
|
|
49
83
|
for j in prange(cols):
|
|
50
84
|
for k in prange(dims):
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
85
|
+
out[i, j, k] = nums[i, j, k] + value
|
|
86
|
+
|
|
87
|
+
return np.asarray(out)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _pointwise_add_value_4d(
|
|
91
|
+
NUM[:, :, :, :] nums,
|
|
92
|
+
NUM value,
|
|
93
|
+
NUM[:, :, :, :] out,
|
|
94
|
+
Py_ssize_t num_threads,
|
|
95
|
+
) -> np.ndarray:
|
|
96
|
+
cdef Py_ssize_t dim1 = out.shape[0], dim2 = out.shape[1], dim3 = out.shape[2], dim4 = out.shape[3]
|
|
97
|
+
cdef Py_ssize_t i1, i2, i3, i4
|
|
98
|
+
|
|
99
|
+
for i1 in prange(dim1, nogil=True, num_threads=num_threads):
|
|
100
|
+
for i2 in prange(dim2):
|
|
101
|
+
for i3 in prange(dim3):
|
|
102
|
+
for i4 in prange(dim4):
|
|
103
|
+
out[i1, i2, i3, i4] = nums[i1, i2, i3, i4] + value
|
|
104
|
+
|
|
105
|
+
return np.asarray(out)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _pointwise_add_array_3d_fp16(
|
|
109
|
+
npy_half[:, :, :] nums1,
|
|
110
|
+
npy_half[:, :, :] nums2,
|
|
111
|
+
npy_half[:, :, :] out,
|
|
112
|
+
Py_ssize_t num_threads,
|
|
113
|
+
) -> np.ndarray:
|
|
114
|
+
cdef Py_ssize_t rows = out.shape[0], cols = out.shape[1], dims = out.shape[2]
|
|
115
|
+
cdef Py_ssize_t i, j, k
|
|
116
|
+
|
|
117
|
+
for i in prange(rows, nogil=True, num_threads=num_threads):
|
|
118
|
+
for j in prange(cols):
|
|
119
|
+
for k in prange(dims):
|
|
120
|
+
out[i, j, k] = (npy_float_to_half(npy_half_to_float(nums1[i, j, k]) +
|
|
121
|
+
npy_half_to_float(nums2[i, j, k])))
|
|
122
|
+
|
|
123
|
+
return np.asarray(out)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _pointwise_add_array_4d_fp16(
|
|
127
|
+
npy_half[:, :, :, :] nums1,
|
|
128
|
+
npy_half[:, :, :, :] nums2,
|
|
129
|
+
npy_half[:, :, :, :] out,
|
|
130
|
+
Py_ssize_t num_threads,
|
|
131
|
+
) -> np.ndarray:
|
|
132
|
+
cdef Py_ssize_t dim1 = out.shape[0], dim2 = out.shape[1], dim3 = out.shape[2], dim4 = out.shape[3]
|
|
133
|
+
cdef Py_ssize_t i1, i2, i3, i4
|
|
134
|
+
|
|
135
|
+
for i1 in prange(dim1, nogil=True, num_threads=num_threads):
|
|
136
|
+
for i2 in prange(dim2):
|
|
137
|
+
for i3 in prange(dim3):
|
|
138
|
+
for i4 in prange(dim4):
|
|
139
|
+
out[i1, i2, i3, i4] = (npy_float_to_half(npy_half_to_float(nums1[i1, i2, i3, i4]) +
|
|
140
|
+
npy_half_to_float(nums2[i1, i2, i3, i4])))
|
|
141
|
+
|
|
142
|
+
return np.asarray(out)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _pointwise_add_value_3d_fp16(
|
|
146
|
+
npy_half[:, :, :] nums,
|
|
147
|
+
npy_half value,
|
|
148
|
+
npy_half[:, :, :] out,
|
|
149
|
+
Py_ssize_t num_threads,
|
|
150
|
+
) -> np.ndarray:
|
|
151
|
+
cdef Py_ssize_t rows = out.shape[0], cols = out.shape[1], dims = out.shape[2]
|
|
152
|
+
cdef Py_ssize_t i, j, k
|
|
153
|
+
|
|
154
|
+
for i in prange(rows, nogil=True, num_threads=num_threads):
|
|
155
|
+
for j in prange(cols):
|
|
156
|
+
for k in prange(dims):
|
|
157
|
+
out[i, j, k] = npy_float_to_half(npy_half_to_float(nums[i, j, k]) + npy_half_to_float(value))
|
|
158
|
+
|
|
159
|
+
return np.asarray(out)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _pointwise_add_value_4d_fp16(
|
|
163
|
+
npy_half[:, :, :, :] nums,
|
|
164
|
+
npy_half value,
|
|
165
|
+
npy_half[:, :, :, :] out,
|
|
166
|
+
Py_ssize_t num_threads,
|
|
167
|
+
) -> np.ndarray:
|
|
168
|
+
cdef Py_ssize_t dim1 = out.shape[0], dim2 = out.shape[1], dim3 = out.shape[2], dim4 = out.shape[3]
|
|
169
|
+
cdef Py_ssize_t i1, i2, i3, i4
|
|
170
|
+
|
|
171
|
+
for i1 in prange(dim1, nogil=True, num_threads=num_threads):
|
|
172
|
+
for i2 in prange(dim2):
|
|
173
|
+
for i3 in prange(dim3):
|
|
174
|
+
for i4 in prange(dim4):
|
|
175
|
+
out[i1, i2, i3, i4] = (npy_float_to_half(npy_half_to_float(nums[i1, i2, i3, i4]) +
|
|
176
|
+
npy_half_to_float(value)))
|
|
177
|
+
|
|
178
|
+
return np.asarray(out)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _fill_3d(NUM_AND_NPY_HALF[:, :, :] nums, NUM_AND_NPY_HALF value, Py_ssize_t num_threads) -> None:
|
|
182
|
+
cdef Py_ssize_t rows = nums.shape[0], cols = nums.shape[1], dims = nums.shape[2]
|
|
183
|
+
cdef Py_ssize_t i, j, k
|
|
184
|
+
|
|
185
|
+
for i in prange(rows, nogil=True, num_threads=num_threads):
|
|
186
|
+
for j in prange(cols):
|
|
187
|
+
for k in prange(dims):
|
|
188
|
+
nums[i, j, k] = value
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _fill_4d(NUM_AND_NPY_HALF[:, :, :, :] nums, NUM_AND_NPY_HALF value, Py_ssize_t num_threads) -> None:
|
|
192
|
+
cdef Py_ssize_t dim1 = nums.shape[0], dim2 = nums.shape[1], dim3 = nums.shape[2], dim4 = nums.shape[3]
|
|
193
|
+
cdef Py_ssize_t i1, i2, i3, i4
|
|
194
|
+
|
|
195
|
+
for i1 in prange(dim1, nogil=True, num_threads=num_threads):
|
|
196
|
+
for i2 in prange(dim2):
|
|
197
|
+
for i3 in prange(dim3):
|
|
198
|
+
for i4 in prange(dim4):
|
|
199
|
+
nums[i1, i2, i3, i4] = value
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
# FIXME: somehow `const NUM_AND_NPY_HALF` is not working
|
|
203
|
+
cpdef void _copy_3d(const NUM[:, :, :] nums1, NUM[:, :, :] nums2, Py_ssize_t num_threads):
|
|
204
|
+
cdef Py_ssize_t rows = nums1.shape[0], cols = nums1.shape[1], dims = nums1.shape[2]
|
|
205
|
+
cdef Py_ssize_t i, j, k
|
|
206
|
+
|
|
207
|
+
for i in prange(rows, nogil=True, num_threads=num_threads):
|
|
208
|
+
for j in prange(cols):
|
|
209
|
+
for k in prange(dims):
|
|
210
|
+
nums2[i, j, k] = nums1[i, j, k]
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
cpdef void _copy_4d(const NUM[:, :, :, :] nums1, NUM[:, :, :, :] nums2, Py_ssize_t num_threads):
|
|
214
|
+
cdef Py_ssize_t dim1 = nums1.shape[0], dim2 = nums1.shape[1], dim3 = nums1.shape[2], dim4 = nums1.shape[3]
|
|
215
|
+
cdef Py_ssize_t i1, i2, i3, i4
|
|
216
|
+
|
|
217
|
+
for i1 in prange(dim1, nogil=True, num_threads=num_threads):
|
|
218
|
+
for i2 in prange(dim2):
|
|
219
|
+
for i3 in prange(dim3):
|
|
220
|
+
for i4 in prange(dim4):
|
|
221
|
+
nums2[i1, i2, i3, i4] = nums1[i1, i2, i3, i4]
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
cpdef void _copy_3d_fp16(const npy_half[:, :, :] nums1, npy_half[:, :, :] nums2, Py_ssize_t num_threads):
|
|
225
|
+
cdef Py_ssize_t rows = nums1.shape[0], cols = nums1.shape[1], dims = nums1.shape[2]
|
|
226
|
+
cdef Py_ssize_t i, j, k
|
|
227
|
+
|
|
228
|
+
for i in prange(rows, nogil=True, num_threads=num_threads):
|
|
229
|
+
for j in prange(cols):
|
|
230
|
+
for k in prange(dims):
|
|
231
|
+
nums2[i, j, k] = nums1[i, j, k]
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
cpdef void _copy_4d_fp16(const npy_half[:, :, :, :] nums1, npy_half[:, :, :, :] nums2, Py_ssize_t num_threads):
|
|
235
|
+
cdef Py_ssize_t dim1 = nums1.shape[0], dim2 = nums1.shape[1], dim3 = nums1.shape[2], dim4 = nums1.shape[3]
|
|
236
|
+
cdef Py_ssize_t i1, i2, i3, i4
|
|
237
|
+
|
|
238
|
+
for i1 in prange(dim1, nogil=True, num_threads=num_threads):
|
|
239
|
+
for i2 in prange(dim2):
|
|
240
|
+
for i3 in prange(dim3):
|
|
241
|
+
for i4 in prange(dim4):
|
|
242
|
+
nums2[i1, i2, i3, i4] = nums1[i1, i2, i3, i4]
|