Skip to content

Commit f2b4ce0

Browse files
authored
Merge branch 'JuliaArrays:master' into master
2 parents 68255c5 + 7708986 commit f2b4ce0

File tree

19 files changed

+167
-78
lines changed

19 files changed

+167
-78
lines changed

.github/workflows/Invalidations.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ jobs:
3636
echo "Invalidations on default branch: ${{ steps.invs_default.outputs.total }} (${{ steps.invs_default.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
3737
echo "This branch: ${{ steps.invs_pr.outputs.total }} (${{ steps.invs_pr.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
3838
- name: Check if the PR does increase number of invalidations
39-
if: steps.invs_pr.outputs.total > steps.invs_default.outputs.total
40-
run: exit 1
39+
run: |
40+
if [ ${{ steps.invs_pr.outputs.total }} -gt ${{ steps.invs_default.outputs.total }} ]; then
41+
exit 1
42+
fi

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StaticArrays"
22
uuid = "90137ffa-7385-5640-81b9-e52037218182"
3-
version = "1.9.6"
3+
version = "1.9.7"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

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
)
Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ additional loop unrolling and inlining, and consequentially (c) their mutating
140140
methods like `map!` are extremely fast. Benchmarking shows that operations such
141141
as addition and matrix multiplication are faster for `MMatrix` than `Matrix`,
142142
at least for sizes up to 14 × 14, though keep in mind that optimal speed will
143-
be obtained by using mutating functions (like `map!` or `A_mul_B!`) where
143+
be obtained by using mutating functions (like `map!` or `mul!`) where
144144
possible, rather than reallocating new memory.
145145

146146
Mutable static arrays also happen to be very useful containers that can be
@@ -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
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/StaticArrays.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ using LinearAlgebra
1616
import LinearAlgebra: transpose, adjoint, dot, eigvals, eigen, lyap, tr,
1717
kron, diag, norm, dot, diagm, lu, svd, svdvals, pinv,
1818
factorize, ishermitian, issymmetric, isposdef, issuccess, normalize,
19-
normalize!, Eigen, det, logdet, logabsdet, cross, diff, qr, \
19+
normalize!, Eigen, det, logdet, logabsdet, cross, diff, qr, \,
20+
triu, tril
2021
using LinearAlgebra: checksquare
2122

2223
using PrecompileTools

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:

0 commit comments

Comments
 (0)