@@ -102,24 +102,37 @@ blockstype(a::BlockArray) = blockstype(typeof(a))
102102blocktype (arraytype:: Type{<:BlockArray} ) = eltype (blockstype (arraytype))
103103blocktype (a:: BlockArray ) = eltype (blocks (a))
104104
105- abstract type AbstractBlockSparseArrayInterface <: AbstractSparseArrayInterface end
105+ abstract type AbstractBlockSparseArrayInterface{N} <: AbstractSparseArrayInterface{N} end
106106
107107# TODO : Also support specifying the `blocktype` along with the `eltype`.
108- function DerivableInterfaces . arraytype (
109- interface :: AbstractBlockSparseArrayInterface , T :: Type
110- )
111- B = DerivableInterfaces . arraytype (interface . blockinterface, T )
112- return BlockSparseArray{T,<: Any ,B}
108+ function Base . similar (interface :: AbstractBlockSparseArrayInterface , T :: Type , ax :: Tuple )
109+ N = length (ax)
110+ block_axt = Tuple{ blockaxistype .(ax) ... }
111+ B = _similartype ( blockinterface (interface), Type{T}, block_axt )
112+ return similar ( BlockSparseArray{T,N ,B}, ax)
113113end
114114
115- struct BlockSparseArrayInterface{B<: AbstractArrayInterface } < :
116- AbstractBlockSparseArrayInterface
115+ struct BlockSparseArrayInterface{N, B<: AbstractArrayInterface{N} } < :
116+ AbstractBlockSparseArrayInterface{N}
117117 blockinterface:: B
118118end
119+ blockinterface (interface:: BlockSparseArrayInterface ) = getfield (interface, :blockinterface )
120+ function BlockSparseArrayInterface {N} (blockinterface:: AbstractArrayInterface{N} ) where {N}
121+ return BlockSparseArrayInterface {N,typeof(blockinterface)} (blockinterface)
122+ end
123+ function BlockSparseArrayInterface {N} () where {N}
124+ return BlockSparseArrayInterface {N} (DefaultArrayInterface {N} ())
125+ end
126+ BlockSparseArrayInterface (:: Val{N} ) where {N} = BlockSparseArrayInterface {N} ()
127+ BlockSparseArrayInterface {M} (:: Val{N} ) where {M,N} = BlockSparseArrayInterface {N} ()
128+ function BlockSparseArrayInterface {M,B} (:: Val{N} ) where {M,B<: AbstractArrayInterface{M} ,N}
129+ return BlockSparseArrayInterface {N,B} (B (Val (N)))
130+ end
131+ BlockSparseArrayInterface () = BlockSparseArrayInterface {Any} ()
119132
120- @interface :: AbstractBlockSparseArrayInterface BlockArrays. blocks (a:: AbstractArray ) = error (
121- " Not implemented"
122- )
133+ @interface :: AbstractBlockSparseArrayInterface function BlockArrays. blocks (a:: AbstractArray )
134+ return error ( " Not implemented" )
135+ end
123136
124137@interface :: AbstractBlockSparseArrayInterface function SparseArraysBase. isstored (
125138 a:: AbstractArray{<:Any,N} , I:: Vararg{Int,N}
0 commit comments