Skip to content

Add broadcasting and slicing using a lazy view structure#50

Open
trulsf wants to merge 15 commits into
mainfrom
tf/view
Open

Add broadcasting and slicing using a lazy view structure#50
trulsf wants to merge 15 commits into
mainfrom
tf/view

Conversation

@trulsf

@trulsf trulsf commented May 23, 2026

Copy link
Copy Markdown
Member

My apologies for a too large PR, but I got a bit carried away :)

The purpose of this PR is two-fold 1) Broadcasting support 2) A more unified approach when slicing an AbstractSparseArray.

There is still some open issues to discuss, both on naming and preferred ergonomics. I have supported old syntax, but have also added a new slice() function that provides the same syntax as doing it directly when indexing.

I will follow up this PR with an updates to benchmarks and documentation (depending upon where it goes).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a unified, lazy slicing/view mechanism for AbstractSparseArray and introduces broadcast support that materializes results as SparseArray, aiming to improve ergonomics and consistency when indexing/slicing sparse containers (including JuMP-backed IndexedVarArray).

Changes:

  • Introduces SparseArraySlice and a slice(sa, mask...) API, and updates getindex selection logic to return lazy slices for non-exact selectors.
  • Adds broadcasting support for AbstractSparseArray via a custom BroadcastStyle, producing SparseArray results.
  • Extends IndexedVarArray selection with a cache cutoff knob (set_cache_cutoff!) and integrates slice key-projection helpers into cached selection.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
test/testdata.jl Adds a small SparseArray fixture used by new slice/broadcast tests.
test/runtests.jl Adds coverage for SparseArraySlice behavior and broadcasting across SparseArray, slices, and IndexedVarArray.
src/SparseVariables.jl Wires in new slice.jl/broadcast.jl and exports new APIs/types.
src/sparsearray.jl Introduces _keytype interface and a generic haskey for AbstractSparseArray.
src/slice.jl Implements SparseArraySlice, key projection/reconstruction, and core slice behaviors.
src/indexedarray.jl Adds _keytype for IndexedVarArray, cache cutoff configuration, and slice-specific optimizations (cached key selection + efficient JuMP sum).
src/dictionaries.jl Refactors index classification (isfixed) and routes non-lookup indexing through _make_slice.
src/broadcast.jl Implements broadcast style, key compatibility checks, and materialization into SparseArray.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/dictionaries.jl
Comment thread src/dictionaries.jl
Comment on lines 228 to +229
isfixed(::Type{T} where {T<:Function}) = false
isfixed(::Type{T} where {T<:UnitRange}) = false
iscolon(t) = false
iscolon(::Type{T} where {T<:Colon}) = true
isfixed(::Type{T} where {T<:AbstractRange}) = false
Comment thread src/slice.jl Outdated
Comment thread src/broadcast.jl
Comment thread src/slice.jl Outdated
Comment thread src/slice.jl Outdated
Comment thread src/slice.jl
return haskey(_data(v.parent), _reconstruct_key(v.mask, free_key, T))
end

Base.length(v::SparseArraySlice) = length(_view_matching_keys(v))
Comment thread src/indexedarray.jl Outdated
@codecov-commenter

codecov-commenter commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.58824% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/broadcast.jl 82.50% 7 Missing ⚠️
src/slice.jl 94.17% 6 Missing ⚠️
src/sparsearray.jl 60.00% 2 Missing ⚠️
src/indexedarray.jl 94.44% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/SparseVariables.jl 100.00% <100.00%> (ø)
src/dictionaries.jl 81.73% <100.00%> (-3.75%) ⬇️
src/indexedarray.jl 97.75% <94.44%> (+7.27%) ⬆️
src/sparsearray.jl 79.62% <60.00%> (-2.01%) ⬇️
src/slice.jl 94.17% <94.17%> (ø)
src/broadcast.jl 82.50% <82.50%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants