Skip to content

Commit

Permalink
Eliminate lambda wrappers
Browse files Browse the repository at this point in the history
Instead of using `lambda` wrappers`, simply call the fused type function
directly with the intended specialization. Should cutdown the overhead
of dispatch and make it easier for the compiler to inline it. This
remains pretty compact thanks to the conversion of the function to an
in-place computation and some previous refactoring.
  • Loading branch information
jakirkham committed Oct 15, 2018
1 parent 5d6fc90 commit ddeaf0f
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/rank_filter.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,25 @@ 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])
out_strip = None

if out.dtype.type == numpy.float32:
lineRankOrderFilter1D = lambda a: \
for idx in out_strip_indices:
lineRankOrderFilter1D_floating_inplace[float](
a, half_length, rank
out_swap[idx], half_length, rank
)
elif out.dtype.type == numpy.float64:
lineRankOrderFilter1D = lambda a: \
for idx in out_strip_indices:
lineRankOrderFilter1D_floating_inplace[double](
a, half_length, rank
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:
lineRankOrderFilter1D(out_swap[idx])

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

return(out)

0 comments on commit ddeaf0f

Please sign in to comment.