StaticArrays.StaticMatMulLike
— TypeStaticMatMulLike
Static wrappers used for multiplication dispatch.
diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 3a46b032..1be7d4f3 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.6.7","generation_timestamp":"2024-07-15T09:22:22","documenter_version":"1.5.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.6.7","generation_timestamp":"2024-07-29T17:29:30","documenter_version":"1.5.0"}} \ No newline at end of file diff --git a/dev/api/index.html b/dev/api/index.html index 0be3df19..04207ea2 100644 --- a/dev/api/index.html +++ b/dev/api/index.html @@ -9,7 +9,7 @@ SizedMatrix{3,3}(rand(3,3)) # Construct a random 3×3 SizedArray (see below)
Statically sized indexing can be realized by indexing each dimension by a scalar, a StaticVector
or :
. Indexing in this way will result a statically sized array (even if the input was dynamically sized, in the case of StaticVector
indices) of the closest type (as defined by similar_type
).
Conversely, indexing a statically sized array with a dynamically sized index (such as a Vector{Integer}
or UnitRange{Integer}
) will result in a standard (dynamically sized) Array
.
similar_type()
Since immutable arrays need to be constructed "all-at-once", we need a way of obtaining an appropriate constructor if the element type or dimensions of the output array differs from the input. To this end, similar_type
is introduced, behaving just like similar
, except that it returns a type. Relevant methods are:
similar_type(::Type{A}) where {A <: StaticArray} # defaults to A
similar_type(::Type{A}, ::Type{ElType}) where {A <: StaticArray, ElType} # Change element type
similar_type(::Type{A}, size::Size) where {A <: AbstractArray} # Change size
-similar_type(::Type{A}, ::Type{ElType}, size::Size) where {A <: AbstractArray, ElType} # Change both
These setting will affect everything, from indexing, to matrix multiplication and broadcast
. Users wanting introduce a new array type should only overload the last method in the above.
Use of similar
will fall back to a mutable container, such as a MVector
(see below), and it requires use of the Size
trait if you wish to set a new static size (or else a dynamically sized Array
will be generated when specifying the size as plain integers).
You can collect iterators into static arrays directly with StaticArrays.sacollect
. The size needs to be specified, but the element type is optional.
MVector
, MMatrix
and MArray
These statically sized arrays are identical to the above, but are defined as mutable struct
s, instead of immutable struct
s. Because they are mutable, they allow setindex!
to be defined (achieved through pointer manipulation, into a tuple).
As a consequence of Julia's internal implementation, these mutable containers live on the heap, not the stack. Their memory must be allocated and tracked by the garbage collector. Nevertheless, there is opportunity for speed improvements relative to Base.Array
because (a) there may be one less pointer indirection, (b) their (typically small) static size allows for additional loop unrolling and inlining, and consequentially (c) their mutating methods like map!
are extremely fast. Benchmarking shows that operations such as addition and matrix multiplication are faster for MMatrix
than Matrix
, at least for sizes up to 14 × 14, though keep in mind that optimal speed will be obtained by using mutating functions (like map!
or A_mul_B!
) where possible, rather than reallocating new memory.
Mutable static arrays also happen to be very useful containers that can be constructed on the heap (with the ability to use setindex!
, etc), and later copied as e.g. an immutable SVector
to the stack for use, or into e.g. an Array{SVector}
for storage.
Convenience macros @MVector
, @MMatrix
and @MArray
are provided.
SizedArray
: a decorate size wrapper for Array
Another convenient mutable type is the SizedArray
, which is just a wrapper-type about a standard Julia Array
which declares its known size. For example, if we knew that a
was a 2×2 Matrix
, then we can type sa = SizedArray{Tuple{2,2}}(a)
to construct a new object which knows the type (the size will be verified automatically). For one and two dimensions, a more convenient syntax for obtaining a SizedArray
is by using the SizedMatrix
and SizedVector
aliases, e.g. sa = SizedMatrix{2,2}(a)
.
Then, methods on sa
will use the specialized code provided by the StaticArrays package, which in many cases will be much, much faster. For example, calling eigen(sa)
will be significantly faster than eigen(a)
since it will perform a specialized 2×2 matrix diagonalization rather than a general algorithm provided by Julia and LAPACK.
In some cases it will make more sense to use a SizedArray
, and in other cases an MArray
might be preferable.
FieldVector
Sometimes it is useful to give your own struct types the properties of a vector. StaticArrays can take care of this for you by allowing you to inherit from FieldVector{N, T}
. For example, consider:
struct Point3D <: FieldVector{3, Float64}
+similar_type(::Type{A}, ::Type{ElType}, size::Size) where {A <: AbstractArray, ElType} # Change both
These setting will affect everything, from indexing, to matrix multiplication and broadcast
. Users wanting introduce a new array type should only overload the last method in the above.
Use of similar
will fall back to a mutable container, such as a MVector
(see below), and it requires use of the Size
trait if you wish to set a new static size (or else a dynamically sized Array
will be generated when specifying the size as plain integers).
You can collect iterators into static arrays directly with StaticArrays.sacollect
. The size needs to be specified, but the element type is optional.
MVector
, MMatrix
and MArray
These statically sized arrays are identical to the above, but are defined as mutable struct
s, instead of immutable struct
s. Because they are mutable, they allow setindex!
to be defined (achieved through pointer manipulation, into a tuple).
As a consequence of Julia's internal implementation, these mutable containers live on the heap, not the stack. Their memory must be allocated and tracked by the garbage collector. Nevertheless, there is opportunity for speed improvements relative to Base.Array
because (a) there may be one less pointer indirection, (b) their (typically small) static size allows for additional loop unrolling and inlining, and consequentially (c) their mutating methods like map!
are extremely fast. Benchmarking shows that operations such as addition and matrix multiplication are faster for MMatrix
than Matrix
, at least for sizes up to 14 × 14, though keep in mind that optimal speed will be obtained by using mutating functions (like map!
or mul!
) where possible, rather than reallocating new memory.
Mutable static arrays also happen to be very useful containers that can be constructed on the heap (with the ability to use setindex!
, etc), and later copied as e.g. an immutable SVector
to the stack for use, or into e.g. an Array{SVector}
for storage.
Convenience macros @MVector
, @MMatrix
and @MArray
are provided.
SizedArray
: a decorate size wrapper for Array
Another convenient mutable type is the SizedArray
, which is just a wrapper-type about a standard Julia Array
which declares its known size. For example, if we knew that a
was a 2×2 Matrix
, then we can type sa = SizedArray{Tuple{2,2}}(a)
to construct a new object which knows the type (the size will be verified automatically). For one and two dimensions, a more convenient syntax for obtaining a SizedArray
is by using the SizedMatrix
and SizedVector
aliases, e.g. sa = SizedMatrix{2,2}(a)
.
Then, methods on sa
will use the specialized code provided by the StaticArrays package, which in many cases will be much, much faster. For example, calling eigen(sa)
will be significantly faster than eigen(a)
since it will perform a specialized 2×2 matrix diagonalization rather than a general algorithm provided by Julia and LAPACK.
In some cases it will make more sense to use a SizedArray
, and in other cases an MArray
might be preferable.
FieldVector
Sometimes it is useful to give your own struct types the properties of a vector. StaticArrays can take care of this for you by allowing you to inherit from FieldVector{N, T}
. For example, consider:
struct Point3D <: FieldVector{3, Float64}
x::Float64
y::Float64
z::Float64
@@ -58,11 +58,11 @@
v = zero(MVector{N,T})
v[I] = one(T)
SVector(v)
-end
It seems Julia and LLVM are smart enough to use processor vectorization extensions like SSE and AVX - however they are currently partially disabled by default. Run Julia with julia -O
or julia -O3
to enable these optimizations, and many of your (immutable) StaticArray
methods should become significantly faster!
StaticArrays.Args
StaticArrays.SA
StaticArrays.SHermitianCompact
StaticArrays.SOneTo
StaticArrays.Scalar
StaticArrays.StaticMatMulLike
StaticArrays.TSize
StaticArrays._InitialValue
StaticArraysCore.Dynamic
StaticArraysCore.FieldArray
StaticArraysCore.FieldMatrix
StaticArraysCore.FieldVector
StaticArraysCore.MArray
StaticArraysCore.MMatrix
StaticArraysCore.MVector
StaticArraysCore.SArray
StaticArraysCore.SMatrix
StaticArraysCore.SVector
StaticArraysCore.Size
StaticArraysCore.SizedArray
StaticArraysCore.SizedMatrix
StaticArraysCore.SizedVector
StaticArraysCore.StaticArray
Base.setindex
Base.similar
LinearAlgebra.qr
StaticArrays._construct_similar
StaticArrays._lind
StaticArrays._muladd_expr
StaticArrays._size
StaticArrays.arithmetic_closure
StaticArrays.check_dims
StaticArrays.construct_type
StaticArrays.deleteat
StaticArrays.dimmatch
StaticArrays.gen_by_access
StaticArrays.gen_by_access
StaticArrays.insert
StaticArrays.mul_result_structure
StaticArrays.multiplied_dimension
StaticArrays.pop
StaticArrays.popfirst
StaticArrays.push
StaticArrays.pushfirst
StaticArrays.sacollect
StaticArrays.same_size
StaticArrays.sizematch
StaticArrays.sizematch
StaticArrays.uplo_access
StaticArraysCore.similar_type
StaticArraysCore.size_to_tuple
StaticArrays.@MArray
StaticArrays.@MMatrix
StaticArrays.@MVector
StaticArrays.@SArray
StaticArrays.@SMatrix
StaticArrays.@SVector
StaticArrays.StaticMatMulLike
— TypeStaticMatMulLike
Static wrappers used for multiplication dispatch.
StaticArrays.Args
— TypeArgs
A help wrapper to distinguish SA(x...)
and SA((x...,))
StaticArrays.SA
— TypeSA[ elements ]
-SA{T}[ elements ]
Create SArray
literals using array construction syntax. The element type is inferred by promoting elements
to a common type or set to T
when T
is provided explicitly.
Examples:
SA[1.0, 2.0]
creates a length-2 SVector
of Float64
elements.SA[1 2; 3 4]
creates a 2×2 SMatrix
of Int
s.SA[1 2]
creates a 1×2 SMatrix
of Int
s.SA{Float32}[1, 2]
creates a length-2 SVector
of Float32
elements.A couple of helpful type aliases are also provided:
SA_F64[1, 2]
creates a length-2 SVector
of Float64
elementsSA_F32[1, 2]
creates a length-2 SVector
of Float32
elementsStaticArrays.SHermitianCompact
— TypeSHermitianCompact{N, T, L} <: StaticMatrix{N, N, T}
A StaticArray
subtype that can represent a Hermitian matrix. Unlike LinearAlgebra.Hermitian
, SHermitianCompact
stores only the lower triangle of the matrix (as an SVector
), and the diagonal may not be real. The lower triangle is stored in column-major order and the superdiagonal entries are adjoint
to the transposed subdiagonal entries. The diagonal is returned as-is. For example, for an SHermitianCompact{3}
, the indices of the stored elements can be visualized as follows:
┌ 1 ⋅ ⋅ ┐
+end
It seems Julia and LLVM are smart enough to use processor vectorization extensions like SSE and AVX - however they are currently partially disabled by default. Run Julia with julia -O
or julia -O3
to enable these optimizations, and many of your (immutable) StaticArray
methods should become significantly faster!
StaticArrays.Args
StaticArrays.SA
StaticArrays.SHermitianCompact
StaticArrays.SOneTo
StaticArrays.Scalar
StaticArrays.StaticMatMulLike
StaticArrays.TSize
StaticArrays._InitialValue
StaticArraysCore.Dynamic
StaticArraysCore.FieldArray
StaticArraysCore.FieldMatrix
StaticArraysCore.FieldVector
StaticArraysCore.MArray
StaticArraysCore.MMatrix
StaticArraysCore.MVector
StaticArraysCore.SArray
StaticArraysCore.SMatrix
StaticArraysCore.SVector
StaticArraysCore.Size
StaticArraysCore.SizedArray
StaticArraysCore.SizedMatrix
StaticArraysCore.SizedVector
StaticArraysCore.StaticArray
Base.setindex
Base.similar
LinearAlgebra.qr
StaticArrays._construct_similar
StaticArrays._lind
StaticArrays._muladd_expr
StaticArrays._size
StaticArrays.arithmetic_closure
StaticArrays.check_dims
StaticArrays.construct_type
StaticArrays.deleteat
StaticArrays.dimmatch
StaticArrays.gen_by_access
StaticArrays.gen_by_access
StaticArrays.insert
StaticArrays.mul_result_structure
StaticArrays.multiplied_dimension
StaticArrays.pop
StaticArrays.popfirst
StaticArrays.push
StaticArrays.pushfirst
StaticArrays.sacollect
StaticArrays.same_size
StaticArrays.sizematch
StaticArrays.sizematch
StaticArrays.uplo_access
StaticArraysCore.similar_type
StaticArraysCore.size_to_tuple
StaticArrays.@MArray
StaticArrays.@MMatrix
StaticArrays.@MVector
StaticArrays.@SArray
StaticArrays.@SMatrix
StaticArrays.@SVector
StaticArrays.StaticMatMulLike
— TypeStaticMatMulLike
Static wrappers used for multiplication dispatch.
StaticArrays.Args
— TypeArgs
A help wrapper to distinguish SA(x...)
and SA((x...,))
StaticArrays.SA
— TypeSA[ elements ]
+SA{T}[ elements ]
Create SArray
literals using array construction syntax. The element type is inferred by promoting elements
to a common type or set to T
when T
is provided explicitly.
Examples:
SA[1.0, 2.0]
creates a length-2 SVector
of Float64
elements.SA[1 2; 3 4]
creates a 2×2 SMatrix
of Int
s.SA[1 2]
creates a 1×2 SMatrix
of Int
s.SA{Float32}[1, 2]
creates a length-2 SVector
of Float32
elements.A couple of helpful type aliases are also provided:
SA_F64[1, 2]
creates a length-2 SVector
of Float64
elementsSA_F32[1, 2]
creates a length-2 SVector
of Float32
elementsStaticArrays.SHermitianCompact
— TypeSHermitianCompact{N, T, L} <: StaticMatrix{N, N, T}
A StaticArray
subtype that can represent a Hermitian matrix. Unlike LinearAlgebra.Hermitian
, SHermitianCompact
stores only the lower triangle of the matrix (as an SVector
), and the diagonal may not be real. The lower triangle is stored in column-major order and the superdiagonal entries are adjoint
to the transposed subdiagonal entries. The diagonal is returned as-is. For example, for an SHermitianCompact{3}
, the indices of the stored elements can be visualized as follows:
┌ 1 ⋅ ⋅ ┐
| 2 4 ⋅ |
-└ 3 5 6 ┘
Type parameters:
N
: matrix dimension;T
: element type for lower triangle;L
: length of the SVector
storing the lower triangular elements.Note that L
is always the N
th triangular number.
An SHermitianCompact
may be constructed either:
AbstractVector
containing the lower triangular elements; orTuple
containing both upper and lower triangular elements in column major order; orStaticMatrix
.For the latter two cases, only the lower triangular elements are used; the upper triangular elements are ignored.
When its element type is real, then a SHermitianCompact
is both Hermitian and symmetric. Otherwise, to ensure that a SHermitianCompact
matrix, a
, is Hermitian according to LinearAlgebra.ishermitian
, take an average with its adjoint, i.e. (a+a')/2
, or take a Hermitian view of the data with LinearAlgebra.Hermitian(a)
. However, the latter case is not specialized to use the compact storage.
StaticArrays.SOneTo
— TypeSOneTo(n)
Return a statically-sized AbstractUnitRange
starting at 1
, functioning as the axes
of a StaticArray
.
StaticArrays.Scalar
— TypeScalar{T}(x::T)
Construct a statically-sized 0-dimensional array that contains a single element, x
. This type is particularly useful for influencing broadcasting operations.
StaticArrays.TSize
— TypeTSize{S,T}
Size that stores whether a Matrix is a Transpose. Useful when selecting multiplication methods, and avoiding allocations when dealing with the Transpose
type by passing around the original matrix. Should pair with parent
.
StaticArrays._InitialValue
— Type_InitialValue
A singleton type for representing "universal" initial value (identity element).
The idea is that, given op
for mapfoldl
, virtually, we define an "extended" version of it by
op′(::_InitialValue, x) = x
-op′(acc, x) = op(acc, x)
This is just a conceptually useful model to have in mind and we don't actually define op′
here (yet?). But see Base.BottomRF
for how it might work in action.
(It is related to that you can always turn a semigroup without an identity into a monoid by "adjoining" an element that acts as the identity.)
Base.setindex
— Methodsetindex(vec::StaticArray, x, index::Int)
Return a new array with the item at index
replaced by x
.
Examples
julia> setindex(@SVector[1,2,3], 4, 2)
+└ 3 5 6 ┘
Type parameters:
N
: matrix dimension;T
: element type for lower triangle;L
: length of the SVector
storing the lower triangular elements.Note that L
is always the N
th triangular number.
An SHermitianCompact
may be constructed either:
AbstractVector
containing the lower triangular elements; orTuple
containing both upper and lower triangular elements in column major order; orStaticMatrix
.For the latter two cases, only the lower triangular elements are used; the upper triangular elements are ignored.
When its element type is real, then a SHermitianCompact
is both Hermitian and symmetric. Otherwise, to ensure that a SHermitianCompact
matrix, a
, is Hermitian according to LinearAlgebra.ishermitian
, take an average with its adjoint, i.e. (a+a')/2
, or take a Hermitian view of the data with LinearAlgebra.Hermitian(a)
. However, the latter case is not specialized to use the compact storage.
StaticArrays.SOneTo
— TypeSOneTo(n)
Return a statically-sized AbstractUnitRange
starting at 1
, functioning as the axes
of a StaticArray
.
StaticArrays.Scalar
— TypeScalar{T}(x::T)
Construct a statically-sized 0-dimensional array that contains a single element, x
. This type is particularly useful for influencing broadcasting operations.
StaticArrays.TSize
— TypeTSize{S,T}
Size that stores whether a Matrix is a Transpose. Useful when selecting multiplication methods, and avoiding allocations when dealing with the Transpose
type by passing around the original matrix. Should pair with parent
.
StaticArrays._InitialValue
— Type_InitialValue
A singleton type for representing "universal" initial value (identity element).
The idea is that, given op
for mapfoldl
, virtually, we define an "extended" version of it by
op′(::_InitialValue, x) = x
+op′(acc, x) = op(acc, x)
This is just a conceptually useful model to have in mind and we don't actually define op′
here (yet?). But see Base.BottomRF
for how it might work in action.
(It is related to that you can always turn a semigroup without an identity into a monoid by "adjoining" an element that acts as the identity.)
Base.setindex
— Methodsetindex(vec::StaticArray, x, index::Int)
Return a new array with the item at index
replaced by x
.
Examples
julia> setindex(@SVector[1,2,3], 4, 2)
3-element SVector{3, Int64} with indices SOneTo(3):
1
4
@@ -71,10 +71,10 @@
julia> setindex(@SMatrix[2 4; 6 8], 1, 2)
2×2 SMatrix{2, 2, Int64, 4} with indices SOneTo(2)×SOneTo(2):
2 4
- 1 8
Base.similar
— Methodsimilar(static_array)
+ 1 8
Base.similar
— Methodsimilar(static_array)
similar(static_array, T)
similar(array, ::Size)
-similar(array, T, ::Size)
Constructs and returns a mutable but statically-sized array (i.e. a StaticArray
). If the input array
is not a StaticArray
, then the Size
is required to determine the output size (or else a dynamically sized array will be returned).
LinearAlgebra.qr
— Methodqr(A::StaticMatrix,
+similar(array, T, ::Size)
Constructs and returns a mutable but statically-sized array (i.e. a StaticArray
). If the input array
is not a StaticArray
, then the Size
is required to determine the output size (or else a dynamically sized array will be returned).
LinearAlgebra.qr
— Methodqr(A::StaticMatrix,
pivot::Union{Val{true}, Val{false}, LinearAlgebra.PivotingStrategy} = Val(false))
Compute the QR factorization of A
. The factors can be obtained by iteration:
julia> A = @SMatrix rand(3,4);
julia> Q, R = qr(A);
@@ -83,7 +83,7 @@
true
or by using getfield
:
julia> F = qr(A);
julia> F.Q * F.R ≈ A
-true
StaticArrays._construct_similar
— Method_construct_similar(a, ::Size, elements::NTuple)
Construct a static array of similar type to a
with the given elements
.
When a
is an instance or a concrete type the element type eltype(a)
is used. However, when a
is a UnionAll
type such as SMatrix{2,2}
, the promoted type of elements
is used instead.
StaticArrays._lind
— Method_lind(var, A, k, j)
Obtain an expression for the linear index of var[k,j]
, taking transposes into account.
StaticArrays._muladd_expr
— Method_muladd_expr(lhs, rhs, coeffs)
Combine left and right sides of an assignment expression, short-cutting lhs = α * rhs + β * lhs
, element-wise. If α = 1
, the multiplication by α
is removed. If β = 0
, the second rhs
term is removed.
StaticArrays._size
— Method_size(a)
Return either the statically known Size()
or runtime size()
StaticArrays.arithmetic_closure
— Methodarithmetic_closure(T)
Return the type which values of type T
will promote to under a combination of the arithmetic operations +
, -
, *
and /
.
julia> import StaticArrays.arithmetic_closure
+true
StaticArrays._construct_similar
— Method_construct_similar(a, ::Size, elements::NTuple)
Construct a static array of similar type to a
with the given elements
.
When a
is an instance or a concrete type the element type eltype(a)
is used. However, when a
is a UnionAll
type such as SMatrix{2,2}
, the promoted type of elements
is used instead.
StaticArrays._lind
— Method_lind(var, A, k, j)
Obtain an expression for the linear index of var[k,j]
, taking transposes into account.
StaticArrays._muladd_expr
— Method_muladd_expr(lhs, rhs, coeffs)
Combine left and right sides of an assignment expression, short-cutting lhs = α * rhs + β * lhs
, element-wise. If α = 1
, the multiplication by α
is removed. If β = 0
, the second rhs
term is removed.
StaticArrays._size
— Method_size(a)
Return either the statically known Size()
or runtime size()
StaticArrays.arithmetic_closure
— Methodarithmetic_closure(T)
Return the type which values of type T
will promote to under a combination of the arithmetic operations +
, -
, *
and /
.
julia> import StaticArrays.arithmetic_closure
julia> arithmetic_closure(Bool)
Float64
@@ -95,56 +95,56 @@
BigFloat
julia> arithmetic_closure(BigInt)
-BigFloat
StaticArrays.check_dims
— Methodcheck_dims(sc, sa, sb)
Validate the dimensions of a matrix multiplication, including matrix-vector products
StaticArrays.construct_type
— MethodSA′ = construct_type(::Type{SA}, x) where {SA<:StaticArray}
Pick a proper constructor SA′
based on x
if SA(x)
/SA(x...)
has no specific definition. The default returned SA′
is SA
itself for user defined StaticArray
s. This differs from similar_type()
in that SA′
should always be a subtype of SA
.
To distinguish SA(x...)
and SA(x::Tuple)
, the former calls construct_type(SA, StaticArrays.Args(x))
instead of construct_type(SA, x)
.
Please make sure SA'(x)
has a specific definition if the default behavior is overloaded. Otherwise construction might fall into infinite recursion.
The adaption rules for official StaticArray
s could be summarized as:
SA <: FieldArray
: eltype
adaptable
FieldArray
s are always static-sized. We only derive SA′
's eltype
using type promotion if needed.
SA <: Union{SArray, MArray, SHermitianCompact, SizedArray}
: size
/eltype
adaptable
SA(x::Tuple)
If SA
is fully static-sized, then we first try to fill SA
with x
's elements. If failed and length(SA) == 1
, then we try to fill SA
with x
itself.
If SA
is not fully static-sized, then we always try to fill SA
with x
's elements, and the constructor's Size
is derived based on:
SA <: StaticVector
, then we use length(x)
as the output Length
SA <: StaticMatrix{M}
, then we use (M, N)
(N = length(x) ÷ M
) as the output Size
SA <: StaticMatrix{M,M} where M
, then we use (N, N)
(N = sqrt(length(x)
) as the output Size
.SA(x...)
Similar to Tuple
, but we never fill SA
with x
itself.
SA(x::StaticArray)
We treat x
as Tuple
whenever possible. If failed, then try to inherit x
's Size
.
SA(x::AbstractArray)
x
is used to provide eltype. Thus SA
must be static sized.
StaticArrays.deleteat
— Methoddeleteat(vec::StaticVector, index::Integer)
Return a new vector with the item at the given index
removed.
Examples
julia> deleteat(@SVector[6, 5, 4, 3, 2, 1], 2)
+BigFloat
StaticArrays.check_dims
— Methodcheck_dims(sc, sa, sb)
Validate the dimensions of a matrix multiplication, including matrix-vector products
StaticArrays.construct_type
— MethodSA′ = construct_type(::Type{SA}, x) where {SA<:StaticArray}
Pick a proper constructor SA′
based on x
if SA(x)
/SA(x...)
has no specific definition. The default returned SA′
is SA
itself for user defined StaticArray
s. This differs from similar_type()
in that SA′
should always be a subtype of SA
.
To distinguish SA(x...)
and SA(x::Tuple)
, the former calls construct_type(SA, StaticArrays.Args(x))
instead of construct_type(SA, x)
.
Please make sure SA'(x)
has a specific definition if the default behavior is overloaded. Otherwise construction might fall into infinite recursion.
The adaption rules for official StaticArray
s could be summarized as:
SA <: FieldArray
: eltype
adaptable
FieldArray
s are always static-sized. We only derive SA′
's eltype
using type promotion if needed.
SA <: Union{SArray, MArray, SHermitianCompact, SizedArray}
: size
/eltype
adaptable
SA(x::Tuple)
If SA
is fully static-sized, then we first try to fill SA
with x
's elements. If failed and length(SA) == 1
, then we try to fill SA
with x
itself.
If SA
is not fully static-sized, then we always try to fill SA
with x
's elements, and the constructor's Size
is derived based on:
SA <: StaticVector
, then we use length(x)
as the output Length
SA <: StaticMatrix{M}
, then we use (M, N)
(N = length(x) ÷ M
) as the output Size
SA <: StaticMatrix{M,M} where M
, then we use (N, N)
(N = sqrt(length(x)
) as the output Size
.SA(x...)
Similar to Tuple
, but we never fill SA
with x
itself.
SA(x::StaticArray)
We treat x
as Tuple
whenever possible. If failed, then try to inherit x
's Size
.
SA(x::AbstractArray)
x
is used to provide eltype. Thus SA
must be static sized.
StaticArrays.deleteat
— Methoddeleteat(vec::StaticVector, index::Integer)
Return a new vector with the item at the given index
removed.
Examples
julia> deleteat(@SVector[6, 5, 4, 3, 2, 1], 2)
5-element SVector{5, Int64} with indices SOneTo(5):
6
4
3
2
- 1
StaticArrays.dimmatch
— Functiondimmatch(x::StaticDimension, y::StaticDimension)
Return whether dimensions x
and y
match at compile time, that is:
x
and y
are both Int
s, check that they are equalx
or y
are Dynamic()
, return trueStaticArrays.gen_by_access
— Functiongen_by_access(expr_gen, a::Type{<:AbstractArray}, asym = :wrapped_a)
Statically generate outer code for fully unrolled multiplication loops. Returned code does wrapper-specific tests (for example if a symmetric matrix view is U
or L
) and the body of the if expression is then generated by function expr_gen
. The function expr_gen
receives access pattern description symbol as its argument and this symbol is then consumed by uplo_access to generate the right code for matrix element access.
The name of the matrix to test is indicated by asym
.
StaticArrays.gen_by_access
— Methodgen_by_access(expr_gen, a::Type{<:AbstractArray}, b::Type{<:AbstractArray})
Similar to gen_by_access
with only one type argument. The difference is that tests for both arrays of type a
and b
are generated and expr_gen
receives two access arguments, first for matrix a
and the second for matrix b
.
StaticArrays.insert
— Methodinsert(vec::StaticVector, index::Integer, item)
Return a new vector with item
inserted into vec
at the given index
.
Examples
julia> insert(@SVector[6, 5, 4, 2, 1], 4, 3)
+ 1
StaticArrays.dimmatch
— Functiondimmatch(x::StaticDimension, y::StaticDimension)
Return whether dimensions x
and y
match at compile time, that is:
x
and y
are both Int
s, check that they are equalx
or y
are Dynamic()
, return trueStaticArrays.gen_by_access
— Functiongen_by_access(expr_gen, a::Type{<:AbstractArray}, asym = :wrapped_a)
Statically generate outer code for fully unrolled multiplication loops. Returned code does wrapper-specific tests (for example if a symmetric matrix view is U
or L
) and the body of the if expression is then generated by function expr_gen
. The function expr_gen
receives access pattern description symbol as its argument and this symbol is then consumed by uplo_access to generate the right code for matrix element access.
The name of the matrix to test is indicated by asym
.
StaticArrays.gen_by_access
— Methodgen_by_access(expr_gen, a::Type{<:AbstractArray}, b::Type{<:AbstractArray})
Similar to gen_by_access
with only one type argument. The difference is that tests for both arrays of type a
and b
are generated and expr_gen
receives two access arguments, first for matrix a
and the second for matrix b
.
StaticArrays.insert
— Methodinsert(vec::StaticVector, index::Integer, item)
Return a new vector with item
inserted into vec
at the given index
.
Examples
julia> insert(@SVector[6, 5, 4, 2, 1], 4, 3)
6-element SVector{6, Int64} with indices SOneTo(6):
6
5
4
3
2
- 1
StaticArrays.mul_result_structure
— Methodmul_result_structure(a::Type, b::Type)
Get a structure wrapper that should be applied to the result of multiplication of matrices of given types (a*b
).
StaticArrays.multiplied_dimension
— Methodmultiplied_dimension(A, B)
Calculate the product of the dimensions being multiplied. Useful as a heuristic for unrolling.
StaticArrays.pop
— Methodpop(vec::StaticVector)
Return a new vector with the last item in vec
removed.
Examples
julia> pop(@SVector[1,2,3])
+ 1
StaticArrays.mul_result_structure
— Methodmul_result_structure(a::Type, b::Type)
Get a structure wrapper that should be applied to the result of multiplication of matrices of given types (a*b
).
StaticArrays.multiplied_dimension
— Methodmultiplied_dimension(A, B)
Calculate the product of the dimensions being multiplied. Useful as a heuristic for unrolling.
StaticArrays.pop
— Methodpop(vec::StaticVector)
Return a new vector with the last item in vec
removed.
Examples
julia> pop(@SVector[1,2,3])
2-element SVector{2, Int64} with indices SOneTo(2):
1
- 2
StaticArrays.popfirst
— Methodpopfirst(vec::StaticVector)
Return a new vector with the first item in vec
removed.
Examples
julia> popfirst(@SVector[1,2,3])
+ 2
StaticArrays.popfirst
— Methodpopfirst(vec::StaticVector)
Return a new vector with the first item in vec
removed.
Examples
julia> popfirst(@SVector[1,2,3])
2-element SVector{2, Int64} with indices SOneTo(2):
2
- 3
StaticArrays.push
— Methodpush(vec::StaticVector, item)
Return a new StaticVector
with item
inserted on the end of vec
.
Examples
julia> push(@SVector[1, 2, 3], 4)
+ 3
StaticArrays.push
— Methodpush(vec::StaticVector, item)
Return a new StaticVector
with item
inserted on the end of vec
.
Examples
julia> push(@SVector[1, 2, 3], 4)
4-element SVector{4, Int64} with indices SOneTo(4):
1
2
3
- 4
StaticArrays.pushfirst
— Methodpushfirst(vec::StaticVector, item)
Return a new StaticVector
with item
inserted at the beginning of vec
.
Examples
julia> pushfirst(@SVector[1, 2, 3, 4], 5)
+ 4
StaticArrays.pushfirst
— Methodpushfirst(vec::StaticVector, item)
Return a new StaticVector
with item
inserted at the beginning of vec
.
Examples
julia> pushfirst(@SVector[1, 2, 3, 4], 5)
5-element SVector{5, Int64} with indices SOneTo(5):
5
1
2
3
- 4
StaticArrays.sacollect
— Functionsacollect(SA, gen)
Construct a statically-sized vector of type SA
.from a generator gen
. SA
needs to have a size parameter since the length of vec
is unknown to the compiler. SA
can optionally specify the element type as well.
Example:
sacollect(SVector{3, Int}, 2i+1 for i in 1:3)
+ 4
StaticArrays.sacollect
— Functionsacollect(SA, gen)
Construct a statically-sized vector of type SA
.from a generator gen
. SA
needs to have a size parameter since the length of vec
is unknown to the compiler. SA
can optionally specify the element type as well.
Example:
sacollect(SVector{3, Int}, 2i+1 for i in 1:3)
sacollect(SMatrix{2, 3}, i+j for i in 1:2, j in 1:3)
-sacollect(SArray{2, 3}, i+j for i in 1:2, j in 1:3)
This creates the same statically-sized vector as if the generator were collected in an array, but is more efficient since no array is allocated.
Equivalent:
SVector{3, Int}([2i+1 for i in 1:3])
StaticArrays.same_size
— Methodsame_size(as...)
Returns the common Size
of the inputs (or else throws a DimensionMismatch
)
StaticArrays.sizematch
— Methodsizematch(::Size, ::Size)
-sizematch(::Tuple, ::Tuple)
Determine whether two sizes match, in the sense that they have the same number of dimensions, and their dimensions match as determined by dimmatch
.
StaticArrays.sizematch
— Methodsizematch(::Size, A::AbstractArray)
Determine whether array A
matches the given size. If A
is a StaticArray
, the check is performed at compile time, otherwise, the check is performed at runtime.
StaticArrays.uplo_access
— Methoduplo_access(sa, asym, k, j, uplo)
Generate code for matrix element access, for a matrix of size sa
locally referred to as asym
in the context where the result will be used. Both indices k
and j
need to be statically known for this function to work. uplo
is the access pattern mode generated by the gen_by_access
function.
StaticArrays.@MArray
— Macro@MArray [a b; c d]
+sacollect(SArray{2, 3}, i+j for i in 1:2, j in 1:3)
This creates the same statically-sized vector as if the generator were collected in an array, but is more efficient since no array is allocated.
Equivalent:
SVector{3, Int}([2i+1 for i in 1:3])
StaticArrays.same_size
— Methodsame_size(as...)
Returns the common Size
of the inputs (or else throws a DimensionMismatch
)
StaticArrays.sizematch
— Methodsizematch(::Size, ::Size)
+sizematch(::Tuple, ::Tuple)
Determine whether two sizes match, in the sense that they have the same number of dimensions, and their dimensions match as determined by dimmatch
.
StaticArrays.sizematch
— Methodsizematch(::Size, A::AbstractArray)
Determine whether array A
matches the given size. If A
is a StaticArray
, the check is performed at compile time, otherwise, the check is performed at runtime.
StaticArrays.uplo_access
— Methoduplo_access(sa, asym, k, j, uplo)
Generate code for matrix element access, for a matrix of size sa
locally referred to as asym
in the context where the result will be used. Both indices k
and j
need to be statically known for this function to work. uplo
is the access pattern mode generated by the gen_by_access
function.
StaticArrays.@MArray
— Macro@MArray [a b; c d]
@MArray [[a, b];[c, d]]
@MArray [i+j for i in 1:2, j in 1:2]
-@MArray ones(2, 2, 2)
A convenience macro to construct MArray
with arbitrary dimension. See @SArray
for detailed features.
StaticArrays.@MMatrix
— Macro@MMatrix [a b c d]
+@MArray ones(2, 2, 2)
A convenience macro to construct MArray
with arbitrary dimension. See @SArray
for detailed features.
StaticArrays.@MMatrix
— Macro@MMatrix [a b c d]
@MMatrix [[a, b];[c, d]]
@MMatrix [i+j for i in 1:2, j in 1:2]
-@MMatrix ones(2, 2)
A convenience macro to construct MMatrix
. See @SArray
for detailed features.
StaticArrays.@MVector
— Macro@MVector [a, b, c, d]
+@MMatrix ones(2, 2)
A convenience macro to construct MMatrix
. See @SArray
for detailed features.
StaticArrays.@MVector
— Macro@MVector [a, b, c, d]
@MVector [i for i in 1:2]
-@MVector ones(2)
A convenience macro to construct MVector
. See @SArray
for detailed features.
StaticArrays.@SArray
— Macro@SArray [a b; c d]
+@MVector ones(2)
A convenience macro to construct MVector
. See @SArray
for detailed features.
StaticArrays.@SArray
— Macro@SArray [a b; c d]
@SArray [[a, b];[c, d]]
@SArray [i+j for i in 1:2, j in 1:2]
-@SArray ones(2, 2, 2)
A convenience macro to construct SArray
with arbitrary dimension. It supports:
(typed) array literals.
Every argument inside the square brackets is treated as a scalar during expansion. Thus @SArray[a; b]
always forms a SVector{2}
and @SArray [a b; c]
always throws an error.
comprehensions
The range of a comprehension is evaluated at global scope by the macro, and must be made of combinations of literal values, functions, or global variables.
initialization functions
Only support zeros()
, ones()
, fill()
, rand()
, randn()
, and randexp()
StaticArrays.@SMatrix
— Macro@SMatrix [a b c d]
+@SArray ones(2, 2, 2)
A convenience macro to construct SArray
with arbitrary dimension. It supports:
(typed) array literals.
Every argument inside the square brackets is treated as a scalar during expansion. Thus @SArray[a; b]
always forms a SVector{2}
and @SArray [a b; c]
always throws an error.
comprehensions
The range of a comprehension is evaluated at global scope by the macro, and must be made of combinations of literal values, functions, or global variables.
initialization functions
Only support zeros()
, ones()
, fill()
, rand()
, randn()
, and randexp()
StaticArrays.@SMatrix
— Macro@SMatrix [a b c d]
@SMatrix [[a, b];[c, d]]
@SMatrix [i+j for i in 1:2, j in 1:2]
-@SMatrix ones(2, 2)
A convenience macro to construct SMatrix
. See @SArray
for detailed features.
StaticArrays.@SVector
— Macro@SVector [a, b, c, d]
+@SMatrix ones(2, 2)
A convenience macro to construct SMatrix
. See @SArray
for detailed features.
StaticArrays.@SVector
— Macro@SVector [a, b, c, d]
@SVector [i for i in 1:2]
-@SVector ones(2)
A convenience macro to construct SVector
. See @SArray
for detailed features.
StaticArraysCore.Dynamic
— TypeDynamic()
Used to signify that a dimension of an array is not known statically.
StaticArraysCore.FieldArray
— Typeabstract FieldArray{N, T, D} <: StaticArray{N, T, D}
Inheriting from this type will make it easy to create your own rank-D tensor types. A FieldArray
will automatically define getindex
and setindex!
appropriately. An immutable FieldArray
will be as performant as an SArray
of similar length and element type, while a mutable FieldArray
will behave similarly to an MArray
.
Note that you must define the fields of any FieldArray
subtype in column major order. If you want to use an alternative ordering you will need to pay special attention in providing your own definitions of getindex
, setindex!
and tuple conversion.
If you define a FieldArray
which is parametric on the element type you should consider defining similar_type
as in the FieldVector
example.
Example
struct Stiffness <: FieldArray{Tuple{2,2,2,2}, Float64, 4}
+@SVector ones(2)
A convenience macro to construct SVector
. See @SArray
for detailed features.
StaticArraysCore.Dynamic
— TypeDynamic()
Used to signify that a dimension of an array is not known statically.
StaticArraysCore.FieldArray
— Typeabstract FieldArray{N, T, D} <: StaticArray{N, T, D}
Inheriting from this type will make it easy to create your own rank-D tensor types. A FieldArray
will automatically define getindex
and setindex!
appropriately. An immutable FieldArray
will be as performant as an SArray
of similar length and element type, while a mutable FieldArray
will behave similarly to an MArray
.
Note that you must define the fields of any FieldArray
subtype in column major order. If you want to use an alternative ordering you will need to pay special attention in providing your own definitions of getindex
, setindex!
and tuple conversion.
If you define a FieldArray
which is parametric on the element type you should consider defining similar_type
as in the FieldVector
example.
Example
struct Stiffness <: FieldArray{Tuple{2,2,2,2}, Float64, 4}
xxxx::Float64
yxxx::Float64
xyxx::Float64
@@ -209,4 +209,4 @@
StaticMatrix{N,M,T} = StaticArray{Tuple{N,M}, T, 2}
StaticArray
s are Julia arrays with fixed, known size.
Dev docs
They must define the following methods:
getindex()
with an integer (linear indexing) (preferably @inline
with @boundscheck
).Tuple()
, returning the data in a flat Tuple.It may be useful to implement:
similar_type(::Type{MyStaticArray}, ::Type{NewElType}, ::Size{NewSize})
, returning a type (or type constructor) that accepts a flat tuple of data.For mutable containers you may also need to define the following:
setindex!
for a single element (linear indexing).similar(::Type{MyStaticArray}, ::Type{NewElType}, ::Size{NewSize})
.MyStaticArray{...}()
for unintialized data is assumed to exist.(see also SVector
, SMatrix
, SArray
, MVector
, MMatrix
, MArray
, SizedArray
, FieldVector
, FieldMatrix
and FieldArray
)
StaticArraysCore.similar_type
— Functionsimilar_type(static_array)
similar_type(static_array, T)
similar_type(array, ::Size)
-similar_type(array, T, ::Size)
Returns a constructor for a statically-sized array similar to the input array (or type) static_array
/array
, optionally with different element type T
or size Size
. If the input array
is not a StaticArray
then the Size
is mandatory.
This differs from similar()
in that the resulting array type may not be mutable (or define setindex!()
), and therefore the returned type may need to be constructed with its data.
Note that the (optional) size must be specified as a static Size
object (so the compiler can infer the result statically).
New types should define the signature similar_type(::Type{A},::Type{T},::Size{S}) where {A<:MyType,T,S}
if they wish to overload the default behavior.
StaticArraysCore.size_to_tuple
— Methodsize_to_tuple(::Type{S}) where S<:Tuple
Converts a size given by Tuple{N, M, ...}
into a tuple (N, M, ...)
.
Settings
This document was generated with Documenter.jl version 1.5.0 on Monday 15 July 2024. Using Julia version 1.6.7.