Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lambda wrappers #139

Merged
merged 4 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/rank_filter.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ cdef extern from "rank_filter.hxx" namespace "rank_filter":
@cython.boundscheck(False)
@cython.initializedcheck(False)
@cython.nonecheck(False)
cdef inline void lineRankOrderFilter1D_floating(floating[::1] src,
floating[::1] dest,
size_t half_length,
double rank) nogil:
cdef floating* src_begin = &src[0]
cdef floating* src_end = &src[-1] + 1
cdef floating* dest_begin = &dest[0]
cdef floating* dest_end = &dest[-1] + 1
cdef inline void lineRankOrderFilter1D_floating_inplace(floating[::1] a,
size_t half_length,
double rank) nogil:
cdef floating* a_begin = &a[0]
cdef floating* a_end = &a[-1] + 1

lineRankOrderFilter1D(
src_begin, src_end, dest_begin, dest_end, half_length, rank
a_begin, a_end, a_begin, a_end, half_length, rank
)
26 changes: 12 additions & 14 deletions src/rank_filter.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rank_filter cimport lineRankOrderFilter1D_floating
from rank_filter cimport lineRankOrderFilter1D_floating_inplace

cimport cython

Expand Down Expand Up @@ -52,26 +52,24 @@ def lineRankOrderFilter(image not None,
"Both `image` and `out` must have the same shape."
numpy.copyto(out, image)

lineRankOrderFilter1D = None
out_swap = numpy.ascontiguousarray(out.swapaxes(axis, -1))
out_strip_indices = numpy.ndindex(out_swap.shape[:-1])

if out.dtype.type == numpy.float32:
lineRankOrderFilter1D = lambda a1, a2: \
lineRankOrderFilter1D_floating[float](a1, a2, half_length, rank)
for idx in out_strip_indices:
lineRankOrderFilter1D_floating_inplace[float](
out_swap[idx], half_length, rank
)
elif out.dtype.type == numpy.float64:
lineRankOrderFilter1D = lambda a1, a2: \
lineRankOrderFilter1D_floating[double](a1, a2, half_length, rank)
for idx in out_strip_indices:
lineRankOrderFilter1D_floating_inplace[double](
out_swap[idx], half_length, rank
)
else:
raise TypeError(
"Only `float32` and `float64` are supported for `image` and `out`."
)

out_swap = numpy.ascontiguousarray(out.swapaxes(axis, -1))
out_strip_indices = numpy.ndindex(out_swap.shape[:-1])
out_strip = None

for idx in out_strip_indices:
out_strip = out_swap[idx]
lineRankOrderFilter1D(out_strip, out_strip)

numpy.copyto(out, out_swap.swapaxes(-1, axis))

return(out)