1- using BlockArrays: BlockArrays, Block, BlockedUnitRange, blockedrange, blocklength
1+ using BlockArrays:
2+ BlockArrays,
3+ Block,
4+ BlockedUnitRange,
5+ UndefBlocksInitializer,
6+ blockedrange,
7+ blocklength,
8+ undef_blocks
29using DerivableInterfaces: @interface
310using Dictionaries: Dictionary
411using SparseArraysBase: SparseArrayDOK
512
13+ """
14+ SparseArrayDOK{T}(::UndefBlocksInitializer, axes)
15+ SparseArrayDOK{T,N}(::UndefBlocksInitializer, axes)
16+
17+ Construct the block structure of an undefined BlockSparseArray that will have
18+ blocked axes `axes`.
19+ """
20+ function SparseArraysBase. SparseArrayDOK {T,N} (
21+ :: UndefBlocksInitializer , ax:: Tuple{Vararg{AbstractUnitRange{<:Integer},N}}
22+ ) where {T,N}
23+ return SparseArrayDOK {T,N} (undef, blocklength .(ax), GetUnstoredBlock (ax))
24+ end
25+ function SparseArraysBase. SparseArrayDOK {T,N} (
26+ :: UndefBlocksInitializer , ax:: Vararg{AbstractUnitRange{<:Integer},N}
27+ ) where {T,N}
28+ return SparseArrayDOK {T,N} (undef_blocks, ax)
29+ end
30+ function SparseArraysBase. SparseArrayDOK {T,N} (
31+ :: UndefBlocksInitializer , dims:: Tuple{Vararg{AbstractVector{<:Integer},N}}
32+ ) where {T,N}
33+ return SparseArrayDOK {T,N} (undef_blocks, blockedrange .(dims))
34+ end
35+ function SparseArraysBase. SparseArrayDOK {T,N} (
36+ :: UndefBlocksInitializer , dims:: Vararg{AbstractVector{<:Integer},N}
37+ ) where {T,N}
38+ return SparseArrayDOK {T,N} (undef_blocks, blockedrange .(dims))
39+ end
40+
41+ function SparseArraysBase. SparseArrayDOK {T} (
42+ :: UndefBlocksInitializer , ax:: Tuple{Vararg{AbstractUnitRange{<:Integer},N}}
43+ ) where {T,N}
44+ return SparseArrayDOK {T,N} (undef_blocks, ax)
45+ end
46+ function SparseArraysBase. SparseArrayDOK {T} (
47+ :: UndefBlocksInitializer , ax:: Vararg{AbstractUnitRange{<:Integer},N}
48+ ) where {T,N}
49+ return SparseArrayDOK {T,N} (undef_blocks, ax)
50+ end
51+ function SparseArraysBase. SparseArrayDOK {T} (
52+ :: UndefBlocksInitializer , dims:: Tuple{Vararg{AbstractVector{<:Integer},N}}
53+ ) where {T,N}
54+ return SparseArrayDOK {T,N} (undef_blocks, blockedrange .(dims))
55+ end
56+ function SparseArraysBase. SparseArrayDOK {T} (
57+ :: UndefBlocksInitializer , dims:: Vararg{AbstractVector{<:Integer},N}
58+ ) where {T,N}
59+ return SparseArrayDOK {T,N} (undef_blocks, blockedrange .(dims))
60+ end
61+
662function _BlockSparseArray end
763
864struct BlockSparseArray{
@@ -46,12 +102,22 @@ function sparsemortar(
46102) where {T,N}
47103 return _BlockSparseArray (blocks, axes)
48104end
49-
50- function BlockArrays. mortar (
51- blocks:: SparseArrayDOK{<:AbstractArray{T,N},N} ,
52- axes:: Tuple{Vararg{AbstractUnitRange{<:Integer},N}} ,
105+ function sparsemortar (
106+ blocks:: AbstractArray{<:AbstractArray{T,N},N} ,
107+ axes:: Vararg{AbstractUnitRange{<:Integer},N} ,
53108) where {T,N}
54- return _BlockSparseArray (blocks, axes)
109+ return sparsemortar (blocks, axes)
110+ end
111+ function sparsemortar (
112+ blocks:: AbstractArray{<:AbstractArray{T,N},N} ,
113+ dims:: Tuple{Vararg{AbstractVector{<:Integer},N}} ,
114+ ) where {T,N}
115+ return sparsemortar (blocks, blockedrange .(dims))
116+ end
117+ function sparsemortar (
118+ blocks:: AbstractArray{<:AbstractArray{T,N},N} , dims:: Vararg{AbstractVector{<:Integer},N}
119+ ) where {T,N}
120+ return sparsemortar (blocks, dims)
55121end
56122
57123@doc """
@@ -64,20 +130,19 @@ of block lengths in each dimension or a list of blocked ranges representing the
64130""" BlockSparseArray
65131
66132function BlockSparseArray {T,N,A} (
67- :: UndefInitializer , axes:: Tuple{Vararg{AbstractUnitRange,N}}
133+ :: UndefInitializer , axes:: Tuple{Vararg{AbstractUnitRange{<:Integer} ,N}}
68134) where {T,N,A<: AbstractArray{T,N} }
69- blocks = default_blocks (A, axes)
70- return _BlockSparseArray (blocks, axes)
135+ return _BlockSparseArray (SparseArrayDOK {A} (undef_blocks, axes), axes)
71136end
72137
73138function BlockSparseArray {T,N,A} (
74- :: UndefInitializer , axes:: Vararg{AbstractUnitRange,N}
139+ :: UndefInitializer , axes:: Vararg{AbstractUnitRange{<:Integer} ,N}
75140) where {T,N,A<: AbstractArray{T,N} }
76141 return BlockSparseArray {T,N,A} (undef, axes)
77142end
78143
79144function BlockSparseArray {T,N,A} (
80- :: UndefInitializer , dims:: Tuple{Vararg{Vector{Int },N}}
145+ :: UndefInitializer , dims:: Tuple{Vararg{AbstractVector{<:Integer },N}}
81146) where {T,N,A<: AbstractArray{T,N} }
82147 return BlockSparseArray {T,N,A} (undef, blockedrange .(dims))
83148end
86151function BlockSparseArray {T,0,A} (
87152 :: UndefInitializer , axes:: Tuple{}
88153) where {T,A<: AbstractArray{T,0} }
89- blocks = default_blocks (A, axes)
90- return _BlockSparseArray (blocks, axes)
154+ return _BlockSparseArray (SparseArrayDOK {A} (undef_blocks, axes), axes)
91155end
92156
93157function BlockSparseArray {T,N,A} (
94- :: UndefInitializer , dims:: Vararg{Vector{Int },N}
158+ :: UndefInitializer , dims:: Vararg{AbstractVector{<:Integer },N}
95159) where {T,N,A<: AbstractArray{T,N} }
96160 return BlockSparseArray {T,N,A} (undef, dims)
97161end
98162
99163function BlockSparseArray {T,N} (
100- :: UndefInitializer , axes:: Tuple{Vararg{AbstractUnitRange,N}}
164+ :: UndefInitializer , axes:: Tuple{Vararg{AbstractUnitRange{<:Integer} ,N}}
101165) where {T,N}
102- return BlockSparseArray {T,N,default_arraytype(T, axes) } (undef, axes)
166+ return BlockSparseArray {T,N,Array{T,N} } (undef, axes)
103167end
104168
105169function BlockSparseArray {T,N} (
106- :: UndefInitializer , axes:: Vararg{AbstractUnitRange,N}
170+ :: UndefInitializer , axes:: Vararg{AbstractUnitRange{<:Integer} ,N}
107171) where {T,N}
108172 return BlockSparseArray {T,N} (undef, axes)
109173end
110174
111175function BlockSparseArray {T,0} (:: UndefInitializer , axes:: Tuple{} ) where {T}
112- return BlockSparseArray {T,0,default_arraytype(T, axes) } (undef, axes)
176+ return BlockSparseArray {T,0,Array{T,0} } (undef, axes)
113177end
114178
115179function BlockSparseArray {T,N} (
116- :: UndefInitializer , dims:: Tuple{Vararg{Vector{Int },N}}
180+ :: UndefInitializer , dims:: Tuple{Vararg{AbstractVector{<:Integer },N}}
117181) where {T,N}
118182 return BlockSparseArray {T,N} (undef, blockedrange .(dims))
119183end
120184
121- function BlockSparseArray {T,N} (:: UndefInitializer , dims:: Vararg{Vector{Int},N} ) where {T,N}
185+ function BlockSparseArray {T,N} (
186+ :: UndefInitializer , dims:: Vararg{AbstractVector{<:Integer},N}
187+ ) where {T,N}
122188 return BlockSparseArray {T,N} (undef, dims)
123189end
124190
125- function BlockSparseArray {T} (:: UndefInitializer , dims:: Tuple{Vararg{Vector{Int}}} ) where {T}
191+ function BlockSparseArray {T} (
192+ :: UndefInitializer , dims:: Tuple{Vararg{AbstractVector{<:Integer}}}
193+ ) where {T}
126194 return BlockSparseArray {T,length(dims)} (undef, dims)
127195end
128196
129197function BlockSparseArray {T} (
130- :: UndefInitializer , axes:: Tuple{Vararg{AbstractUnitRange}}
198+ :: UndefInitializer , axes:: Tuple{Vararg{AbstractUnitRange{<:Integer} }}
131199) where {T}
132200 return BlockSparseArray {T,length(axes)} (undef, axes)
133201end
@@ -136,11 +204,15 @@ function BlockSparseArray{T}(::UndefInitializer, axes::Tuple{}) where {T}
136204 return BlockSparseArray {T,length(axes)} (undef, axes)
137205end
138206
139- function BlockSparseArray {T} (:: UndefInitializer , dims:: Vararg{Vector{Int}} ) where {T}
207+ function BlockSparseArray {T} (
208+ :: UndefInitializer , dims:: Vararg{AbstractVector{<:Integer}}
209+ ) where {T}
140210 return BlockSparseArray {T} (undef, dims)
141211end
142212
143- function BlockSparseArray {T} (:: UndefInitializer , axes:: Vararg{AbstractUnitRange} ) where {T}
213+ function BlockSparseArray {T} (
214+ :: UndefInitializer , axes:: Vararg{AbstractUnitRange{<:Integer}}
215+ ) where {T}
144216 return BlockSparseArray {T} (undef, axes)
145217end
146218
0 commit comments