diff --git a/Project.toml b/Project.toml index ebe5308a..e4067b1f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BlockSparseArrays" uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4" authors = ["ITensor developers and contributors"] -version = "0.3.5" +version = "0.3.6" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" @@ -33,7 +33,7 @@ Adapt = "4.1.1" Aqua = "0.8.9" ArrayLayouts = "1.10.4" BlockArrays = "1.2.0" -DerivableInterfaces = "0.3.8" +DerivableInterfaces = "0.4" DiagonalArrays = "0.3" Dictionaries = "0.4.3" FillArrays = "1.13.0" diff --git a/src/abstractblocksparsearray/cat.jl b/src/abstractblocksparsearray/cat.jl index 66626c9f..cdefdcf9 100644 --- a/src/abstractblocksparsearray/cat.jl +++ b/src/abstractblocksparsearray/cat.jl @@ -1,9 +1,6 @@ using DerivableInterfaces: @interface, interface +using DerivableInterfaces.Concatenate: concatenate function Base._cat(dims, as::AnyAbstractBlockSparseArray...) - # TODO: Call `DerivableInterfaces.cat_along(dims, as...)` instead, - # for better inferability. See: - # https://github.com/ITensor/DerivableInterfaces.jl/pull/13 - # https://github.com/ITensor/DerivableInterfaces.jl/pull/17 - return @interface interface(as...) cat(as...; dims) + return concatenate(dims, as...) end diff --git a/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl b/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl index 29d38e51..0e577f17 100644 --- a/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl +++ b/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl @@ -1,5 +1,5 @@ using Adapt: Adapt, WrappedArray, adapt -using ArrayLayouts: zero! +using ArrayLayouts: ArrayLayouts using BlockArrays: BlockArrays, AbstractBlockVector, @@ -9,7 +9,7 @@ using BlockArrays: blockedrange, mortar, unblock -using DerivableInterfaces: DerivableInterfaces, @interface, DefaultArrayInterface +using DerivableInterfaces: DerivableInterfaces, @interface, DefaultArrayInterface, zero! using GPUArraysCore: @allowscalar using SplitApplyCombine: groupcount using TypeParameterAccessors: similartype @@ -154,9 +154,8 @@ function Base.setindex!(a::AnyAbstractBlockSparseArray{<:Any,1}, value, I::Block return a end -# TODO: Use `@derive`. function ArrayLayouts.zero!(a::AnyAbstractBlockSparseArray) - return @interface interface(a) zero!(a) + return zero!(a) end # TODO: Use `@derive`. diff --git a/src/blocksparsearrayinterface/blocksparsearrayinterface.jl b/src/blocksparsearrayinterface/blocksparsearrayinterface.jl index 17c54c7f..e258af84 100644 --- a/src/blocksparsearrayinterface/blocksparsearrayinterface.jl +++ b/src/blocksparsearrayinterface/blocksparsearrayinterface.jl @@ -1,4 +1,4 @@ -using ArrayLayouts: ArrayLayouts, zero! +using ArrayLayouts: ArrayLayouts using BlockArrays: BlockArrays, AbstractBlockVector, @@ -16,7 +16,7 @@ using BlockArrays: blocklength, blocks, findblockindex -using DerivableInterfaces: DerivableInterfaces, @interface, DefaultArrayInterface +using DerivableInterfaces: DerivableInterfaces, @interface, DefaultArrayInterface, zero! using LinearAlgebra: Adjoint, Transpose using SparseArraysBase: AbstractSparseArrayInterface, @@ -266,7 +266,9 @@ end return a end -@interface ::AbstractBlockSparseArrayInterface function ArrayLayouts.zero!(a::AbstractArray) +@interface ::AbstractBlockSparseArrayInterface function DerivableInterfaces.zero!( + a::AbstractArray +) # This will try to empty the storage if possible. zero!(blocks(a)) return a diff --git a/src/blocksparsearrayinterface/cat.jl b/src/blocksparsearrayinterface/cat.jl index 71ec2e7f..2c0178a6 100644 --- a/src/blocksparsearrayinterface/cat.jl +++ b/src/blocksparsearrayinterface/cat.jl @@ -1,18 +1,14 @@ -using BlockArrays: AbstractBlockedUnitRange, blockedrange, blocklengths -using DerivableInterfaces: DerivableInterfaces, @interface, cat! -using SparseArraysBase: SparseArraysBase +using BlockArrays: blocks +using DerivableInterfaces.Concatenate: Concatenated, cat! -# TODO: Maybe move to `DerivableInterfacesBlockArraysExt`. -# TODO: Handle dual graded unit ranges, for example in a new `SparseArraysBaseGradedUnitRangesExt`. -function DerivableInterfaces.axis_cat( - a1::AbstractBlockedUnitRange, a2::AbstractBlockedUnitRange +function Base.copyto!( + dest::AbstractArray, concat::Concatenated{<:BlockSparseArrayInterface} ) - return blockedrange(vcat(blocklengths(a1), blocklengths(a2))) -end - -@interface ::AbstractBlockSparseArrayInterface function DerivableInterfaces.cat!( - a_dest::AbstractArray, as::AbstractArray...; dims -) - cat!(blocks(a_dest), blocks.(as)...; dims) - return a_dest + # TODO: This assumes the destination blocking is commensurate with + # the blocking of the sources, for example because it was constructed + # based on the input arguments. Maybe check that explicitly. + # This should mostly just get called from `cat` anyway and not get + # called explicitly. + cat!(blocks(dest), blocks.(concat.args)...; dims=concat.dims) + return dest end diff --git a/src/blocksparsearrayinterface/getunstoredblock.jl b/src/blocksparsearrayinterface/getunstoredblock.jl index db9267e5..43b58c02 100644 --- a/src/blocksparsearrayinterface/getunstoredblock.jl +++ b/src/blocksparsearrayinterface/getunstoredblock.jl @@ -1,5 +1,5 @@ -using ArrayLayouts: zero! using BlockArrays: Block +using DerivableInterfaces: zero! struct GetUnstoredBlock{Axes} axes::Axes