Skip to content

Fix edge cases of csr_array#39

Merged
aarmey merged 2 commits into
mainfrom
aarmey-patch-1
Jul 2, 2025
Merged

Fix edge cases of csr_array#39
aarmey merged 2 commits into
mainfrom
aarmey-patch-1

Conversation

@aarmey
Copy link
Copy Markdown
Member

@aarmey aarmey commented Jul 2, 2025

A csr_array can have non-sparse zeros potentially.

A csr_array can have non-sparse zeros potentially.
@aarmey aarmey requested a review from Copilot July 2, 2025 03:28
@aarmey aarmey self-assigned this Jul 2, 2025
@aarmey aarmey added the bug Something isn't working label Jul 2, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_nn calculation to use 1D indexing on flattened row/column sums.
Comments suppressed due to low confidence (2)

parafac2/normalize.py:83

  • sum_duplicates() and eliminate_zeros() modify the input in place. If callers of get_deviance rely on the original matrix, consider working on a copy or clearly document this side effect.
    data.sum_duplicates()

parafac2/normalize.py:110

  • If n_i or pi_j are 2D arrays (e.g., numpy matrices), indexing with [row]/[col] could yield unexpected shapes. Ensure these sums are explicitly flattened (e.g., via ravel() or squeeze()) so that elementwise multiplication produces a 1D array of scalars.
    mu_ij_nn = n_i[row] * pi_j[col]

Comment thread parafac2/normalize.py Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 2, 2025

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 91.45%. Comparing base (ccf708f) to head (8a3de9c).

Files with missing lines Patch % Lines
parafac2/normalize.py 0.00% 3 Missing ⚠️
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     
Flag Coverage Δ
unittests 91.45% <0.00%> (-0.43%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@aarmey aarmey merged commit 121c2e3 into main Jul 2, 2025
3 checks passed
@aarmey aarmey deleted the aarmey-patch-1 branch July 2, 2025 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants