Utilities for StaticArrays
StaticArrays
implements statically sized arrays like SVector{N, T}
.
- The
scmatrix
functions provides a data structureSCMatrix
that stores aVector{SVector{N, T}}
and additionally provides a view of aMatrix{T}
with fixed column dimensionN
. joinrows
andjonrows
stack the contents of aVector{SVector{N, T}}
as rows of a matrix. A typical use case is assembling the right-hand-side of a system of equations or proving column vectors toplots
.splitrows
andsplitrows!
store the rows a matrix asVector{SVector{N, T}}
.
BaseUtilities.SCMatrix
— TypeSC = scmatrix(Val(M), rand(M, n))
SC = scmatrix([@SVector rand(M) for i in 1:n])
SC = scmatrix(Val(M), [@SVector rand(M) for i in 1:n])
SC === scmatrix(SC)
Construct matrix SCMatric{M, T}
with fixed size columns (fixed row dimension M
, static column size). An SCMatrix{M, T}
can be viewed either as a Matrix{T}
or as a Vector{SVector{M, T}}
:
A = matrix(SC)
c::Vector{SVector} = columns(A)
Requirements for AbstractMatrix
are delegated to SCMatrix
:
SC[:, j]
returns an SVector.SC[:, j] = x
writes an entire column.- The general
getindex!
gives an error: individual elements are immutable! size
,ndims
andlength
refer tomatrix(SC)
.matrix(SC)
orSC[]
gives theMatrix
columns(SC)
orSC[:]
gives theVector
of columns.
As an alternative to SVector
, columns can be interpreted as NTuple
s at construction and access as Vector
of columns:
SC = scmatrix([ntuple(_ -> rand(), Val(M)) for i in 1:n])
t::Vector{NTuple} = ntuples(A)
Different from Matrix
and SVector
, the SCMatrix
constructed from tuples t
does not take ownership of t
! It is valid only during the lifetime of t
!
Base.getindex
— MethodBase.getindex
— MethodBaseUtilities.columns
— MethodBaseUtilities.joinrows!
— Methodjoinrows!(X::AbstractMatrix{T}, x::Vector{SVector{N, T}})
Copy rows of matrix X
into x
.
Requires size(X) == length(x), N
See also joinrows
, splitrows!
, scmatrix
BaseUtilities.matrix
— MethodBaseUtilities.ntuples
— Methodt = ntuples(SC)
Same as columns
, but view SCMatrix
as t::Vector{NTuple}
, i.e., each column is represented as an NTuple
.
BaseUtilities.scmatrix
— FunctionSC = scmatrix(Val(M), rand(M, n))
SC = scmatrix([@SVector rand(M) for i in 1:n])
SC = scmatrix(Val(M), [@SVector rand(M) for i in 1:n])
SC = scmatrix([ntuple(_ -> rand(), Val(M)) for i in 1:n])
SC === scmatrix(SC)
Construct SCMatrix
.
Construction of a SCMatrix
from a SCMatrix
returns the identical matrix.
See also SCMatrix
BaseUtilities.splitrows!
— Methodx = splitrows!(x, X[, Val(N)=Val(M)])
Store rows of _ × N
matrix X
as entries in x::Vector{SVector{M}}
with M >= N
. If vector dimension is larger than N
(i.e., the number of columns in X
, the remaining elements of the vectors remain untouched.
Overwrites contents of x
.
Requires length(x) == size(X, 1)
and size(X, 2) >= N
!
BaseUtilities.splitrows
— Methodx = splitrows(X, Val(N))
Store rows of _ × N
matrix X
as entries in x::Vector{SVector{N}}
.
Requires size(X, 2) == N
!
See also splitrows!
, joinrows
, scmatrix
BaseUtilities.unsafe_matrix
— MethodA = unsafe_matrix(v)
Convert vector v::Vector{SVector{N, T}
to matrix without taking ownership.
See also unsafe_svector
, unsafe_ntuple
, SCMatrix
BaseUtilities.unsafe_ntuple
— Methodv = unsafe_ntuple(v)
Convert matrix A
with M
rows to v::Vector{SVector{N, T}}
without taking ownership.
See also unsafe_svector
, unsafe_matrix
, SCMatrix
BaseUtilities.unsafe_svector
— Functionv = unsafe_svector(Val(M), A)
Convert matrix A
with M
rows to v::Vector{SVector{N, T}}
without taking ownership.
See also unsafe_matrix
, unsafe_ntuple
, SCMatrix