Utilities for StaticArrays

StaticArrays implements statically sized arrays like SVector{N, T}.

  • The scmatrix functions provides a data structure SCMatrix that stores a Vector{SVector{N, T}} and additionally provides a view of a Matrix{T} with fixed column dimension N.
  • joinrows and jonrows stack the contents of a Vector{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 to plots.
  • splitrows and splitrows! store the rows a matrix as Vector{SVector{N, T}}.
BaseUtilities.SCMatrixType
SC = 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 and length refer to matrix(SC).
  • matrix(SC) or SC[] gives the Matrix
  • columns(SC) or SC[:] gives the Vector of 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)
Warn

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!

See also scmatrix, matrix, columns, ntuples

source
BaseUtilities.scmatrixFunction
SC = 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.

Note

Construction of a SCMatrix from a SCMatrix returns the identical matrix.

See also SCMatrix

source
BaseUtilities.splitrows!Method
x = 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.

precondition

Requires length(x) == size(X, 1) and size(X, 2) >= N!

See also splitrows, joinrows, scmatrix

source