Utilities for StaticArrays
StaticArrays implements statically sized arrays like SVector{N, T}.
- The
scmatrixfunctions provides a data structureSCMatrixthat stores aVector{SVector{N, T}}and additionally provides a view of aMatrix{T}with fixed column dimensionN. joinrowsandjonrowsstack 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.splitrowsandsplitrows!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] = xwrites an entire column.- The general
getindex!gives an error: individual elements are immutable! size,ndimsandlengthrefer tomatrix(SC).matrix(SC)orSC[]gives theMatrixcolumns(SC)orSC[:]gives theVectorof columns.
As an alternative to SVector, columns can be interpreted as NTuples at construction and access as Vector of columns:
SC = scmatrix([ntuple(_ -> rand(), Val(M)) for i in 1:n])
t::Vector{NTuple} = ntuples(A)Base.getindex — MethodBase.getindex — MethodBaseUtilities.columns — MethodBaseUtilities.joinrows! — Methodjoinrows!(X::AbstractMatrix{T}, x::Vector{SVector{N, T}})Copy rows of matrix X into x.
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.
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.
BaseUtilities.splitrows — Methodx = splitrows(X, Val(N))Store rows of _ × N matrix X as entries in x::Vector{SVector{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