-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Cannot inherit csr_matrix properly #5520
Comments
The issue is that sparse matrix classes take their Unfortunately, this isn't particularly easy to work around. I'd recommend not subclassing for your application, but perhaps keeping the graph as an instance variable in your search class. |
Also note that this sort of question is better suited for StackOverflow, where many more eyes will see it. I'll leave the issue open for now because I'm wondering if the difficulty of subclassing is a bug or not. |
thanks :) |
I think these classes simply aren't designed for subclassing by users. It can be done, but probably never a good idea. |
just a thought: (I'm Not going to subclass sparse matrices to replace dot by element wise multiplication. :) |
For the particular problem, I guess you could override |
@matthew-brett you'd have to do some hackery with a no-op setter method, because I'm coming around to the idea of a refactor, in which the format string is set explicitly (probably as a read-only property) for each class. The "first three characters of the class name" approach is a little too magic for my tastes. Does anyone remember why it was designed that way originally? |
So, the quick solution is to replace the subclass name to something like |
@perimosocordiae - it sounds like a refactor could solve this particular problem without causing compatibility problems - is that right? |
That's the idea. I'll open a PR soon. |
Refer to issue scipy#5520 for discussion.
The PR seems fine, but I think we should explicitly document that subclassing is not recommended/supported. It's quite hard to not break custom subclasses by accident, and from experience with ndarray I think we know that subclassing is rarely the best option. |
I agree that a bit of a warning in the docs is a good idea. Where would be best for that sort of thing? |
fixed in gh-5530 |
Refer to issue scipy#5520 for discussion.
Hi, I found csr_matrix data structure is quite suitable for doing Depth First Search and Beadth First Search, so I tried to inherit
csr_matrix
to make a newsgraph
class.But I could not construct a object with this class.
I got the following error:
Could u help to inherit
csr_matrix
properlyThe text was updated successfully, but these errors were encountered: