Skip to content

Commit 86d7f46

Browse files
committed
Update for TypeParameterAccessors.jl v0.4
1 parent 09a0a6b commit 86d7f46

File tree

6 files changed

+34
-14
lines changed

6 files changed

+34
-14
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ SparseArraysBase = "0.5"
4444
SplitApplyCombine = "1.2.3"
4545
TensorAlgebra = "0.3.2"
4646
Test = "1.10"
47-
TypeParameterAccessors = "0.2, 0.3, 0.4"
47+
TypeParameterAccessors = "0.4"
4848
julia = "1.10"
4949

5050
[extras]

src/BlockArraysExtensions/blockedunitrange.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ axis(a::AbstractVector) = axes(a, 1)
2929
function eachblockaxis(a::AbstractVector)
3030
return map(axis, blocks(a))
3131
end
32+
function blockaxistype(a::AbstractVector)
33+
return eltype(eachblockaxis(a))
34+
end
3235

3336
# Take a collection of axes and mortar them
3437
# into a single blocked axis.

src/abstractblocksparsearray/unblockedsubarray.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ function Broadcast.BroadcastStyle(arraytype::Type{<:UnblockedSubArray})
3030
return BroadcastStyle(blocktype(parenttype(arraytype)))
3131
end
3232

33-
function TypeParameterAccessors.similartype(arraytype::Type{<:UnblockedSubArray}, elt::Type)
34-
return similartype(blocktype(parenttype(arraytype)), elt)
35-
end
36-
3733
function Base.similar(
3834
a::UnblockedSubArray, elt::Type, axes::Tuple{Base.OneTo,Vararg{Base.OneTo}}
3935
)

src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ function Base.similar(
231231
end
232232

233233
function blocksparse_similar(a, elt::Type, axes::Tuple)
234-
return BlockSparseArray{elt,length(axes),similartype(blocktype(a), elt, axes)}(
235-
undef, axes
236-
)
234+
ndims = length(axes)
235+
blockt = similartype(blocktype(a), Type{elt}, Tuple{blockaxistype.(axes)...})
236+
return BlockSparseArray{elt,ndims,blockt}(undef, axes)
237237
end
238238
@interface ::AbstractBlockSparseArrayInterface function Base.similar(
239239
a::AbstractArray, elt::Type, axes::Tuple{Vararg{Int}}

src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ using BlockArrays:
1616
blocklength,
1717
blocks,
1818
findblockindex
19-
using DerivableInterfaces: DerivableInterfaces, @interface, DefaultArrayInterface, zero!
19+
using DerivableInterfaces:
20+
DerivableInterfaces, @interface, AbstractArrayInterface, DefaultArrayInterface, zero!
2021
using LinearAlgebra: Adjoint, Transpose
2122
using SparseArraysBase:
2223
AbstractSparseArrayInterface,
@@ -101,14 +102,34 @@ blockstype(a::BlockArray) = blockstype(typeof(a))
101102
blocktype(arraytype::Type{<:BlockArray}) = eltype(blockstype(arraytype))
102103
blocktype(a::BlockArray) = eltype(blocks(a))
103104

104-
abstract type AbstractBlockSparseArrayInterface{N} <: AbstractSparseArrayInterface{N} end
105+
abstract type AbstractBlockSparseArrayInterface{N,B<:AbstractArrayInterface{N}} <:
106+
AbstractSparseArrayInterface{N} end
107+
108+
function blockinterface(interface::AbstractBlockSparseArrayInterface{<:Any,B}) where {B}
109+
return B()
110+
end
105111

106112
# TODO: Also support specifying the `blocktype` along with the `eltype`.
107-
function Base.similar(::AbstractBlockSparseArrayInterface, T::Type, ax::Tuple)
108-
return similar(BlockSparseArray{T}, ax)
113+
function Base.similar(interface::AbstractBlockSparseArrayInterface, T::Type, ax::Tuple)
114+
# TODO: Generalize by storing the block interface in the block sparse array interface.
115+
N = length(ax)
116+
B = similartype(blockinterface(interface), T, Tuple{blockaxistype.(ax)...})
117+
return similar(BlockSparseArray{T,N,B}, ax)
109118
end
110119

111-
struct BlockSparseArrayInterface{N} <: AbstractBlockSparseArrayInterface{N} end
120+
struct BlockSparseArrayInterface{N,B<:AbstractArrayInterface{N}} <:
121+
AbstractBlockSparseArrayInterface{N,B}
122+
blockinterface::B
123+
end
124+
function BlockSparseArrayInterface{N}(blockinterface::AbstractArrayInterface{N}) where {N}
125+
return BlockSparseArrayInterface{N,typeof(blockinterface)}(blockinterface)
126+
end
127+
function BlockSparseArrayInterface{M,B}(::Val{N}) where {M,B,N}
128+
return BlockSparseArrayInterface{N,B}(blockinterface(B)(Val(N)))
129+
end
130+
function BlockSparseArrayInterface{N}() where {N}
131+
return BlockSparseArrayInterface{N}(DefaultArrayInterface{N}())
132+
end
112133
BlockSparseArrayInterface(::Val{N}) where {N} = BlockSparseArrayInterface{N}()
113134
BlockSparseArrayInterface{M}(::Val{N}) where {M,N} = BlockSparseArrayInterface{N}()
114135
BlockSparseArrayInterface() = BlockSparseArrayInterface{Any}()

test/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ Suppressor = "0.2"
3838
TensorAlgebra = "0.3.2"
3939
Test = "1"
4040
TestExtras = "0.3"
41-
TypeParameterAccessors = "0.2, 0.3, 0.4"
41+
TypeParameterAccessors = "0.4"

0 commit comments

Comments
 (0)