Visitar URL original
Fix sparse backend: SVD-init PARAFAC and clearer import error by aarmey · Pull Request #664 · tensorly/tensorly · GitHub
Skip to content

Fix sparse backend: SVD-init PARAFAC and clearer import error - #664

Open
aarmey wants to merge 1 commit into
mainfrom
investigate-446
Open

aarmey wants to merge 1 commit into
mainfrom
investigate-446

Conversation

@aarmey

@aarmey aarmey commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Related to #446.

  • Add argmax (with axis) to the numpy.sparse backend, returning dense indices. Previously parafac(..., init="svd") on a sparse tensor failed with TypeError: Backend.argmax() got an unexpected keyword argument 'axis' in svd_flip.
  • Add index_update for COO arrays (immutable), needed by the SVD init after the above.
  • Validate that the imported sparse module provides the functions the backend registers, and has __version__. A wrong or shadowing sparse module now raises a clear ImportError instead of a bare AttributeError (the symptom reported in parafac decomposition when registering sparse backend #446).
  • Tests for SVD-init sparse PARAFAC and sparse argmax.

pytest tensorly/contrib/sparse tensorly/tenalg: 291 passed (sparse 0.19.2).

SVD-initialized PARAFAC on sparse tensors failed because the sparse backend
lacked argmax (axis) and index_update. Also validate that the imported
`sparse` module provides the required functions so a wrong/shadowing module
gives a clear ImportError instead of a bare AttributeError.
@aarmey aarmey closed this Oct 11, 2026
@aarmey aarmey reopened this Oct 11, 2026
@JeanKossaifi

Copy link
Copy Markdown
Member

Looks good to me, thank you!

@antonsoo antonsoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 85fd172 on CPU with PyData sparse 0.19.2: pytest tensorly/contrib/sparse tensorly/tenalg -q gives 291 passed.

Also checked reconstructed values beyond the new shape test: six sparse rank-1/2/3 tensors in float32/float64 match dense PARAFAC, and rank-4 PARAFAC of the Zachary karate-club adjacency matrix matches NumPy's truncated SVD (residual norm 7.346444141705379 versus 7.346444141705378). All seven decompositions fail on the parent a4f8954 with the missing argmax(axis=...) error. Twelve argmax comparisons covering implicit zeros, ties and negative axes also match NumPy on this head. No issue found in these paths.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants