Repository navigation
Conversation
✅ Deploy Preview for docsite-preview canceled.
|
…rray Use the scalar width to count triplets and check the input dtype before reading the buffer. Cover scalar, vector and matrix ndarrays on CPU. Fixes taichi-dev#8501.
junwha
force-pushed
the
fix-bof-sparse-matrix
branch
from
November 29, 2026 17:05
c1fb92a to
d79c5f0
Compare
This branch has not been deployed
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.
Fixes #8501.
build_from_ndarraydivided the buffer size in bytes by three, which could make it read past the end of the array. Count one triplet for every three scalars and check that the array and matrix have the same scalar dtype before reading.I ran
tests/python/test_sparse_matrix.pyon CPU. All 57 CPU tests passed, including the new regression cases. The two CUDA tests were skipped.Note
Low Risk
Localized fix to sparse-matrix construction from ndarrays with added validation and expanded tests; no auth or infrastructure changes.
Overview
Fixes incorrect
num_tripletscalculation inmake_sparse_matrix_from_ndarray, which previously usedndarray.get_nelement() * ndarray.get_element_size() / 3and broke when each ndarray “element” is a vector or matrix (multiple scalars per entry). The code now derives scalars per element from the scalar dtype size and computesnum_tripletsasnelement * scalars_per_element / 3.Adds a dtype guard so building fails with a clear error when the sparse matrix scalar type and the ndarray’s scalar type differ. The triplet-build loop index type is updated to
size_tto matchnum_triplets.Tests for
build_from_ndarraynow cover scalar, vector, and matrix element layouts viafrom_numpy, assert concrete off-diagonal values, fix the test name typo, and add a dtype mismatch case.Reviewed by Cursor Bugbot for commit d79c5f0. Bugbot is set up for automated code reviews on this repo. Configure here.