-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
MAINT: sparse: add lazy loading for csgraph and linalg #22815
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks like what we want.
csgraph will no longer be imported at the time sparse is imported; only when
sparse.csgraph` is accessed.linalg
will be auto-imported when accessed (it currently is not imported with sparse)
I'm not sure about the details of tach.toml
. Why does linalg
stay in the "depends_on" for scipy.sparse
? Does something in sparse
depends on linalg
? If so does linalg
get imported when importing sparse
when using "tach"?
For whatever reason |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a nice way to import matrix_power and allow lazy loading. Thanks!
This looks good to me!
I would suggest reverting that change. It is true that One could argue that keeping track of import-time dependencies only is more useful than dependencies in general, but I think at this stage it is helpful to be explicit about potential runtime gotchas. EDIT: tach itself is not just about import-time deps (hence the initial failures until you tweaked the style), but rather modularity more broadly, so I think that change is more of a circumvention of tach's detection than a sort of 'fix' |
I'm not sure I entirely agree. If we also use also track runtime dependencies then it looses its "sharpness" as I could add |
Sure, but I could imagine a similar issue about runtime instead, so I don't think either way is favoured. Hence I think explicit rather than implicit is better.
There should be other ways to achieve this (or better) sharpness. Reading the docs, it looks like we could add something like: [[interfaces]]
expose = ["matrix_power"]
from = ["scipy.sparse.linalg"]
visibility = ["scipy.sparse"]
exclusive = true I'm running into some errors when trying to get recent versions of |
scipy/sparse/_matrix.py
Outdated
import scipy | ||
return scipy.sparse.linalg.matrix_power(self, power) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mean to block the PR as tach-bikeshedding is insignificant compared to the import performance improvement, but as another data-point, Ralf was against this pattern at #22412 (comment)
This reverts commit 196720d.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks Jake, and for the review Dan!
Reference issue
closes #22382
What does this implement/fix?
Adds lazy loading for the two submodules in order to speed up import times.
Additional information