Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCEMENT] Define SparseArraysBase.isstored for block sparse arrays #26

Open
mtfishman opened this issue Jan 14, 2025 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@mtfishman
Copy link
Member

Currently:

julia> using BlockSparseArrays: BlockSparseArray

julia> using SparseArraysBase: isstored

julia> a = BlockSparseArray{Float64}([2, 2], [2, 2])
2×2-blocked 4×4 BlockSparseMatrix{Float64, Matrix{Float64}, SparseMatrixDOK{Matrix{Float64}, BlockSparseArrays.GetUnstoredBlock{Tuple{BlockedOneTo{Int64, Vector{Int64}}, BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockedOneTo{Int64, Vector{Int64}}, BlockedOneTo{Int64, Vector{Int64}}}}:
 .  .  │  .  .
 .  .  │  .  .
 ──────┼──────
 .  .  │  .  .
 .  .  │  .  .

julia> a[1, 2] = 12
12

julia> a
2×2-blocked 4×4 BlockSparseMatrix{Float64, Matrix{Float64}, SparseMatrixDOK{Matrix{Float64}, BlockSparseArrays.GetUnstoredBlock{Tuple{BlockedOneTo{Int64, Vector{Int64}}, BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockedOneTo{Int64, Vector{Int64}}, BlockedOneTo{Int64, Vector{Int64}}}}:
 0.0  12.0  │  .  .
 0.0   0.0  │  .  .
 ───────────┼──────
  .     .   │  .  .
  .     .   │  .  .

julia> isstored(a, 1, 1) # Correct
true

julia> isstored(a, 1, 4) # Should be false
true

and:

julia> isstored(a, Block(1, 1)) # Not defined
ERROR: MethodError: no method matching isstored(::BlockSparseMatrix{Float64, Matrix{…}, SparseMatrixDOK{…}, Tuple{…}}, ::Block{2, Int64})
The function `isstored` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  isstored(::AbstractArray, ::Int64...)
   @ SparseArraysBase none:0
  isstored(::AbstractArray, ::CartesianIndex)
   @ SparseArraysBase ~/.julia/packages/SparseArraysBase/9oYN7/src/abstractsparsearrayinterface.jl:58
  isstored(::BlockSparseArrays.SparsePermutedDimsArrayBlocks{var"#s16", N, BlockType, Array} where {var"#s16", BlockType<:AbstractArray{var"#s16", N}, Array<:(PermutedDimsArray{var"#s16", N})}, ::Int64...) where N
   @ BlockSparseArrays ~/.julia/dev/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl:253
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[18]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> isstored(a, Block(1), Block(1)) # Not defined
ERROR: MethodError: no method matching isstored(::BlockSparseMatrix{Float64, Matrix{…}, SparseMatrixDOK{…}, Tuple{…}}, ::Block{1, Int64}, ::Block{1, Int64})
The function `isstored` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  isstored(::AbstractArray, ::Int64...)
   @ SparseArraysBase none:0
  isstored(::AbstractArray, ::CartesianIndex)
   @ SparseArraysBase ~/.julia/packages/SparseArraysBase/9oYN7/src/abstractsparsearrayinterface.jl:58
  isstored(::BlockSparseArrays.SparsePermutedDimsArrayBlocks{var"#s16", N, BlockType, Array} where {var"#s16", BlockType<:AbstractArray{var"#s16", N}, Array<:(PermutedDimsArray{var"#s16", N})}, ::Int64...) where N
   @ BlockSparseArrays ~/.julia/dev/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl:253
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[19]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> isstored(a, Block(1, 1)[1, 1]) # Not defined
ERROR: MethodError: no method matching isstored(::BlockSparseMatrix{Float64, Matrix{…}, SparseMatrixDOK{…}, Tuple{…}}, ::BlockIndex{2, Tuple{…}, Tuple{…}})
The function `isstored` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  isstored(::AbstractArray, ::Int64...)
   @ SparseArraysBase none:0
  isstored(::AbstractArray, ::CartesianIndex)
   @ SparseArraysBase ~/.julia/packages/SparseArraysBase/9oYN7/src/abstractsparsearrayinterface.jl:58
  isstored(::BlockSparseArrays.SparsePermutedDimsArrayBlocks{var"#s16", N, BlockType, Array} where {var"#s16", BlockType<:AbstractArray{var"#s16", N}, Array<:(PermutedDimsArray{var"#s16", N})}, ::Int64...) where N
   @ BlockSparseArrays ~/.julia/dev/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl:253
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[21]:1
Some type information was truncated. Use `show(err)` to see complete types.

using:

julia> pkgversion(BlockSparseArrays)
v"0.2.5"

julia> pkgversion(SparseArraysBase)
v"0.2.6"

We could also consider defining isblockstored(a, 1, 1) == isstored(a, Block(1, 1)) though maybe the isstored interface is sufficient.

@mtfishman mtfishman added the enhancement New feature or request label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant