From 1ffcc26fefdada87ccc8528940a70dbd71f07190 Mon Sep 17 00:00:00 2001 From: Paola Malsot Date: Mon, 20 Oct 2025 13:45:08 +0300 Subject: [PATCH 1/6] test: test_transpose_matvec (fails without fix) --- tests/test_transpose_matvec.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/test_transpose_matvec.py diff --git a/tests/test_transpose_matvec.py b/tests/test_transpose_matvec.py new file mode 100644 index 00000000..ef8b3b06 --- /dev/null +++ b/tests/test_transpose_matvec.py @@ -0,0 +1,24 @@ +import narwhals as nw +import numpy as np +import pandas as pd + +import tabmat as tm + + +def test_transpose_matvec_does_not_crash(): + # With high n_categories CategoricalMatrix.indices is read-only. + # As a result, transpose_matvec method crashed with "buffer + # source array is read-only". + + n = 797_586 + n_categories = 58_059 + categories = [f"cat[{i}]" for i in range(n_categories)] + indices = np.linspace(0, n_categories - 1, n).round().astype(int) + cat_vec = pd.Series(pd.Categorical.from_codes(indices, categories=categories)) + cat_vec_nw = nw.from_native(cat_vec, allow_series=True) + weights = np.ones(n) + cat_matrix_tm = tm.CategoricalMatrix(cat_vec_nw) + + result = cat_matrix_tm.transpose_matvec(weights) + + assert result is not None From d608d503920ba3f1c3554e79660934b79dc33492 Mon Sep 17 00:00:00 2001 From: Jan Tilly Date: Wed, 22 Oct 2025 14:18:29 +0200 Subject: [PATCH 2/6] Use const int and do nothing else. --- src/tabmat/ext/cat_split_helpers-tmpl.cpp | 2 +- src/tabmat/ext/categorical.pyx | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tabmat/ext/cat_split_helpers-tmpl.cpp b/src/tabmat/ext/cat_split_helpers-tmpl.cpp index df7a21c6..af5793cc 100644 --- a/src/tabmat/ext/cat_split_helpers-tmpl.cpp +++ b/src/tabmat/ext/cat_split_helpers-tmpl.cpp @@ -5,7 +5,7 @@ template void _transpose_matvec_${type}( Int n_rows, - Int* indices, + const Int* indices, F* other, F* res, Int res_size diff --git a/src/tabmat/ext/categorical.pyx b/src/tabmat/ext/categorical.pyx index be97844b..5852fc0e 100644 --- a/src/tabmat/ext/categorical.pyx +++ b/src/tabmat/ext/categorical.pyx @@ -16,12 +16,12 @@ ctypedef fused win_numeric: long long cdef extern from "cat_split_helpers.cpp": - void _transpose_matvec_all_rows_fast[Int, F](Int, Int*, F*, F*, Int) - void _transpose_matvec_all_rows_complex[Int, F](Int, Int*, F*, F*, Int, bool) + void _transpose_matvec_all_rows_fast[Int, F](Int, const int*, F*, F*, Int) + void _transpose_matvec_all_rows_complex[Int, F](Int, const int*, F*, F*, Int, bool) def transpose_matvec_fast( - int[:] indices, + const int[:] indices, floating[:] other, int n_cols, dtype, @@ -68,7 +68,7 @@ def transpose_matvec_fast( def transpose_matvec_complex( - int[:] indices, + const int[:] indices, floating[:] other, int n_cols, dtype, From dc1cb71ced09415d5c935f08675940d1bf0419d2 Mon Sep 17 00:00:00 2001 From: Jan Tilly Date: Wed, 22 Oct 2025 14:21:51 +0200 Subject: [PATCH 3/6] Run CI. --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1160ca90..c68a4022 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,10 +7,6 @@ on: # In addition to pull requests, we want to run CI for pushes # to the main branch and tags. push: - branches: - - "main" - tags: - - "*" jobs: pre-commit-checks: From 78a026b4b946758e47d1f9ea5c0041c165fe1958 Mon Sep 17 00:00:00 2001 From: Paola Malsot Date: Mon, 27 Oct 2025 11:46:52 +0100 Subject: [PATCH 4/6] add CHANGELOG.rst --- CHANGELOG.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index fe9399a8..4e96f6b8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,15 @@ Changelog ========= + +4.1.4 - 2025-10-27 +------------------ + +**Bug fix:** + +- Fixed :meth:`CategoricalMatrix.transpose_matvec` to operate on read-only buffers as well. + + 4.1.3 - 2025-10-14 ------------------ From 50365d13d1fa848a51308c0a96854c963e976c48 Mon Sep 17 00:00:00 2001 From: Paola Malsot Date: Mon, 27 Oct 2025 13:36:09 +0100 Subject: [PATCH 5/6] Revert "Run CI." This reverts commit dc1cb71ced09415d5c935f08675940d1bf0419d2. --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c68a4022..1160ca90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,10 @@ on: # In addition to pull requests, we want to run CI for pushes # to the main branch and tags. push: + branches: + - "main" + tags: + - "*" jobs: pre-commit-checks: From e7a288e70defbe083a040856c4345b2608b646ca Mon Sep 17 00:00:00 2001 From: Jan Tilly Date: Wed, 12 Nov 2025 11:40:17 +0100 Subject: [PATCH 6/6] Update CHANGELOG.rst --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4e96f6b8..a231d2e2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,7 +8,7 @@ Changelog ========= -4.1.4 - 2025-10-27 +4.1.4 - 2025-11-12 ------------------ **Bug fix:**