Repository navigation
ENH: Optimize performance of np.atleast_1d - #26130
Conversation
|
We looked at this at the triage meeting and think this needs asv benchmarks. It would be good to see that the slowdown for the list of arrays case is not significant. It would also be good to add a comment explaining that the single-element case is done first for performance reasons. |
I added 3 benchmark functions. On my system there is no slowdown visible for the list of arrays case, but the asv runs are a bit noisy so the variation between main and this PR is typically smaller than the variations between different runs. @ngoldbaum Could you run the benchmarks independently? |
|
Here's what I see running the new benchmarks on my laptop: So on my machine, about 20% faster and any decrease in performance on the list-of-arrays case is less than 5%. Seems worth it to me! |
|
Thanks @eendebakpt! |
In this PR we improve the performance of
np.atleast_1dfor the single argument case (and slightly improve for the other cases).The
np.atleast_1dis used in many other methods as part of the input pre-processing (Github search for np.atleast_1d).Benchmark
Benchmark script