From 47a3ab929382edfbc618e30b02b44606b9196ec1 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 10 Mar 2025 22:50:33 -0400 Subject: [PATCH 1/2] Upgrade to DerivableInterfaces v0.4 --- Project.toml | 4 +-- src/abstractblocksparsearray/cat.jl | 7 ++--- .../wrappedabstractblocksparsearray.jl | 7 +++-- .../blocksparsearrayinterface.jl | 8 +++--- src/blocksparsearrayinterface/cat.jl | 26 ++++++++----------- .../getunstoredblock.jl | 2 +- test/Project.toml | 1 + 7 files changed, 25 insertions(+), 30 deletions(-) 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 diff --git a/test/Project.toml b/test/Project.toml index 7cc17c05..5c72e7a0 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -4,6 +4,7 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" BlockSparseArrays = "2c9a651f-6452-4ace-a6ac-809f4280fbb4" +DerivableInterfaces = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f" DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527" GradedUnitRanges = "e2de450a-8a67-46c7-b59c-01d5a3d041c5" From cc3df883e03502080ba3c32bfa23b5c26283798b Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Tue, 11 Mar 2025 22:40:36 -0400 Subject: [PATCH 2/2] Delete stale test dep --- test/Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Project.toml b/test/Project.toml index 5c72e7a0..7cc17c05 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -4,7 +4,6 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" BlockSparseArrays = "2c9a651f-6452-4ace-a6ac-809f4280fbb4" -DerivableInterfaces = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f" DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527" GradedUnitRanges = "e2de450a-8a67-46c7-b59c-01d5a3d041c5"