Skip to content

Commit 12fd8f7

Browse files
authored
Documentation fixes (#1268)
* Remove api.md and quickstart.md out of pages Only three markdown pages are made, and the current directory structure can be simplified. * Add import statement to quickstart.md * Use dynamic example and repl blocks in api.md * Add doctest setup for StaticArraysCore.jl See commit e9dbf325d69f in StaticArraysCore.jl * Fix docstring code formatting - Add backticks around declared code names - Fix spacing before method headers - Use fenced code blocks * Fix markdown lists Add spacing before list items so that markdown treats them as one list * Add type and method headers to docstrings * Add doctests
1 parent 31c09e9 commit 12fd8f7

File tree

12 files changed

+98
-71
lines changed

12 files changed

+98
-71
lines changed

docs/make.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ using StaticArrays
33
using StaticArraysCore
44

55
# Setup for doctests in docstrings
6-
DocMeta.setdocmeta!(StaticArrays, :DocTestSetup, :(using LinearAlgebra, StaticArrays))
6+
doctest_setup = :(using LinearAlgebra, StaticArrays)
7+
DocMeta.setdocmeta!(StaticArrays, :DocTestSetup, doctest_setup)
8+
DocMeta.setdocmeta!(StaticArraysCore, :DocTestSetup, doctest_setup)
79

810
makedocs(;
911
modules = [StaticArrays, StaticArraysCore],
@@ -13,8 +15,8 @@ makedocs(;
1315
),
1416
pages = [
1517
"Home" => "index.md",
16-
"API" => "pages/api.md",
17-
"Quick Start" => "pages/quickstart.md",
18+
"API" => "api.md",
19+
"Quick Start" => "quickstart.md",
1820
],
1921
sitename = "StaticArrays.jl",
2022
)

docs/src/pages/api.md renamed to docs/src/api.md

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,14 @@ could be represented as a `Vector{SVector{3,Float64}}`.
247247
Another common way of storing the same data is as a 3×`N` `Matrix{Float64}`.
248248
Rather conveniently, such types have *exactly* the same binary layout in memory,
249249
and therefore we can use `reinterpret` to convert between the two formats
250-
```julia
250+
```@example copy
251+
using StaticArrays # hide
251252
function svectors(x::Matrix{T}, ::Val{N}) where {T,N}
252253
size(x,1) == N || error("sizes mismatch")
253254
isbitstype(T) || error("use for bitstypes only")
254255
reinterpret(SVector{N,T}, vec(x))
255256
end
257+
nothing # hide
256258
```
257259
Such a conversion does not copy the data, rather it refers to the *same* memory.
258260
Arguably, a `Vector` of `SVector`s is often preferable to a `Matrix` because it
@@ -263,31 +265,19 @@ However, the resulting object is a Base.ReinterpretArray, not an Array, which
263265
carries some runtime penalty on every single access. If you can afford the
264266
memory for a copy and can live with the non-shared mutation semantics, then it
265267
is better to pull a copy by e.g.
266-
```julia
268+
```@example copy
267269
function svectorscopy(x::Matrix{T}, ::Val{N}) where {T,N}
268270
size(x,1) == N || error("sizes mismatch")
269271
isbitstype(T) || error("use for bitstypes only")
270272
copy(reinterpret(SVector{N,T}, vec(x)))
271273
end
274+
nothing # hide
272275
```
273276
For example:
274-
```
275-
julia> M=reshape(collect(1:6), (2,3))
276-
2×3 Array{Int64,2}:
277-
1 3 5
278-
2 4 6
279-
280-
julia> svectors(M, Val{2}())
281-
3-element reinterpret(SArray{Tuple{2},Int64,1,2}, ::Array{Int64,1}):
282-
[1, 2]
283-
[3, 4]
284-
[5, 6]
285-
286-
julia> svectorscopy(M, Val{2}())
287-
3-element Array{SArray{Tuple{2},Int64,1,2},1}:
288-
[1, 2]
289-
[3, 4]
290-
[5, 6]
277+
```@repl copy
278+
M = reshape(collect(1:6), (2,3))
279+
svectors(M, Val{2}())
280+
svectorscopy(M, Val{2}())
291281
```
292282

293283
### Working with mutable and immutable arrays

docs/src/pages/quickstart.md renamed to docs/src/quickstart.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Quick Start
22

33
```julia
4+
import Pkg
45
Pkg.add("StaticArrays") # or Pkg.clone("https://github.com/JuliaArrays/StaticArrays.jl")
56
using StaticArrays
67
using LinearAlgebra

src/SArray.jl

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,29 @@ shape_string(inds::CartesianIndex) = join(Tuple(inds), '×')
2828
Expr(:block, stmts...)
2929
end
3030
"""
31-
sacollect(SA, gen)
31+
sacollect(SA, gen)
3232
3333
Construct a statically-sized vector of type `SA`.from a generator
3434
`gen`. `SA` needs to have a size parameter since the length of `vec`
3535
is unknown to the compiler. `SA` can optionally specify the element
3636
type as well.
3737
3838
Example:
39-
40-
sacollect(SVector{3, Int}, 2i+1 for i in 1:3)
41-
sacollect(SMatrix{2, 3}, i+j for i in 1:2, j in 1:3)
42-
sacollect(SArray{2, 3}, i+j for i in 1:2, j in 1:3)
39+
```julia
40+
sacollect(SVector{3, Int}, 2i+1 for i in 1:3)
41+
sacollect(SMatrix{2, 3}, i+j for i in 1:2, j in 1:3)
42+
sacollect(SArray{2, 3}, i+j for i in 1:2, j in 1:3)
43+
```
4344
4445
This creates the same statically-sized vector as if the generator were
4546
collected in an array, but is more efficient since no array is
4647
allocated.
4748
4849
Equivalent:
4950
50-
SVector{3, Int}([2i+1 for i in 1:3])
51+
```julia
52+
SVector{3, Int}([2i+1 for i in 1:3])
53+
```
5154
"""
5255
sacollect
5356

@@ -304,19 +307,19 @@ end
304307
A convenience macro to construct `SArray` with arbitrary dimension.
305308
It supports:
306309
1. (typed) array literals.
307-
!!! note
308-
Every argument inside the square brackets is treated as a scalar during expansion.
309-
Thus `@SArray[a; b]` always forms a `SVector{2}` and `@SArray [a b; c]` always throws
310-
an error.
310+
!!! note
311+
Every argument inside the square brackets is treated as a scalar during expansion.
312+
Thus `@SArray[a; b]` always forms a `SVector{2}` and `@SArray [a b; c]` always throws
313+
an error.
311314
312315
2. comprehensions
313-
!!! note
314-
The range of a comprehension is evaluated at global scope by the macro, and must be
315-
made of combinations of literal values, functions, or global variables.
316+
!!! note
317+
The range of a comprehension is evaluated at global scope by the macro, and must be
318+
made of combinations of literal values, functions, or global variables.
316319
317320
3. initialization functions
318-
!!! note
319-
Only support `zeros()`, `ones()`, `fill()`, `rand()`, `randn()`, and `randexp()`
321+
!!! note
322+
Only support `zeros()`, `ones()`, `fill()`, `rand()`, `randn()`, and `randexp()`
320323
"""
321324
macro SArray(ex)
322325
static_array_gen(SArray, ex, __module__)

src/arraymath.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ end
182182
"""
183183
arithmetic_closure(T)
184184
185-
Return the type which values of type `T` will promote to under a combination of the arithmetic operations `+, -, *` and `/`.
185+
Return the type which values of type `T` will promote to under a combination of the arithmetic operations `+`, `-`, `*` and `/`.
186186
187187
```jldoctest
188188
julia> import StaticArrays.arithmetic_closure

src/convert.jl

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,29 @@ The adaption rules for official `StaticArray`s could be summarized as:
6060
6161
# `SA <: Union{SArray, MArray, SHermitianCompact, SizedArray}`: `size`/`eltype` adaptable
6262
63-
- SA(x::Tuple)
64-
If `SA` is fully static-sized, then we first try to fill `SA` with `x`'s elements.
65-
If failed and `length(SA) == 1`, then we try to fill `SA` with `x` itself.
66-
67-
If `SA` is not fully static-sized, then we always try to fill `SA` with `x`'s elements,
68-
and the constructor's `Size` is derived based on:
69-
1. If `SA <: StaticVector`, then we use `length(x)` as the output `Length`
70-
2. If `SA <: StaticMatrix{M}`, then we use `(M, N)` (`N = length(x) ÷ M`) as the output `Size`
71-
3. If `SA <: StaticMatrix{M,M} where M`, then we use `(N, N)` (`N = sqrt(length(x)`) as the output `Size`.
72-
- SA(x...)
73-
Similar to `Tuple`, but we never fill `SA` with `x` itself.
74-
- SA(x::StaticArray)
75-
We treat `x` as `Tuple` whenever possible. If failed, then try to inherit `x`'s `Size`.
76-
- SA(x::AbstractArray)
77-
`x` is used to provide eltype. Thus `SA` must be static sized.
63+
- `SA(x::Tuple)`
64+
65+
If `SA` is fully static-sized, then we first try to fill `SA` with `x`'s elements.
66+
If failed and `length(SA) == 1`, then we try to fill `SA` with `x` itself.
67+
68+
If `SA` is not fully static-sized, then we always try to fill `SA` with `x`'s elements,
69+
and the constructor's `Size` is derived based on:
70+
1. If `SA <: StaticVector`, then we use `length(x)` as the output `Length`
71+
2. If `SA <: StaticMatrix{M}`, then we use `(M, N)` (`N = length(x) ÷ M`) as the output `Size`
72+
3. If `SA <: StaticMatrix{M,M} where M`, then we use `(N, N)` (`N = sqrt(length(x)`) as the output `Size`.
73+
74+
- `SA(x...)`
75+
76+
Similar to `Tuple`, but we never fill `SA` with `x` itself.
77+
78+
- `SA(x::StaticArray)`
79+
80+
We treat `x` as `Tuple` whenever possible. If failed, then try to inherit `x`'s `Size`.
81+
82+
- `SA(x::AbstractArray)`
83+
84+
`x` is used to provide eltype. Thus `SA` must be static sized.
85+
7886
"""
7987
function construct_type(::Type{SA}, x) where {SA<:StaticArray}
8088
x isa BadArgs || return SA

src/initializers.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ provided explicitly.
99
# Examples:
1010
1111
* `SA[1.0, 2.0]` creates a length-2 `SVector` of `Float64` elements.
12-
* `SA[1 2; 3 4]` creates a 2×2 SMatrix of `Int`s.
13-
* `SA[1 2]` creates a 1×2 SMatrix of `Int`s.
12+
* `SA[1 2; 3 4]` creates a 2×2 `SMatrix` of `Int`s.
13+
* `SA[1 2]` creates a 1×2 `SMatrix` of `Int`s.
1414
* `SA{Float32}[1, 2]` creates a length-2 `SVector` of `Float32` elements.
1515
1616
A couple of helpful type aliases are also provided:

src/mapreduce.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ A singleton type for representing "universal" initial value (identity element).
66
The idea is that, given `op` for `mapfoldl`, virtually, we define an "extended"
77
version of it by
88
9-
op′(::_InitialValue, x) = x
10-
op′(acc, x) = op(acc, x)
9+
```julia
10+
op′(::_InitialValue, x) = x
11+
op′(acc, x) = op(acc, x)
12+
```
1113
1214
This is just a conceptually useful model to have in mind and we don't actually
1315
define `op′` here (yet?). But see `Base.BottomRF` for how it might work in

src/matrix_multiply.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import LinearAlgebra: BlasFloat, matprod, mul!
1919
mul_result_structure(a::Type, b::Type)
2020
2121
Get a structure wrapper that should be applied to the result of multiplication of matrices
22-
of given types (a*b).
22+
of given types (`a*b`).
2323
"""
2424
function mul_result_structure(a, b)
2525
return identity

src/matrix_multiply_add.jl

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ end
8787
"""
8888
gen_by_access(expr_gen, a::Type{<:AbstractArray}, b::Type{<:AbstractArray})
8989
90-
Similar to gen_by_access with only one type argument. The difference is that tests for both
90+
Similar to `gen_by_access` with only one type argument. The difference is that tests for both
9191
arrays of type `a` and `b` are generated and `expr_gen` receives two access arguments,
9292
first for matrix `a` and the second for matrix `b`.
9393
"""
@@ -175,7 +175,10 @@ function gen_by_access(expr_gen, a::Type{<:Diagonal{<:Any, <:StaticVector}}, b::
175175
end
176176

177177

178-
""" Size that stores whether a Matrix is a Transpose
178+
"""
179+
TSize{S,T}
180+
181+
Size that stores whether a Matrix is a Transpose.
179182
Useful when selecting multiplication methods, and avoiding allocations when dealing with
180183
the `Transpose` type by passing around the original matrix.
181184
Should pair with `parent`.
@@ -245,11 +248,19 @@ const StaticVecOrMatLikeForFiveArgMulDest{T} = Union{
245248
return _mul!(TSize(dest), mul_parent(dest), Size(A), Size(B), A, B, NoMulAdd{TMul, TDest}())
246249
end
247250

248-
"Calculate the product of the dimensions being multiplied. Useful as a heuristic for unrolling."
251+
"""
252+
multiplied_dimension(A, B)
253+
254+
Calculate the product of the dimensions being multiplied. Useful as a heuristic for unrolling.
255+
"""
249256
@inline multiplied_dimension(A::Type{<:StaticVecOrMatLike}, B::Type{<:StaticVecOrMatLike}) =
250257
prod(size(A)) * size(B,2)
251258

252-
"Validate the dimensions of a matrix multiplication, including matrix-vector products"
259+
"""
260+
check_dims(sc, sa, sb)
261+
262+
Validate the dimensions of a matrix multiplication, including matrix-vector products
263+
"""
253264
function check_dims(::Size{sc}, ::Size{sa}, ::Size{sb}) where {sa,sb,sc}
254265
if sb[1] != sa[2] || sc[1] != sa[1]
255266
return false
@@ -356,10 +367,12 @@ function uplo_access(sa, asym, k, j, uplo)
356367
end
357368
end
358369

359-
""" Combine left and right sides of an assignment expression, short-cutting
360-
lhs = α * rhs + β * lhs,
361-
element-wise.
362-
If α = 1, the multiplication by α is removed. If β = 0, the second rhs term is removed.
370+
"""
371+
_muladd_expr(lhs, rhs, coeffs)
372+
373+
Combine left and right sides of an assignment expression, short-cutting
374+
`lhs = α * rhs + β * lhs`, element-wise.
375+
If `α = 1`, the multiplication by `α` is removed. If `β = 0`, the second `rhs` term is removed.
363376
"""
364377
function _muladd_expr(lhs::Array{Expr}, rhs::Array{Expr}, ::Type{<:AlphaBeta})
365378
@assert length(lhs) == length(rhs)
@@ -378,7 +391,11 @@ end
378391
[:($(lhs[k]) = $(rhs[k])) for k = 1:length(lhs)]
379392
end
380393

381-
"Obtain an expression for the linear index of var[k,j], taking transposes into account"
394+
"""
395+
_lind(var, A, k, j)
396+
397+
Obtain an expression for the linear index of `var[k,j]`, taking transposes into account.
398+
"""
382399
function _lind(var::Symbol, A::Type{TSize{sa,tA}}, k::Int, j::Int) where {sa,tA}
383400
ula = uplo_access(sa, var, k, j, tA)
384401
if ula.head == :call && ula.args[1] == :transpose

0 commit comments

Comments
 (0)