[Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)
Christopher Barker
Chris.Barker at noaa.gov
Wed Jan 10 18:19:07 EST 2007
A. M. Archibald wrote:
> Why not write the algorithm in C?
I did just that a while back, for Numeric. I've enclosed the code for
reference.
Unfortunately, I never did figure out an efficient way to write this
sort of thing for all types, so it only does doubles. Also, it does a
bunch of special casing for discontiguous vs. contiguous arrays, and
clipping to an array vs a scaler for the min and max arguments.
Do what you will with the code...
look for NumericExtras_fastclip in with the rest of the stuff in there
-- much of which is now obsolete -- I haven't touched this is a few years.
-Chris
NOTE: is there a clean and efficient way to write custom functions of
this sort for all types and both contiguous and discontiguous arrays? I
guess I'm imaging some smart iterators and a micro version of C++
templates -- or maybe use C++ templates themselves.
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: NumericExtras.c
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070110/1e8f6a59/attachment.c>
More information about the NumPy-Discussion
mailing list