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
Optimized saturation operator #22
Conversation
@sgillies could I get your 👀 on the Cython code in
Ping me if you see anything that we could do more safely, concisely or efficiently. |
cdef int a0 = arr.shape[0] | ||
cdef int a1 = arr.shape[1] | ||
cdef int a2 = arr.shape[2] | ||
cdef np.ndarray[FLOAT_t, ndim=3] out = np.zeros((a0, a1, a2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find any advice or benchmarks on the best way to allocate an array of equal shape. This works but there may be more efficient ways.
@sgillies typing the loop variables didn't do much for speed but changing the order did. I looked into memoryviews. The primary benefit seems to be writing generic functions that can use cython, numpy or C arrays. I tried memoryviews and it works but there's no speed difference and I don't see the benefit - dealing with numpy arrays explicitly seems like a cleaner approach. |
Resolves #21
The previous saturation operation went something like:
This PR provides a cython
rio_color.colorspace
module which provides c functions to do the math directly, then some python wrappers to work efficiently against ndarrays.See #21 for details of testing and benchmarks.