-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
special-casing np.array(range(...)) #7233
Comments
Seems like the sort of thing that should be put on the mailing list. Did you already put it on there? If so, could we please have a link? |
Wouldn't it be better to fix sparse matrices or use arange in the first place? |
Sure, this fix can go into scipy.sparse, but it's obviously more generally applicable than just for sparse matrices. |
But that is what arange is for. What is the problem with arange? |
I think I'd be for not special-casing this. We're also removing the special case for |
Having said that, I don't think this optimization is worthwhile - it seems like optimization efforts would be better invested elsewhere |
I guess I may try my hand at implementing this at some point but feel free to close it for now... |
Thanks @anntzer |
Compare (on Python3 -- for Python2, read "xrange" instead of "range"):
Note that while iterating over a
range
is not very fast, it is still much better than the array creation:On one hand, special cases are awful. On the other hand, the
range
builtin is probably important enough to deserve a special case. Or not? (Feel free to close this issue if that's not going to happen.)(Real issue which prompted this suggestion: I was building sparse matrices using
scipy.sparse.csc_matrix
with some indices specified usingrange
, and that construction step turned out to take a significant portion of the time because of the calls tonp.array
).Cross-posted to the mailing list: https://mail.scipy.org/pipermail/numpy-discussion/2016-February/074960.html
The text was updated successfully, but these errors were encountered: