Fix edge cases of csr_array#39
Merged
Merged
Conversation
A csr_array can have non-sparse zeros potentially.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves get_deviance by ensuring sparse data has no redundant or zero entries and by simplifying how expected counts (mu_ij_nn) are computed.
- Adds in-place deduplication and zero-elimination on the input CSR matrix.
- Updates
mu_ij_nncalculation to use 1D indexing on flattened row/column sums.
Comments suppressed due to low confidence (2)
parafac2/normalize.py:83
sum_duplicates()andeliminate_zeros()modify the input in place. If callers ofget_deviancerely on the original matrix, consider working on a copy or clearly document this side effect.
data.sum_duplicates()
parafac2/normalize.py:110
- If
n_iorpi_jare 2D arrays (e.g., numpy matrices), indexing with[row]/[col]could yield unexpected shapes. Ensure these sums are explicitly flattened (e.g., viaravel()orsqueeze()) so that elementwise multiplication produces a 1D array of scalars.
mu_ij_nn = n_i[row] * pi_j[col]
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #39 +/- ##
==========================================
- Coverage 91.87% 91.45% -0.43%
==========================================
Files 10 10
Lines 431 433 +2
==========================================
Hits 396 396
- Misses 35 37 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A csr_array can have non-sparse zeros potentially.