Skip to content

Commit afc7277

Browse files
authored
Upgrade to FunctionImplementations v0.4 (#205)
1 parent 10e69a2 commit afc7277

8 files changed

Lines changed: 55 additions & 57 deletions

File tree

Project.toml

Lines changed: 3 additions & 3 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 <support@itensor.org> and contributors"]
4-
version = "0.10.17"
4+
version = "0.10.18"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
@@ -33,13 +33,13 @@ BlockArrays = "1.2"
3333
DiagonalArrays = "0.3"
3434
Dictionaries = "0.4.3"
3535
FillArrays = "1.13"
36-
FunctionImplementations = "0.3.1"
36+
FunctionImplementations = "0.4"
3737
GPUArraysCore = "0.1, 0.2"
3838
LinearAlgebra = "1.10"
3939
MacroTools = "0.5.13"
4040
MapBroadcast = "0.1.5"
4141
MatrixAlgebraKit = "0.6"
42-
SparseArraysBase = "0.8.3"
42+
SparseArraysBase = "0.9"
4343
SplitApplyCombine = "1.2.3"
4444
TensorAlgebra = "0.6.2"
4545
TypeParameterAccessors = "0.4.1"

src/abstractblocksparsearray/broadcast.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using BlockArrays: AbstractBlockedUnitRange, BlockSlice
22
using Base.Broadcast: BroadcastStyle
33

44
function Base.Broadcast.BroadcastStyle(arraytype::Type{<:AnyAbstractBlockSparseArray})
5-
return Broadcast.BlockSparseArrayStyle(BroadcastStyle(blocktype(arraytype)))
5+
return BlockSparseArrayStyle(BroadcastStyle(blocktype(arraytype)))
66
end
77

88
# Fix ambiguity error with `BlockArrays`.
@@ -16,7 +16,7 @@ function Base.Broadcast.BroadcastStyle(
1616
},
1717
},
1818
)
19-
return Broadcast.BlockSparseArrayStyle{ndims(arraytype)}()
19+
return BlockSparseArrayStyle{ndims(arraytype)}()
2020
end
2121
function Base.Broadcast.BroadcastStyle(
2222
arraytype::Type{
@@ -32,7 +32,7 @@ function Base.Broadcast.BroadcastStyle(
3232
},
3333
},
3434
)
35-
return Broadcast.BlockSparseArrayStyle{ndims(arraytype)}()
35+
return BlockSparseArrayStyle{ndims(arraytype)}()
3636
end
3737
function Base.Broadcast.BroadcastStyle(
3838
arraytype::Type{
@@ -44,7 +44,7 @@ function Base.Broadcast.BroadcastStyle(
4444
},
4545
},
4646
)
47-
return Broadcast.BlockSparseArrayStyle{ndims(arraytype)}()
47+
return BlockSparseArrayStyle{ndims(arraytype)}()
4848
end
4949

5050
# These catch cases that aren't caught by the standard
@@ -59,7 +59,7 @@ function Base.copyto!(
5959
return copyto!_blocksparse(dest, bc)
6060
end
6161
function Base.copyto!(
62-
dest::AnyAbstractBlockSparseArray{<:Any, N}, bc::Broadcasted{<:Broadcast.BlockSparseArrayStyle{N}}
62+
dest::AnyAbstractBlockSparseArray{<:Any, N}, bc::Broadcasted{<:BlockSparseArrayStyle{N}}
6363
) where {N}
6464
return copyto!_blocksparse(dest, bc)
6565
end

src/abstractblocksparsearray/unblockedsubarray.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ function BlockArrays.blocks(a::UnblockedSubArray)
1818
return SingleBlockView(a)
1919
end
2020

21-
using FunctionImplementations: FunctionImplementations, Style
22-
function FunctionImplementations.Style(arraytype::Type{<:UnblockedSubArray})
23-
return Style(blocktype(parenttype(arraytype)))
21+
using FunctionImplementations: FunctionImplementations, ImplementationStyle
22+
function FunctionImplementations.ImplementationStyle(arraytype::Type{<:UnblockedSubArray})
23+
return ImplementationStyle(blocktype(parenttype(arraytype)))
2424
end
2525

2626
function ArrayLayouts.MemoryLayout(arraytype::Type{<:UnblockedSubArray})

src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using BlockArrays:
99
blockedrange,
1010
mortar,
1111
unblock
12-
using FunctionImplementations: FunctionImplementations, Style, style, zero!
12+
using FunctionImplementations: FunctionImplementations, ImplementationStyle, style, zero!
1313
using GPUArraysCore: @allowscalar
1414
using SplitApplyCombine: groupcount
1515
using TypeParameterAccessors: similartype
@@ -28,8 +28,8 @@ const AnyAbstractBlockSparseVecOrMat{T, N} = Union{
2828
AnyAbstractBlockSparseVector{T}, AnyAbstractBlockSparseMatrix{T},
2929
}
3030

31-
function FunctionImplementations.Style(arrayt::Type{<:AnyAbstractBlockSparseArray})
32-
return BlockSparseArrayStyle()
31+
function FunctionImplementations.ImplementationStyle(arrayt::Type{<:AnyAbstractBlockSparseArray})
32+
return BlockSparseArrayImplementationStyle()
3333
end
3434

3535
# a[1:2, 1:2]
@@ -303,7 +303,7 @@ function Base.similar(
303303
elt::Type,
304304
axes::Tuple{Vararg{AbstractUnitRange{<:Integer}}},
305305
)
306-
return Style(arraytype)(similar)(arraytype, elt, axes)
306+
return ImplementationStyle(arraytype)(similar)(arraytype, elt, axes)
307307
end
308308

309309
function Base.similar(

src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using BlockArrays:
1919
using FunctionImplementations: FunctionImplementations, permuteddims, zero!
2020
using LinearAlgebra: Adjoint, Transpose
2121
using SparseArraysBase:
22-
AbstractSparseArrayStyle,
22+
AbstractSparseArrayImplementationStyle,
2323
getstoredindex,
2424
getunstoredindex,
2525
eachstoredindex,
@@ -109,16 +109,16 @@ blockstype(a::BlockArray) = blockstype(typeof(a))
109109
blocktype(arraytype::Type{<:BlockArray}) = eltype(blockstype(arraytype))
110110
blocktype(a::BlockArray) = eltype(blocks(a))
111111

112-
abstract type AbstractBlockSparseArrayStyle <: AbstractSparseArrayStyle end
112+
abstract type AbstractBlockSparseArrayImplementationStyle <: AbstractSparseArrayImplementationStyle end
113113

114-
struct BlockSparseArrayStyle <: AbstractBlockSparseArrayStyle end
115-
const blocksparse_style = BlockSparseArrayStyle()
114+
struct BlockSparseArrayImplementationStyle <: AbstractBlockSparseArrayImplementationStyle end
115+
const blocksparse_style = BlockSparseArrayImplementationStyle()
116116

117-
function FunctionImplementations.Style(
118-
style1::AbstractBlockSparseArrayStyle,
119-
style2::AbstractBlockSparseArrayStyle,
117+
function FunctionImplementations.ImplementationStyle(
118+
style1::AbstractBlockSparseArrayImplementationStyle,
119+
style2::AbstractBlockSparseArrayImplementationStyle,
120120
)
121-
return BlockSparseArrayStyle()
121+
return BlockSparseArrayImplementationStyle()
122122
end
123123

124124
const blocks_blocksparse = blocksparse_style(blocks)

src/blocksparsearrayinterface/broadcast.jl

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,55 @@ using Base.Broadcast: BroadcastStyle, Broadcasted
22
using GPUArraysCore: @allowscalar
33
using MapBroadcast: Mapped
44

5-
module Broadcast
6-
using Base.Broadcast: AbstractArrayStyle
7-
abstract type AbstractBlockSparseArrayStyle{N, B <: AbstractArrayStyle{N}} <:
8-
AbstractArrayStyle{N} end
9-
struct BlockSparseArrayStyle{N, B <: AbstractArrayStyle{N}} <:
10-
AbstractBlockSparseArrayStyle{N, B}
11-
blockstyle::B
12-
end
13-
function BlockSparseArrayStyle{N}(blockstyle::AbstractArrayStyle{N}) where {N}
14-
return BlockSparseArrayStyle{N, typeof(blockstyle)}(blockstyle)
15-
end
16-
function BlockSparseArrayStyle{N, B}() where {N, B <: AbstractArrayStyle{N}}
17-
return BlockSparseArrayStyle{N, B}(B())
18-
end
19-
function BlockSparseArrayStyle{N}() where {N}
20-
return BlockSparseArrayStyle{N}(Base.Broadcast.DefaultArrayStyle{N}())
21-
end
22-
BlockSparseArrayStyle(::Val{N}) where {N} = BlockSparseArrayStyle{N}()
23-
BlockSparseArrayStyle{M}(::Val{N}) where {M, N} = BlockSparseArrayStyle{N}()
24-
function BlockSparseArrayStyle{M, B}(::Val{N}) where {M, B <: AbstractArrayStyle{M}, N}
25-
return BlockSparseArrayStyle{N}(B(Val(N)))
26-
end
5+
using Base.Broadcast: AbstractArrayStyle
6+
abstract type AbstractBlockSparseArrayStyle{N, B <: AbstractArrayStyle{N}} <:
7+
AbstractArrayStyle{N} end
8+
struct BlockSparseArrayStyle{N, B <: AbstractArrayStyle{N}} <:
9+
AbstractBlockSparseArrayStyle{N, B}
10+
blockstyle::B
11+
end
12+
function BlockSparseArrayStyle{N}(blockstyle::AbstractArrayStyle{N}) where {N}
13+
return BlockSparseArrayStyle{N, typeof(blockstyle)}(blockstyle)
14+
end
15+
function BlockSparseArrayStyle{N, B}() where {N, B <: AbstractArrayStyle{N}}
16+
return BlockSparseArrayStyle{N, B}(B())
17+
end
18+
function BlockSparseArrayStyle{N}() where {N}
19+
return BlockSparseArrayStyle{N}(Base.Broadcast.DefaultArrayStyle{N}())
20+
end
21+
BlockSparseArrayStyle(::Val{N}) where {N} = BlockSparseArrayStyle{N}()
22+
BlockSparseArrayStyle{M}(::Val{N}) where {M, N} = BlockSparseArrayStyle{N}()
23+
function BlockSparseArrayStyle{M, B}(::Val{N}) where {M, B <: AbstractArrayStyle{M}, N}
24+
return BlockSparseArrayStyle{N}(B(Val(N)))
2725
end
2826

2927
function blockstyle(
30-
::Broadcast.AbstractBlockSparseArrayStyle{N, B},
28+
::AbstractBlockSparseArrayStyle{N, B},
3129
) where {N, B <: Base.Broadcast.AbstractArrayStyle{N}}
3230
return B()
3331
end
3432

3533
function Base.Broadcast.BroadcastStyle(
36-
style1::Broadcast.AbstractBlockSparseArrayStyle,
37-
style2::Broadcast.AbstractBlockSparseArrayStyle,
34+
style1::AbstractBlockSparseArrayStyle,
35+
style2::AbstractBlockSparseArrayStyle,
3836
)
3937
style = Base.Broadcast.result_style(blockstyle(style1), blockstyle(style2))
40-
return Broadcast.BlockSparseArrayStyle(style)
38+
return BlockSparseArrayStyle(style)
4139
end
4240

43-
Base.Broadcast.BroadcastStyle(a::Broadcast.BlockSparseArrayStyle, ::Base.Broadcast.DefaultArrayStyle{0}) = a
41+
Base.Broadcast.BroadcastStyle(a::BlockSparseArrayStyle, ::Base.Broadcast.DefaultArrayStyle{0}) = a
4442
function Base.Broadcast.BroadcastStyle(
45-
::Broadcast.BlockSparseArrayStyle{N}, a::Base.Broadcast.DefaultArrayStyle
43+
::BlockSparseArrayStyle{N}, a::Base.Broadcast.DefaultArrayStyle
4644
) where {N}
4745
return Base.Broadcast.BroadcastStyle(Base.Broadcast.DefaultArrayStyle{N}(), a)
4846
end
4947
function Base.Broadcast.BroadcastStyle(
50-
::Broadcast.BlockSparseArrayStyle{N}, ::Base.Broadcast.Style{Tuple}
48+
::BlockSparseArrayStyle{N}, ::Base.Broadcast.Style{Tuple}
5149
) where {N}
5250
return Base.Broadcast.DefaultArrayStyle{N}()
5351
end
5452

55-
function Base.similar(bc::Broadcasted{<:Broadcast.BlockSparseArrayStyle}, elt::Type, ax)
53+
function Base.similar(bc::Broadcasted{<:BlockSparseArrayStyle}, elt::Type, ax)
5654
# Find the first array in the broadcast expression.
5755
# TODO: Make this more generic, base it off sure this handles GPU arrays properly.
5856
bc′ = Base.Broadcast.flatten(bc)
@@ -84,7 +82,7 @@ end
8482

8583
# Broadcasting implementation
8684
function Base.copyto!(
87-
dest::AbstractArray{<:Any, N}, bc::Broadcasted{Broadcast.BlockSparseArrayStyle{N}}
85+
dest::AbstractArray{<:Any, N}, bc::Broadcasted{BlockSparseArrayStyle{N}}
8886
) where {N}
8987
return copyto!_blocksparse(dest, bc)
9088
end

src/blocksparsearrayinterface/cat.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using BlockArrays: blocks
22
using FunctionImplementations.Concatenate: Concatenated, cat!
33

44
function Base.copyto!(
5-
dest::AbstractArray, concat::Concatenated{<:Broadcast.BlockSparseArrayStyle}
5+
dest::AbstractArray, concat::Concatenated{<:BlockSparseArrayStyle}
66
)
77
# TODO: This assumes the destination blocking is commensurate with
88
# the blocking of the sources, for example because it was constructed

test/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ ArrayLayouts = "1"
3030
BlockArrays = "1.8"
3131
BlockSparseArrays = "0.10"
3232
DiagonalArrays = "0.3"
33-
FunctionImplementations = "0.3"
33+
FunctionImplementations = "0.4"
3434
GPUArraysCore = "0.2"
3535
JLArrays = "0.2, 0.3"
3636
LinearAlgebra = "1"
3737
MatrixAlgebraKit = "0.6"
3838
Random = "1"
3939
SafeTestsets = "0.1"
40-
SparseArraysBase = "0.8"
40+
SparseArraysBase = "0.9"
4141
StableRNGs = "1"
4242
Suppressor = "0.2"
4343
TensorAlgebra = "0.6"

0 commit comments

Comments
 (0)