Skip to content
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

FIX: Enforce sub-matrix shape to all-zero columns being dropped #104

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release history:

## v1.1.1

### Internal

- FIX: Prevent Scipy from dropping columns that are all zero for sub-matrices

## v1.1.0

Add new function to select top-n from blocks of a sparse matrix matmul.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"

[project]
name = "sparse_dot_topn"
version = "1.1.0"
version = "1.1.1"
description = "This package boosts a sparse matrix multiplication followed by selecting the top-n multiplication"
readme = "README.md"
requires-python = ">=3.8"
Expand Down
13 changes: 5 additions & 8 deletions src/sparse_dot_topn/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,18 +324,15 @@ def zip_sp_matmul_topn(top_n: int, C_mats: list[csr_matrix]) -> csr_matrix:
indptr.append(C.indptr)
indices.append(C.indices)

ncols = np.asarray(ncols, int)
total_cols = ncols.sum()
if not np.all(np.diff(_nrows) == 0):
msg = "Each `C` in `C_mats` should have the same number of rows."
raise ValueError(msg)

return csr_matrix(
_core.zip_sp_matmul_topn(
top_n=top_n,
Z_max_nnz=nrows * top_n,
nrows=nrows,
B_ncols=np.asarray(ncols, int),
data=data,
indptr=indptr,
indices=indices,
)
top_n=top_n, Z_max_nnz=nrows * top_n, nrows=nrows, B_ncols=ncols, data=data, indptr=indptr, indices=indices
),
shape=(nrows, total_cols),
)
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

@pytest.fixture(scope="package")
def rng():
return np.random.Generator(np.random.PCG64DXSM(1483336117))
return np.random.Generator(np.random.PCG64DXSM(1481236117))
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def test_stack_zip_sp_matmul_topn(rng, dtype):
C_ref = sp_matmul_topn(A, B.T, top_n=10, threshold=0.01, sort=True)

# zipped C-matrix
As = [A[i*200:(i+1)*200] for i in range(5)] # names-to-match split
As = [A[i * 200 : (i + 1) * 200] for i in range(5)] # names-to-match split
Bs = [B[:100], B[100:300], B[300:]] # GT split

Cs = [[sp_matmul_topn(Aj, Bi.T, top_n=10, threshold=0.01, sort=True) for Bi in Bs] for Aj in As]
Expand Down
Loading