Skip to content
Open
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
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------

Expand Down
2 changes: 1 addition & 1 deletion src/tabmat/ext/cat_split_helpers-tmpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
template <typename Int, typename F>
void _transpose_matvec_${type}(
Int n_rows,
Int* indices,
const Int* indices,
F* other,
F* res,
Int res_size
Expand Down
8 changes: 4 additions & 4 deletions src/tabmat/ext/categorical.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -68,7 +68,7 @@ def transpose_matvec_fast(


def transpose_matvec_complex(
int[:] indices,
const int[:] indices,
floating[:] other,
int n_cols,
dtype,
Expand Down
24 changes: 24 additions & 0 deletions tests/test_transpose_matvec.py
Original file line number Diff line number Diff line change
@@ -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
Loading