Skip to content

Conversation

@jessegrabowski
Copy link
Member

@jessegrabowski jessegrabowski commented Nov 18, 2025

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, and log1p.

I also removed the dense_override on .transpose, which now calls self.T. I think this is fine for now, since we're only supporting sparse matrices, not general sparse arrays. Previously, sparse.T returned a sparse, but sparse.transpose returned a dense, which is baffling.

copy seems 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

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

Comment on lines 203 to +204
def transpose(self):
raise NotImplementedError
return self.T
Copy link
Member

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

@ricardoV94
Copy link
Member

ricardoV94 commented Nov 18, 2025

Re: copy is identity function, we can make it return ViewOp()(self).

One thing with these Elemwise operations is that they box the sparse part like: sparse.data -> f(data) -> sparse_again. If we have multiple Elemwise in succession they won't get fused. We may need a rewrite (not a blocker for this PR ofc).

In general I'm not a big fan of this eager implementation. I would rather do it as a rewrite: elemwise(x.todense()) -> trick used here. Again not a blocker, specially because I haven't thought about all the ramifications

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request sparse variables

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants