-
Notifications
You must be signed in to change notification settings - Fork 152
Use sparse structured methods where possible #1727
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
base: main
Are you sure you want to change the base?
Conversation
| def transpose(self): | ||
| raise NotImplementedError | ||
| return self.T |
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.
Do you want to add the mT property as well? Will make code that works with tensors more likely to work with sparse variables as well
|
Re: copy is identity function, we can make it return One thing with these Elemwise operations is that they box the sparse part like: In general I'm not a big fan of this eager implementation. I would rather do it as a rewrite: |
I don't like this. To me, the point of the structured ops is that you can keep everything sparse. I would write my program with dense Ops following You could object and say we shouldn't be forcing people to use the sparse version of every op, but that's how things current work. |
|
I don't think we're talking about the same thing. The way elemwise sparse operations are implemented is not a good first representation. Much like scan, it leaks irrelevant implementation details in a way that muddles the meaning of the computation. # this is roughly what the @structured decorator does
def log1p(x):
data, indices, indptr = csm_properties(x)
new_data = pt.log1p(data)
return sparse(new_data, indices, indptr)This is not a good first representation of sparse log1p. It's even worse for chains of operations. It's also backend specific, we would never try to write like that in the jax backend. What I was saying is: If we need this form we can introduce it later in the backends that need it (if at all). |
Description
For elemwise functions that are idempotent at 0 such that f(0) = 0, it is safe to always use a
structured_function, rather than converting back to dense.Such functions are
sinh,tanh,arcsin,arctan,arcsinh,deg2rad,rad2deg,expm1, andlog1p.I also removed the dense_override on
.transpose, which now callsself.T. I think this is fine for now, since we're only supporting sparse matrices, not general sparse arrays. Previously,sparse.Treturned a sparse, butsparse.transposereturned a dense, which is baffling.copyseems like another low-hanging fruit, but I'm leaving it for another time because it was slightly harder to reason about than the functions in this PR.Related Issue
Checklist
Type of change