Skip to content

Upgrade to DerivableInterfaces v0.4 #84

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 2 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all 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.3.5"
version = "0.3.6"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down Expand Up @@ -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"
Expand Down
7 changes: 2 additions & 5 deletions src/abstractblocksparsearray/cat.jl
Original file line number Diff line number Diff line change
@@ -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...)

Check warning on line 5 in src/abstractblocksparsearray/cat.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractblocksparsearray/cat.jl#L5

Added line #L5 was not covered by tests
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Adapt: Adapt, WrappedArray, adapt
using ArrayLayouts: zero!
using ArrayLayouts: ArrayLayouts
using BlockArrays:
BlockArrays,
AbstractBlockVector,
Expand All @@ -9,7 +9,7 @@
blockedrange,
mortar,
unblock
using DerivableInterfaces: DerivableInterfaces, @interface, DefaultArrayInterface
using DerivableInterfaces: DerivableInterfaces, @interface, DefaultArrayInterface, zero!
using GPUArraysCore: @allowscalar
using SplitApplyCombine: groupcount
using TypeParameterAccessors: similartype
Expand Down Expand Up @@ -154,9 +154,8 @@
return a
end

# TODO: Use `@derive`.
function ArrayLayouts.zero!(a::AnyAbstractBlockSparseArray)
return @interface interface(a) zero!(a)
return zero!(a)

Check warning on line 158 in src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl#L158

Added line #L158 was not covered by tests
end

# TODO: Use `@derive`.
Expand Down
8 changes: 5 additions & 3 deletions src/blocksparsearrayinterface/blocksparsearrayinterface.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ArrayLayouts: ArrayLayouts, zero!
using ArrayLayouts: ArrayLayouts
using BlockArrays:
BlockArrays,
AbstractBlockVector,
Expand All @@ -16,7 +16,7 @@
blocklength,
blocks,
findblockindex
using DerivableInterfaces: DerivableInterfaces, @interface, DefaultArrayInterface
using DerivableInterfaces: DerivableInterfaces, @interface, DefaultArrayInterface, zero!
using LinearAlgebra: Adjoint, Transpose
using SparseArraysBase:
AbstractSparseArrayInterface,
Expand Down Expand Up @@ -266,7 +266,9 @@
return a
end

@interface ::AbstractBlockSparseArrayInterface function ArrayLayouts.zero!(a::AbstractArray)
@interface ::AbstractBlockSparseArrayInterface function DerivableInterfaces.zero!(

Check warning on line 269 in src/blocksparsearrayinterface/blocksparsearrayinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/blocksparsearrayinterface/blocksparsearrayinterface.jl#L269

Added line #L269 was not covered by tests
a::AbstractArray
)
# This will try to empty the storage if possible.
zero!(blocks(a))
return a
Expand Down
26 changes: 11 additions & 15 deletions src/blocksparsearrayinterface/cat.jl
Original file line number Diff line number Diff line change
@@ -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!(

Check warning on line 4 in src/blocksparsearrayinterface/cat.jl

View check run for this annotation

Codecov / codecov/patch

src/blocksparsearrayinterface/cat.jl#L4

Added line #L4 was not covered by tests
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

Check warning on line 13 in src/blocksparsearrayinterface/cat.jl

View check run for this annotation

Codecov / codecov/patch

src/blocksparsearrayinterface/cat.jl#L12-L13

Added lines #L12 - L13 were not covered by tests
end
2 changes: 1 addition & 1 deletion src/blocksparsearrayinterface/getunstoredblock.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ArrayLayouts: zero!
using BlockArrays: Block
using DerivableInterfaces: zero!

struct GetUnstoredBlock{Axes}
axes::Axes
Expand Down
Loading