-
Notifications
You must be signed in to change notification settings - Fork 285
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
ENH: Use views in set_id_type_array_py #664
Conversation
Codecov Report
@@ Coverage Diff @@
## master #664 +/- ##
==========================================
+ Coverage 50.42% 50.43% +<.01%
==========================================
Files 257 257
Lines 23370 23371 +1
Branches 3187 3186 -1
==========================================
+ Hits 11785 11786 +1
Misses 10828 10828
Partials 757 757
Continue to review full report at Codecov.
|
Ahh yes, this is very nice! This tells me nicely that I should not benchmark stuff late in the night with little sleep. Since the compilation is now optional anyway it should be OK to just leave it as it is. My original benchmarks were very different and did the right thing, this was something I ran last night. Thank you for the extra pair of eyes and a nicer implementation. |
But the call time will correspondingly shrink when the array size gets smaller. Will this actually affect real-world use cases? I wonder if at this point there is extra need-to-compile induced complexity here without any real-world benefit for users. |
The issue is not for smaller data but for larger data where a 50% reduction means more time taken. It does affect "real" world use cases with a large number of cells. They are not for the majority of the casual users but for actual cases with larger data. So given that there is a small increase in performance and that everything works, I think this is fine. There is also the possibility of other code (at Enthought for example) where this may be used and I don't want to change that. |
FWIW I think for larger arrays the performance difference should
(asymptotically) disappear.
… |
It doesn't on my machine here are the numbers on my machine, showing that when N is about a million or more it is about 60% slower. Here is the code from a notebook:
|
Ahh, so it is. Yet another lesson for me about not making (bad) assumptions about optimization! |
No worries, the |
Using this snippet (modified to properly set
empty(..., int)
so the C works properly):on
master
I get roughly ~2x slower:On this PR (which only uses views which do not copy the actual data / are for the most part free) I get only ~25% slower:
So very close in speed. This makes me think compiling might not ever be worth the hassle.
FWIW in a previous version of this (@prabhuramachandran your original snippet) there was
b = np.empty(n*(cs+1))
without specifying the type asint
. The Python code at least gave the correct/expected output (integers stored in thefloat
arrayb
) whereas the C code gave garbage. But I doubt this is really done / useful in practice. There should maybe also be anassert
statement about the dtype ofout_array
at some point.