in reply to Re^2: Processing values of a piddle (PDL) speedup using 'at' vs. 'index'
in thread Processing values of a piddle (PDL) speedup using 'at' vs. 'index'

I take values from these pdls, check them to see if they are a special value, change the value if needed, and then put them into a perl array.

I would say that is entirely the wrong way to do it.

You need to export the piddle in order to print it. So export it first; then search that for your special values; and only access the piddle elements individually if you find the special value in the exported array -- just to update it with the new value.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

  • Comment on Re^3: Processing values of a piddle (PDL) speedup using 'at' vs. 'index'

Replies are listed 'Best First'.
Re^4: Processing values of a piddle (PDL) speedup using 'at' vs. 'index'
by kevbot (Vicar) on Jul 18, 2012 at 04:37 UTC

    I agree (but my actual use case is a little more complex than the code examples that I have given here). I added an additional subroutine to my benchmark code to see how much faster your suggested approach would be. In the 'perl_array' sub, I export the entire pdl to a perl array using the PDL 'list' command. Then, I search the perl array for the "special value" and replace them with an empty string. This is approach is faster.

    Rate pdl_values perl_values perl_array pdl_values 1.52/s -- -97% -99% perl_values 52.3/s 3345% -- -73% perl_array 197/s 12865% 276% --