-
Notifications
You must be signed in to change notification settings - Fork 237
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
drop numpy dependency from Python code for cases without vectors #108
Comments
Hey @StrikerRUS! Thanks for creating this issue. Besides using UPD However I don't have strong arguments against using |
@izeigerman Thanks a lot for your prompt response!
Is
I guess ~8x speedup worth it!
Sure, but generated runtime Python module can be used far away from data science community 🙂 . |
Hey @StrikerRUS, sorry, didn't expect you to reply so quickly :) I've edited my previous message right when you posted your reply. I've read your post carefully one more time and came to a conclusion that what you're saying makes sense. |
Great research btw 👍 |
@izeigerman No problem! I'm sorry too: I read fast, type slowly and GitHub doesn't provide live updates for editions. 😃 |
According to this line, it seems that
numpy
is used as a default math library for runtime even when we do not operate with vectors.m2cgen/m2cgen/interpreters/python/interpreter.py
Lines 30 to 31 in 2475f3c
Let me describe two advantages of dropping
numpy
where it's possible.The first one is excess dependence. Even though
numpy
is a sort of "classic" dependence and there should be no problems with installing it, it requires additional manipulation from a user side. Also, there are some companies with very strict security policies, which prohibit using pip (conda, brew, and other package managers). So, I guess, for them raw Python may be preferable solution in cases where it's possible.The second one is speed.
numpy
is about efficient vector math, in other cases it only produces redundant computational cost. Consider the following example. Take this generated Python code from the repo, change return type fromnp.array
to simplelist
, replace the following things in script:numpy
->math
np.exp
->math.exp
np.power
->math.pow
Here what we get after removing
numpy
:And here are some timings:
Results seems to be identical:
Please share your thoughts about this refactoring.
The text was updated successfully, but these errors were encountered: