Skip to content

Commit f0d48db

Browse files
jnistefanv
authored andcommitted
Use fused types in denoise, warp (#3486)
* MNT: Add a fused numeric type to make fused_types more constent. * MNT: make the interpolation use fused types for any->any type interpolation of images. * MNT: Move even more numpy function calls from Cython to Python. * MNT: More explicit type specifying * BUG: Use fused floats in denoise Pull all denoise array allocation out into python Function used in python should be def not cdef Have the correct number of arguments * MNT: Add additional type check for denoise, more docs * PEP8 fixes * Remove redundant array u and view cu * Mutate output array in Cython and trim in Python * Replace height and width with existing rows and cols * Change iteration order to match array order * Move range_lut and color_lut properly from Cy to Py * Ravel range LUT which is expected to be 1D * Update comment in denoise bilateral tests * Fix relative import in interpolation.pyx * BENCH: Benchmark for warping with many types * Rename warp benchmark file * Update pointer syntax Co-Authored-By: jni <juan.nunez-iglesias@monash.edu>
1 parent 090d1f1 commit f0d48db

8 files changed

Lines changed: 325 additions & 226 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import numpy as np
2+
from skimage.transform import SimilarityTransform, warp
3+
from skimage.util.dtype import convert
4+
import warnings
5+
import functools
6+
import inspect
7+
8+
9+
class WarpSuite:
10+
params = ([np.uint8, np.uint16, np.float32, np.float64],
11+
[128, 1024, 4096],
12+
[0, 1, 3],
13+
# [np.float32, np.float64]
14+
)
15+
# param_names = ['dtype_in', 'N', 'order', 'dtype_tform']
16+
param_names = ['dtype_in', 'N', 'order']
17+
18+
# def setup(self, dtype_in, N, order, dtype_tform):
19+
def setup(self, dtype_in, N, order):
20+
with warnings.catch_warnings():
21+
warnings.filterwarnings("ignore", "Possible precision loss")
22+
self.image = convert(np.random.random((N, N)), dtype=dtype_in)
23+
self.tform = SimilarityTransform(scale=1, rotation=np.pi / 10,
24+
translation=(0, 4))
25+
self.tform.params = self.tform.params.astype('float32')
26+
self.order = order
27+
28+
if 'dtype' in inspect.signature(warp).parameters:
29+
self.warp = functools.partial(warp, dtype=self.image.dtype)
30+
else:
31+
# Keep a call to functools to have the same number of python
32+
# function calls
33+
self.warp = functools.partial(warp)
34+
35+
# def time_same_type(self, dtype_in, N, order, dtype_tform):
36+
def time_same_type(self, dtype_in, N, order):
37+
"""Test the case where the users wants to preserve their same low
38+
precision data type."""
39+
result = self.warp(self.image, self.tform, order=self.order,
40+
preserve_range=True)
41+
42+
# convert back to input type, no-op if same type
43+
result = result.astype(dtype_in, copy=False)
44+
45+
# def time_to_float64(self, dtype_in, N, order, dtype_form):
46+
def time_to_float64(self, dtype_in, N, order):
47+
"""Test the case where want to upvert to float64 for continued
48+
transformations."""
49+
result = warp(self.image, self.tform, order=self.order,
50+
preserve_range=True)

skimage/_shared/fused_numerics.pxd

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
cimport numpy as cnp
2+
import numpy as np
3+
4+
ctypedef fused np_ints:
5+
cnp.int8_t
6+
cnp.int16_t
7+
cnp.int32_t
8+
cnp.int64_t
9+
10+
ctypedef fused np_uints:
11+
cnp.uint8_t
12+
cnp.uint16_t
13+
cnp.uint32_t
14+
cnp.uint64_t
15+
16+
ctypedef fused np_anyint:
17+
np_uints
18+
np_ints
19+
20+
ctypedef fused np_floats:
21+
cnp.float32_t
22+
cnp.float64_t
23+
24+
ctypedef fused np_complexes:
25+
cnp.complex64_t
26+
cnp.complex128_t
27+
28+
ctypedef fused np_real_numeric:
29+
np_anyint
30+
np_floats
31+
32+
ctypedef fused np_numeric:
33+
np_real_numeric
34+
np_complexes

0 commit comments

Comments
 (0)