Thank you for your response, Tanaka-san.
On 2/12/06, Masahiro TANAKA [email protected] wrote:
This is probably because a function (SetFuncs) is called
every step of the loop. How about using na_change_type() ?
Your suggestion is very fast when the types are matched, but if the
original is not a double, the penalty for copying the array is
significant. Also, it’s incorrect if the type cannot be represented
as a float (e.g. complex). (see benchmarks below)
I appreciate the general nature on the design of NArray, and I’ve
learned several nice tricks from investigating it. However, the moral
I’m taking home is that if speed, efficiency and generality are all at
issue, individual routines for each NArray type are still the best way
to go at the C level.
To build extensions with one algorithm description, it seems the best
way is some macro type pseudo C code that can be parsed to generate
multiple C functions for each type. Do you agree?
This seems to justify the approach of the PDL project (perl) and the
PP language that is employed for general extensions. (and I was so
hoping to keep this at the straight forward C level to exploit the
beauty of ruby’s C API. ahh well - it is just C).
Any additional comments or suggestions are welcome, I’d love to find
something I missed.
Thanks!
Cameron
Benchmarking based on:
num_runs = 1000
data_size = 100000
==> INT <==
creating vectors: NArray.int(data_size).random!(100)
user system total real
NArray_rb 1.050000 0.410000 1.460000 ( 1.459850)
NArray_mod 2.670000 0.030000 2.700000 ( 2.706433)
NArray_ct 2.220000 1.600000 3.820000 ( 3.819964)
==> SFLOAT <==
creating vectors: NArray.sfloat(data_size).random!(100)
user system total real
NArray_rb 2.590000 0.340000 2.930000 ( 2.928844)
NArray_mod 2.440000 0.020000 2.460000 ( 2.467045)
NArray_ct 2.100000 1.610000 3.710000 ( 3.715267)
==> FLOAT <==
creating vectors: NArray.float(data_size).random!(100)
user system total real
NArray_rb 2.800000 0.800000 3.600000 ( 3.605653)
NArray_mod 3.920000 0.010000 3.930000 ( 3.934259)
NArray_ct 1.020000 0.000000 1.020000 ( 1.026064)
==> COMPLEX <==
creating vectors: NArray.complex(data_size).random!(100)
user system total real
NArray_rb 5.970000 1.420000 7.390000 ( 7.390152)
NArray_mod 3.950000 0.020000 3.970000 ( 3.971336)
NArray_ct 2.820000 1.590000 4.410000 ( 4.411596)