11
11
12
12
Singleton type used in block array initialization, indicating the
13
13
array-constructor-caller would like an uninitialized block array. See also
14
- undef_blocks (@ref), an alias for UndefBlocksInitializer().
14
+ [` undef_blocks`] (@ref), an alias for ` UndefBlocksInitializer()` .
15
15
16
16
# Examples
17
17
```jldoctest
@@ -28,8 +28,8 @@ struct UndefBlocksInitializer end
28
28
"""
29
29
undef_blocks
30
30
31
- Alias for UndefBlocksInitializer(), which constructs an instance of the singleton
32
- type UndefBlocksInitializer (@ref), used in block array initialization to indicate the
31
+ Alias for ` UndefBlocksInitializer()` , which constructs an instance of the singleton
32
+ type [` UndefBlocksInitializer`] (@ref), used in block array initialization to indicate the
33
33
array-constructor-caller would like an uninitialized block array.
34
34
35
35
# Examples
97
97
_BlockArray (R, block_sizes... )
98
98
99
99
"""
100
- Constructs a `BlockArray` with uninitialized blocks from a block type `R` with sizes defined by `block_sizes`.
100
+ BlockArray(::UndefBlocksInitializer, ::Type{R}, block_sizes::Vararg{AbstractVector{<:Integer}, N}) where {N,R<:AbstractArray{<:Any,N}}
101
101
102
+ Construct a `N`-dim `BlockArray` with uninitialized blocks from a block type `R`, with sizes defined by `block_sizes`.
103
+ Each block **must** be allocated before being accessed.
104
+
105
+ # Examples
102
106
```jldoctest
103
- julia> BlockArray(undef_blocks, Matrix{Float64}, [1,3], [2,2])
107
+ julia> B = BlockArray(undef_blocks, Matrix{Float64}, [1,3], [2,2])
104
108
2×2-blocked 4×4 BlockMatrix{Float64}:
105
109
#undef #undef │ #undef #undef
106
110
────────────────┼────────────────
107
111
#undef #undef │ #undef #undef
108
112
#undef #undef │ #undef #undef
109
113
#undef #undef │ #undef #undef
114
+
115
+ julia> typeof(blocks(B))
116
+ Matrix{Matrix{Float64}} (alias for Array{Array{Float64, 2}, 2})
117
+
118
+ julia> using SparseArrays
119
+
120
+ julia> B = BlockArray(undef_blocks, SparseMatrixCSC{Float64,Int}, [1,3], [2,2]);
121
+
122
+ julia> typeof(blocks(B))
123
+ Matrix{SparseMatrixCSC{Float64, Int64}} (alias for Array{SparseMatrixCSC{Float64, Int64}, 2})
110
124
```
125
+
126
+ See also [`undef_blocks`](@ref), [`UndefBlocksInitializer`](@ref)
111
127
"""
112
128
@inline BlockArray (:: UndefBlocksInitializer , :: Type{R} , block_sizes:: Vararg{AbstractVector{<:Integer}, N} ) where {T, N, R<: AbstractArray{T,N} } =
113
129
undef_blocks_BlockArray (Array{R,N}, block_sizes... )
114
130
131
+ """
132
+ BlockArray{T}(::UndefBlocksInitializer, block_sizes::Vararg{AbstractVector{<:Integer}, N}) where {T,N}
133
+
134
+ Construct a `N`-dim `BlockArray` with uninitialized blocks of type `Array{T,N}`, with sizes defined by `block_sizes`.
135
+ Each block **must** be allocated before being accessed.
136
+
137
+ # Examples
138
+ ```jldoctest
139
+ julia> B = BlockArray{Float64}(undef_blocks, [1,2], [1,2])
140
+ 2×2-blocked 3×3 BlockMatrix{Float64}:
141
+ #undef │ #undef #undef
142
+ ────────┼────────────────
143
+ #undef │ #undef #undef
144
+ #undef │ #undef #undef
145
+
146
+ julia> typeof(blocks(B))
147
+ Matrix{Matrix{Float64}} (alias for Array{Array{Float64, 2}, 2})
148
+
149
+ julia> B = BlockArray{Int8}(undef_blocks, [1,2])
150
+ 2-blocked 3-element BlockVector{Int8}:
151
+ #undef
152
+ ──────
153
+ #undef
154
+ #undef
155
+
156
+ julia> typeof(blocks(B))
157
+ Vector{Vector{Int8}} (alias for Array{Array{Int8, 1}, 1})
158
+
159
+ julia> B[Block(1)] .= 2 # errors, as the block is not allocated yet
160
+ ERROR: UndefRefError: access to undefined reference
161
+ [...]
162
+
163
+ julia> B[Block(1)] = [1]; # assign an array to the block
164
+
165
+ julia> B[Block(2)] = [2,3];
166
+
167
+ julia> B
168
+ 2-blocked 3-element BlockVector{Int8}:
169
+ 1
170
+ ─
171
+ 2
172
+ 3
173
+ ```
174
+
175
+ See also [`undef_blocks`](@ref), [`UndefBlocksInitializer`](@ref)
176
+ """
115
177
@inline BlockArray {T} (:: UndefBlocksInitializer , block_sizes:: Vararg{AbstractVector{<:Integer}, N} ) where {T, N} =
116
178
BlockArray (undef_blocks, Array{T,N}, block_sizes... )
117
179
@@ -149,6 +211,28 @@ initialized_blocks_BlockArray(::Type{R}, block_sizes::Vararg{AbstractVector{<:In
149
211
@inline BlockArray {T,N,R,BS} (:: UndefInitializer , baxes:: BS ) where {T, N, R<: AbstractArray{<:AbstractArray{T,N},N} , BS<: NTuple{N,AbstractUnitRange{Int}} } =
150
212
initialized_blocks_BlockArray (R, baxes)
151
213
214
+ """
215
+ BlockArray{T}(::UndefInitializer, block_sizes::Vararg{AbstractVector{<:Integer}, N}) where {T, N}
216
+
217
+ Construct a `N`-dim `BlockArray` with blocks of type `Array{T,N}`, with sizes defined by `block_sizes`.
218
+ The blocks are allocated using `similar`, and the elements in each block are therefore unitialized.
219
+
220
+ # Examples
221
+ ```jldoctest
222
+ julia> B = BlockArray{Int8}(undef, [1,2]);
223
+
224
+ julia> B[Block(1)] .= 2;
225
+
226
+ julia> B[Block(2)] .= 3;
227
+
228
+ julia> B
229
+ 2-blocked 3-element BlockVector{Int8}:
230
+ 2
231
+ ─
232
+ 3
233
+ 3
234
+ ```
235
+ """
152
236
@inline BlockArray {T} (:: UndefInitializer , block_sizes:: Vararg{AbstractVector{<:Integer}, N} ) where {T, N} =
153
237
initialized_blocks_BlockArray (Array{Array{T,N},N}, block_sizes... )
154
238
0 commit comments