Skip to content

can_setindex must be false for CUSPARSE arrays#495

Merged
ChrisRackauckas merged 1 commit into
JuliaArrays:masterfrom
hexaeder:hw/cusparse-can-setindex
Jul 14, 2026
Merged

can_setindex must be false for CUSPARSE arrays#495
ChrisRackauckas merged 1 commit into
JuliaArrays:masterfrom
hexaeder:hw/cusparse-can-setindex

Conversation

@hexaeder

Copy link
Copy Markdown
Contributor

cuSPARSE arrays implement no setindex! at all, but can_setindex falls back to true
for them, so callers that guard mutation with it crash instead of taking their
non-mutating path:

julia> A = CuSparseMatrixCSC(sparse(Float64[1 0; 0 1]));

julia> ArrayInterface.can_setindex(A)   # should be false
true

julia> A[1, 2] = 1.0
ERROR: CanonicalIndexError: setindex! not defined for CuSparseMatrixCSC{Float64, Int32}

This declares can_setindex = false for the cuSPARSE types in the CUDA extension, with a
test in test/gpu/cuda.jl. The AMDGPU/Metal sparse types might need the same; I left them
alone as I can't test them.

CuSparseVector and the CuSparseMatrix formats implement no setindex! at all,
but can_setindex fell back to the `true` default for them, so callers guarding
mutation with it (e.g. NonlinearSolveBase's safe_similar) hit a
CanonicalIndexError instead of taking their non-mutating path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@hexaeder hexaeder force-pushed the hw/cusparse-can-setindex branch from e6274c6 to d1a1cc6 Compare July 14, 2026 06:33
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 59.89%. Comparing base (b51dc3b) to head (d1a1cc6).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
ext/ArrayInterfaceCUDAExt.jl 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #495      +/-   ##
==========================================
- Coverage   60.00%   59.89%   -0.11%     
==========================================
  Files          15       15              
  Lines         590      591       +1     
==========================================
  Hits          354      354              
- Misses        236      237       +1     

☔ View full report in Codecov by Harness.
📢 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.

@ChrisRackauckas ChrisRackauckas merged commit 3b48690 into JuliaArrays:master Jul 14, 2026
18 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants