Skip to content

Commit b889e28

Browse files
authored
Update docstrings (#271)
* Update docstrings * remove missed doctest setup * Add doctests * Update blockproduct.jl * fix blockvec result summary * validate doctests only on v1.9+ in tests
1 parent e5e6742 commit b889e28

File tree

10 files changed

+213
-30
lines changed

10 files changed

+213
-30
lines changed

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ using Documenter, BlockArrays
33
# Build documentation.
44
# ====================
55

6+
DocMeta.setdocmeta!(BlockArrays, :DocTestSetup, :(using BlockArrays); recursive=true)
7+
68
makedocs(
79
modules = [BlockArrays],
810
sitename = "BlockArrays.jl",
9-
strict = VERSION.major == 1 && sizeof(Int) == 8, # only strict mode on 1.0 and Int64
1011
pages = Any[
1112
"Home" => "index.md",
1213
"Manual" => [

src/abstractblockarray.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Throw a `BlockBoundsError` if the specified block indexes are not in bounds for
7979
Subtypes of `AbstractBlockArray` should
8080
specialize this method if they need to provide custom block bounds checking behaviors.
8181
82-
```jldoctest; setup = quote using BlockArrays end
82+
```jldoctest
8383
julia> A = BlockArray(rand(2,3), [1,1], [2,1]);
8484
8585
julia> blockcheckbounds(A, 3, 2)
@@ -145,7 +145,7 @@ end
145145
Create a generator that iterates over each block of an `AbstractBlockArray`
146146
returning views.
147147
148-
```jldoctest; setup = quote using BlockArrays end
148+
```jldoctest
149149
julia> v = Array(reshape(1:6, (2, 3)))
150150
2×3 Matrix{Int64}:
151151
1 3 5

src/blockarray.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ array-constructor-caller would like an uninitialized block array. See also
1414
undef_blocks (@ref), an alias for UndefBlocksInitializer().
1515
1616
# Examples
17-
```jldoctest; setup=:(using BlockArrays)
17+
```jldoctest
1818
julia> BlockArray(undef_blocks, Matrix{Float32}, [1,2], [3,2])
1919
2×2-blocked 3×5 BlockMatrix{Float32}:
2020
#undef #undef #undef │ #undef #undef
@@ -33,7 +33,7 @@ type UndefBlocksInitializer (@ref), used in block array initialization to indica
3333
array-constructor-caller would like an uninitialized block array.
3434
3535
# Examples
36-
```jldoctest; setup=:(using BlockArrays)
36+
```jldoctest
3737
julia> BlockArray(undef_blocks, Matrix{Float32}, [1,2], [3,2])
3838
2×2-blocked 3×5 BlockMatrix{Float32}:
3939
#undef #undef #undef │ #undef #undef
@@ -99,7 +99,7 @@ end
9999
"""
100100
Constructs a `BlockArray` with uninitialized blocks from a block type `R` with sizes defined by `block_sizes`.
101101
102-
```jldoctest; setup = quote using BlockArrays end
102+
```jldoctest
103103
julia> BlockArray(undef_blocks, Matrix{Float64}, [1,3], [2,2])
104104
2×2-blocked 4×4 BlockMatrix{Float64}:
105105
#undef #undef │ #undef #undef
@@ -218,7 +218,7 @@ Construct a `BlockArray` from `blocks`. `block_sizes` is computed from
218218
This is an "inverse" of [`blocks`](@ref).
219219
220220
# Examples
221-
```jldoctest; setup = quote using BlockArrays end
221+
```jldoctest
222222
julia> arrays = permutedims(reshape([
223223
fill(1.0, 1, 3), fill(2.0, 1, 2),
224224
fill(3.0, 2, 3), fill(4.0, 2, 2),

src/blockaxis.jl

Lines changed: 116 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ is an `AbstractUnitRange{Int}` that has been divided
3131
into blocks, and is used to represent axes of block arrays.
3232
Construction is typically via `blockedrange` which converts
3333
a vector of block lengths to a `BlockedUnitRange`.
34-
```jldoctest; setup = quote using BlockArrays end
34+
35+
# Examples
36+
```jldoctest
3537
julia> blockedrange([2,2,3])
3638
3-blocked 7-element BlockedUnitRange{Vector{Int64}}:
3739
1
@@ -72,14 +74,38 @@ length(a::BlockedUnitRange) = isempty(a.lasts) ? 0 : Integer(last(a.lasts)-a.fir
7274
"""
7375
blockisequal(a::AbstractUnitRange{Int}, b::AbstractUnitRange{Int})
7476
75-
returns true if a and b have the same block structure.
77+
Check if `a` and `b` have the same block structure.
78+
79+
# Examples
80+
```jldoctest
81+
julia> b1 = blockedrange(1:2)
82+
2-blocked 3-element BlockedUnitRange{ArrayLayouts.RangeCumsum{Int64, UnitRange{Int64}}}:
83+
1
84+
85+
2
86+
3
87+
88+
julia> b2 = blockedrange([1,1,1])
89+
3-blocked 3-element BlockedUnitRange{Vector{Int64}}:
90+
1
91+
92+
2
93+
94+
3
95+
96+
julia> blockisequal(b1, b1)
97+
true
98+
99+
julia> blockisequal(b1, b2)
100+
false
101+
```
76102
"""
77103
blockisequal(a::AbstractUnitRange{Int}, b::AbstractUnitRange{Int}) = first(a) == first(b) && blocklasts(a) == blocklasts(b)
78104
blockisequal(a, b, c, d...) = blockisequal(a,b) && blockisequal(b,c,d...)
79105
"""
80106
blockisequal(a::Tuple, b::Tuple)
81107
82-
returns true if `all(blockisequal.(a,b))`` is true.
108+
Return `all(blockisequal.(a,b))``
83109
"""
84110
blockisequal(a::Tuple, b::Tuple) = all(blockisequal.(a, b))
85111

@@ -101,18 +127,28 @@ Base.promote_rule(::Type{BlockedUnitRange{CS}}, ::Type{Base.OneTo{Int}}) where C
101127
blockaxes(A)
102128
103129
Return the tuple of valid block indices for array `A`.
104-
```jldoctest; setup = quote using BlockArrays end
130+
131+
# Examples
132+
```jldoctest
105133
julia> A = BlockArray([1,2,3],[2,1])
106134
2-blocked 3-element BlockVector{Int64}:
107135
1
108136
2
109137
110138
3
111139
112-
julia> blockaxes(A)[1]
113-
2-element BlockRange{1, Tuple{Base.OneTo{Int64}}}:
114-
Block(1)
115-
Block(2)
140+
julia> blockaxes(A)
141+
(BlockRange(Base.OneTo(2)),)
142+
143+
julia> B = BlockArray(zeros(3,4), [1,2], [1,2,1])
144+
2×3-blocked 3×4 BlockMatrix{Float64}:
145+
0.0 │ 0.0 0.0 │ 0.0
146+
─────┼────────────┼─────
147+
0.0 │ 0.0 0.0 │ 0.0
148+
0.0 │ 0.0 0.0 │ 0.0
149+
150+
julia> blockaxes(B)
151+
(BlockRange(Base.OneTo(2)), BlockRange(Base.OneTo(3)))
116152
```
117153
"""
118154
blockaxes(b::BlockedUnitRange) = _blockaxes(b.lasts)
@@ -124,7 +160,9 @@ blockaxes(b) = blockaxes.(axes(b), 1)
124160
blockaxes(A, d)
125161
126162
Return the valid range of block indices for array `A` along dimension `d`.
127-
```jldoctest; setup = quote using BlockArrays end
163+
164+
# Examples
165+
```jldoctest
128166
julia> A = BlockArray([1,2,3],[2,1])
129167
2-blocked 3-element BlockVector{Int64}:
130168
1
@@ -148,7 +186,9 @@ end
148186
149187
Return the tuple of the number of blocks along each
150188
dimension. See also size and blocksizes.
151-
```jldoctest; setup = quote using BlockArrays end
189+
190+
# Examples
191+
```jldoctest
152192
julia> A = BlockArray(ones(3,3),[2,1],[1,1,1])
153193
2×3-blocked 3×3 BlockMatrix{Float64}:
154194
1.0 │ 1.0 │ 1.0
@@ -173,7 +213,9 @@ blocksize(A,i) = length(blockaxes(A,i))
173213
174214
Return the tuple of the sizes of blocks along each
175215
dimension. See also size and blocksize.
176-
```jldoctest; setup = quote using BlockArrays end
216+
217+
# Examples
218+
```jldoctest
177219
julia> A = BlockArray(ones(3,3),[2,1],[1,1,1])
178220
2×3-blocked 3×3 BlockMatrix{Float64}:
179221
1.0 │ 1.0 │ 1.0
@@ -282,19 +324,79 @@ end
282324
"""
283325
blockfirsts(a::AbstractUnitRange{Int})
284326
285-
returns the first index of each block of `a`.
327+
Return the first index of each block of `a`.
328+
329+
# Examples
330+
```jldoctest
331+
julia> b = blockedrange(1:3)
332+
3-blocked 6-element BlockedUnitRange{ArrayLayouts.RangeCumsum{Int64, UnitRange{Int64}}}:
333+
1
334+
335+
2
336+
3
337+
338+
4
339+
5
340+
6
341+
342+
julia> blockfirsts(b)
343+
3-element Vector{Int64}:
344+
1
345+
2
346+
4
347+
```
286348
"""
287349
blockfirsts(a::AbstractUnitRange{Int}) = Ones{Int}(1)
288350
"""
289351
blocklasts(a::AbstractUnitRange{Int})
290352
291-
returns the last index of each block of `a`.
353+
Return the last index of each block of `a`.
354+
355+
# Examples
356+
```jldoctest
357+
julia> b = blockedrange(1:3)
358+
3-blocked 6-element BlockedUnitRange{ArrayLayouts.RangeCumsum{Int64, UnitRange{Int64}}}:
359+
1
360+
361+
2
362+
3
363+
364+
4
365+
5
366+
6
367+
368+
julia> blocklasts(b)
369+
3-element ArrayLayouts.RangeCumsum{Int64, UnitRange{Int64}}:
370+
1
371+
3
372+
6
373+
```
292374
"""
293375
blocklasts(a::AbstractUnitRange{Int}) = Fill(length(a),1)
294376
"""
295377
blocklengths(a::AbstractUnitRange{Int})
296378
297-
returns the length of each block of `a`.
379+
Return the length of each block of `a`.
380+
381+
# Examples
382+
```jldoctest
383+
julia> b = blockedrange(1:3)
384+
3-blocked 6-element BlockedUnitRange{ArrayLayouts.RangeCumsum{Int64, UnitRange{Int64}}}:
385+
1
386+
387+
2
388+
3
389+
390+
4
391+
5
392+
6
393+
394+
julia> blocklengths(b)
395+
3-element Vector{Int64}:
396+
1
397+
2
398+
3
399+
```
298400
"""
299401
blocklengths(a::AbstractUnitRange) = blocklasts(a) .- blockfirsts(a) .+ 1
300402

src/blockindices.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A `Block` is simply a wrapper around a set of indices or enums so that it can be
55
indexing a `AbstractBlockArray` with a `Block` the a block at that block index will be returned instead of
66
a single element.
77
8-
```jldoctest; setup = quote using BlockArrays end
8+
```jldoctest
99
julia> A = BlockArray(ones(2,3), [1, 1], [2, 1])
1010
2×2-blocked 2×3 BlockMatrix{Float64}:
1111
1.0 1.0 │ 1.0
@@ -120,7 +120,7 @@ and the offset index into the block.
120120
121121
It can be used to index into `BlockArrays` in the following manner:
122122
123-
```jldoctest; setup = quote using BlockArrays end
123+
```jldoctest
124124
julia> arr = Array(reshape(1:25, (5,5)));
125125
126126
julia> a = PseudoBlockArray(arr, [3,2], [1,4])

src/blocklinalg.jl

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@ blockrowsupport(_, A, k) = blockaxes(A,2)
22
"""
33
blockrowsupport(A, k)
44
5-
gives an iterator containing the possible non-zero blocks in the k-th block-row of A.
5+
Return an iterator containing the possible non-zero blocks in the k-th block-row of A.
6+
7+
# Examples
8+
```jldoctest
9+
julia> B = BlockArray(collect(reshape(1:9, 3, 3)), [1,2], [1,2])
10+
2×2-blocked 3×3 BlockMatrix{Int64}:
11+
1 │ 4 7
12+
───┼──────
13+
2 │ 5 8
14+
3 │ 6 9
15+
16+
julia> BlockArrays.blockrowsupport(B, 2)
17+
2-element BlockRange{1, Tuple{Base.OneTo{Int64}}}:
18+
Block(1)
19+
Block(2)
20+
```
621
"""
722
blockrowsupport(A, k) = blockrowsupport(MemoryLayout(A), A, k)
823
blockrowsupport(A) = blockrowsupport(A, blockaxes(A,1))
@@ -12,7 +27,22 @@ blockcolsupport(_, A, j) = Block.(colsupport(blocks(A), Int.(j)))
1227
"""
1328
blockcolsupport(A, j)
1429
15-
gives an iterator containing the possible non-zero blocks in the j-th block-column of A.
30+
Return an iterator containing the possible non-zero blocks in the j-th block-column of A.
31+
32+
# Examples
33+
```jldoctest
34+
julia> B = BlockArray(collect(reshape(1:9, 3, 3)), [1,2], [1,2])
35+
2×2-blocked 3×3 BlockMatrix{Int64}:
36+
1 │ 4 7
37+
───┼──────
38+
2 │ 5 8
39+
3 │ 6 9
40+
41+
julia> BlockArrays.blockcolsupport(B, 2)
42+
2-element BlockRange{1, Tuple{Base.OneTo{Int64}}}:
43+
Block(1)
44+
Block(2)
45+
```
1646
"""
1747
blockcolsupport(A, j) = blockcolsupport(MemoryLayout(A), A, j)
1848
blockcolsupport(A) = blockcolsupport(A, blockaxes(A,2))

0 commit comments

Comments
 (0)