Skip to content

CompatHelper: bump compat for SparseArraysBase to 0.6, (keep existing compat) #160

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

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BlockSparseArrays"
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.7.22"
version = "0.7.23"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down Expand Up @@ -40,7 +40,7 @@ LinearAlgebra = "1.10"
MacroTools = "0.5.13"
MapBroadcast = "0.1.5"
MatrixAlgebraKit = "0.2.2"
SparseArraysBase = "0.5"
SparseArraysBase = "0.7.1"
SplitApplyCombine = "1.2.3"
TensorAlgebra = "0.3.2"
Test = "1.10"
Expand Down
4 changes: 2 additions & 2 deletions src/blocksparsearray/blocksparsearray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using BlockArrays:
undef_blocks
using DerivableInterfaces: @interface
using Dictionaries: Dictionary
using SparseArraysBase: SparseArrayDOK
using SparseArraysBase: SparseArrayDOK, Unstored
using TypeParameterAccessors: similartype

"""
Expand All @@ -25,7 +25,7 @@ and should be imported from that package to use it as an input to this construct
function SparseArraysBase.SparseArrayDOK{T,N}(
::UndefBlocksInitializer, ax::Tuple{Vararg{AbstractUnitRange{<:Integer},N}}
) where {T,N}
return SparseArrayDOK{T,N}(undef, blocklength.(ax); getunstored=GetUnstoredBlock(ax))
return SparseArrayDOK{T,N}(undef, Unstored(ZeroBlocks{N,T}(ax)))
end
function SparseArraysBase.SparseArrayDOK{T,N}(
::UndefBlocksInitializer, ax::Vararg{AbstractUnitRange{<:Integer},N}
Expand Down
4 changes: 3 additions & 1 deletion src/blocksparsearrayinterface/blocksparsearrayinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ function SparseArraysBase.getunstoredindex(
_perm(a.array),
)
end
function SparseArraysBase.eachstoredindex(a::SparsePermutedDimsArrayBlocks)
function SparseArraysBase.eachstoredindex(
::IndexCartesian, a::SparsePermutedDimsArrayBlocks
)
return map(I -> _getindices(I, _perm(a.array)), eachstoredindex(blocks(parent(a.array))))
end
## TODO: Define `storedvalues` instead.
Expand Down
40 changes: 21 additions & 19 deletions src/blocksparsearrayinterface/getunstoredblock.jl
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
using BlockArrays: Block
using DerivableInterfaces: zero!

struct GetUnstoredBlock{Axes}
axes::Axes
struct ZeroBlocks{
N,A<:AbstractArray{<:Any,N},ParentAxes<:Tuple{Vararg{AbstractUnitRange{<:Integer},N}}
} <: AbstractArray{A,N}
parentaxes::ParentAxes
end
function ZeroBlocks{N,A}(
ax::Ax
) where {N,A<:AbstractArray{<:Any,N},Ax<:Tuple{Vararg{AbstractUnitRange{<:Integer},N}}}
return ZeroBlocks{N,A,Ax}(ax)
end
Base.size(a::ZeroBlocks) = map(blocklength, a.parentaxes)

function Base.AbstractArray{A}(a::ZeroBlocks{N}) where {N,A}
return ZeroBlocks{N,A}(a.parentaxes)
end

@inline function (f::GetUnstoredBlock)(
::Type{<:AbstractArray{A,N}}, I::Vararg{Int,N}
) where {A,N}
@inline function Base.getindex(a::ZeroBlocks{N,A}, I::Vararg{Int,N}) where {N,A}
# TODO: Use `BlockArrays.eachblockaxes`.
ax = ntuple(N) do d
return only(axes(f.axes[d][Block(I[d])]))
return only(axes(a.parentaxes[d][Block(I[d])]))
end
!isconcretetype(A) && return zero!(similar(Array{eltype(A),N}, ax))
return zero!(similar(A, ax))
end
@inline function (f::GetUnstoredBlock)(
a::AbstractArray{<:Any,N}, I::Vararg{Int,N}
) where {N}
return f(typeof(a), I...)
end
# TODO: Use `Base.to_indices`.
@inline function (f::GetUnstoredBlock)(
a::AbstractArray{<:Any,N}, I::CartesianIndex{N}
) where {N}
return f(a, Tuple(I)...)
@inline function Base.getindex(a::ZeroBlocks{N,A}, I::CartesianIndex{N}) where {N,A}
return a[Tuple(I)...]
end

# TODO: this is a hack and is also type-unstable
using LinearAlgebra: Diagonal
using TypeParameterAccessors: similartype
function (f::GetUnstoredBlock)(
::Type{<:AbstractMatrix{<:Diagonal{<:Any,V}}}, I::Vararg{Int,2}
) where {V}
function Base.getindex(a::ZeroBlocks{2,A}, I::Vararg{Int,2}) where {V,A<:Diagonal{<:Any,V}}
ax = ntuple(2) do d
return only(axes(f.axes[d][Block(I[d])]))
return only(axes(a.parentaxes[d][Block(I[d])]))
end
if allequal(I)
return Diagonal(zero!(similar(V, first(ax))))
Expand Down
3 changes: 2 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ DerivableInterfaces = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f"
DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77"
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MatrixAlgebraKit = "6c742aac-3347-4629-af66-fc926824e5e4"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -34,7 +35,7 @@ LinearAlgebra = "1"
MatrixAlgebraKit = "0.2.5"
Random = "1"
SafeTestsets = "0.1"
SparseArraysBase = "0.5.11"
SparseArraysBase = "0.7"
StableRNGs = "1"
Suppressor = "0.2"
TensorAlgebra = "0.3.2"
Expand Down
Loading