Skip to content

Commit 20a4018

Browse files
authored
Upgrade to DerivableInterfaces v0.4 (#84)
1 parent 04107cd commit 20a4018

File tree

6 files changed

+24
-30
lines changed

6 files changed

+24
-30
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BlockSparseArrays"
22
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.3.5"
4+
version = "0.3.6"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
@@ -33,7 +33,7 @@ Adapt = "4.1.1"
3333
Aqua = "0.8.9"
3434
ArrayLayouts = "1.10.4"
3535
BlockArrays = "1.2.0"
36-
DerivableInterfaces = "0.3.8"
36+
DerivableInterfaces = "0.4"
3737
DiagonalArrays = "0.3"
3838
Dictionaries = "0.4.3"
3939
FillArrays = "1.13.0"

src/abstractblocksparsearray/cat.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using DerivableInterfaces: @interface, interface
2+
using DerivableInterfaces.Concatenate: concatenate
23

34
function Base._cat(dims, as::AnyAbstractBlockSparseArray...)
4-
# TODO: Call `DerivableInterfaces.cat_along(dims, as...)` instead,
5-
# for better inferability. See:
6-
# https://github.com/ITensor/DerivableInterfaces.jl/pull/13
7-
# https://github.com/ITensor/DerivableInterfaces.jl/pull/17
8-
return @interface interface(as...) cat(as...; dims)
5+
return concatenate(dims, as...)
96
end

src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Adapt: Adapt, WrappedArray, adapt
2-
using ArrayLayouts: zero!
2+
using ArrayLayouts: ArrayLayouts
33
using BlockArrays:
44
BlockArrays,
55
AbstractBlockVector,
@@ -9,7 +9,7 @@ using BlockArrays:
99
blockedrange,
1010
mortar,
1111
unblock
12-
using DerivableInterfaces: DerivableInterfaces, @interface, DefaultArrayInterface
12+
using DerivableInterfaces: DerivableInterfaces, @interface, DefaultArrayInterface, zero!
1313
using GPUArraysCore: @allowscalar
1414
using SplitApplyCombine: groupcount
1515
using TypeParameterAccessors: similartype
@@ -154,9 +154,8 @@ function Base.setindex!(a::AnyAbstractBlockSparseArray{<:Any,1}, value, I::Block
154154
return a
155155
end
156156

157-
# TODO: Use `@derive`.
158157
function ArrayLayouts.zero!(a::AnyAbstractBlockSparseArray)
159-
return @interface interface(a) zero!(a)
158+
return zero!(a)
160159
end
161160

162161
# TODO: Use `@derive`.

src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ArrayLayouts: ArrayLayouts, zero!
1+
using ArrayLayouts: ArrayLayouts
22
using BlockArrays:
33
BlockArrays,
44
AbstractBlockVector,
@@ -16,7 +16,7 @@ using BlockArrays:
1616
blocklength,
1717
blocks,
1818
findblockindex
19-
using DerivableInterfaces: DerivableInterfaces, @interface, DefaultArrayInterface
19+
using DerivableInterfaces: DerivableInterfaces, @interface, DefaultArrayInterface, zero!
2020
using LinearAlgebra: Adjoint, Transpose
2121
using SparseArraysBase:
2222
AbstractSparseArrayInterface,
@@ -266,7 +266,9 @@ end
266266
return a
267267
end
268268

269-
@interface ::AbstractBlockSparseArrayInterface function ArrayLayouts.zero!(a::AbstractArray)
269+
@interface ::AbstractBlockSparseArrayInterface function DerivableInterfaces.zero!(
270+
a::AbstractArray
271+
)
270272
# This will try to empty the storage if possible.
271273
zero!(blocks(a))
272274
return a

src/blocksparsearrayinterface/cat.jl

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
using BlockArrays: AbstractBlockedUnitRange, blockedrange, blocklengths
2-
using DerivableInterfaces: DerivableInterfaces, @interface, cat!
3-
using SparseArraysBase: SparseArraysBase
1+
using BlockArrays: blocks
2+
using DerivableInterfaces.Concatenate: Concatenated, cat!
43

5-
# TODO: Maybe move to `DerivableInterfacesBlockArraysExt`.
6-
# TODO: Handle dual graded unit ranges, for example in a new `SparseArraysBaseGradedUnitRangesExt`.
7-
function DerivableInterfaces.axis_cat(
8-
a1::AbstractBlockedUnitRange, a2::AbstractBlockedUnitRange
4+
function Base.copyto!(
5+
dest::AbstractArray, concat::Concatenated{<:BlockSparseArrayInterface}
96
)
10-
return blockedrange(vcat(blocklengths(a1), blocklengths(a2)))
11-
end
12-
13-
@interface ::AbstractBlockSparseArrayInterface function DerivableInterfaces.cat!(
14-
a_dest::AbstractArray, as::AbstractArray...; dims
15-
)
16-
cat!(blocks(a_dest), blocks.(as)...; dims)
17-
return a_dest
7+
# TODO: This assumes the destination blocking is commensurate with
8+
# the blocking of the sources, for example because it was constructed
9+
# based on the input arguments. Maybe check that explicitly.
10+
# This should mostly just get called from `cat` anyway and not get
11+
# called explicitly.
12+
cat!(blocks(dest), blocks.(concat.args)...; dims=concat.dims)
13+
return dest
1814
end

src/blocksparsearrayinterface/getunstoredblock.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using ArrayLayouts: zero!
21
using BlockArrays: Block
2+
using DerivableInterfaces: zero!
33

44
struct GetUnstoredBlock{Axes}
55
axes::Axes

0 commit comments

Comments
 (0)