@@ -16,7 +16,13 @@ using BlockArrays:
1616 blocklength,
1717 blocks,
1818 findblockindex
19- using DerivableInterfaces: DerivableInterfaces, @interface , DefaultArrayInterface, zero!
19+ using DerivableInterfaces:
20+ DerivableInterfaces,
21+ @interface ,
22+ AbstractArrayInterface,
23+ DefaultArrayInterface,
24+ interface,
25+ zero!
2026using LinearAlgebra: Adjoint, Transpose
2127using SparseArraysBase:
2228 AbstractSparseArrayInterface,
@@ -101,18 +107,47 @@ blockstype(a::BlockArray) = blockstype(typeof(a))
101107blocktype (arraytype:: Type{<:BlockArray} ) = eltype (blockstype (arraytype))
102108blocktype (a:: BlockArray ) = eltype (blocks (a))
103109
104- abstract type AbstractBlockSparseArrayInterface{N} <: AbstractSparseArrayInterface{N} end
110+ abstract type AbstractBlockSparseArrayInterface{N,B<: AbstractArrayInterface{N} } < :
111+ AbstractSparseArrayInterface{N} end
112+
113+ function blockinterface (interface:: AbstractBlockSparseArrayInterface{<:Any,B} ) where {B}
114+ return B ()
115+ end
105116
106117# 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)
118+ function Base. similar (interface:: AbstractBlockSparseArrayInterface , T:: Type , ax:: Tuple )
119+ # TODO : Generalize by storing the block interface in the block sparse array interface.
120+ N = length (ax)
121+ B = similartype (typeof (blockinterface (interface)), Type{T}, Tuple{blockaxistype .(ax)... })
122+ return similar (BlockSparseArray{T,N,B}, ax)
109123end
110124
111- struct BlockSparseArrayInterface{N} <: AbstractBlockSparseArrayInterface{N} end
125+ struct BlockSparseArrayInterface{N,B<: AbstractArrayInterface{N} } < :
126+ AbstractBlockSparseArrayInterface{N,B}
127+ blockinterface:: B
128+ end
129+ function BlockSparseArrayInterface {N} (blockinterface:: AbstractArrayInterface{N} ) where {N}
130+ return BlockSparseArrayInterface {N,typeof(blockinterface)} (blockinterface)
131+ end
132+ function BlockSparseArrayInterface {M,B} (:: Val{N} ) where {M,B<: AbstractArrayInterface{M} ,N}
133+ B′ = B (Val (N))
134+ return BlockSparseArrayInterface (B′)
135+ end
136+ function BlockSparseArrayInterface {N} () where {N}
137+ return BlockSparseArrayInterface {N} (DefaultArrayInterface {N} ())
138+ end
112139BlockSparseArrayInterface (:: Val{N} ) where {N} = BlockSparseArrayInterface {N} ()
113140BlockSparseArrayInterface {M} (:: Val{N} ) where {M,N} = BlockSparseArrayInterface {N} ()
114141BlockSparseArrayInterface () = BlockSparseArrayInterface {Any} ()
115142
143+ function DerivableInterfaces. combine_interface_rule (
144+ interface1:: AbstractBlockSparseArrayInterface ,
145+ interface2:: AbstractBlockSparseArrayInterface ,
146+ )
147+ B = interface (blockinterface (interface1), blockinterface (interface2))
148+ return BlockSparseArrayInterface (B)
149+ end
150+
116151@interface :: AbstractBlockSparseArrayInterface function BlockArrays. blocks (a:: AbstractArray )
117152 return error (" Not implemented" )
118153end
0 commit comments