NamedVectorizations.jl

Vectorization in Julia, made convenient.

Installation

] add https://github.com/nicomignoni/NamedVectorizations.jl.git

Quickstart

A Named Vectorization (NV) is a Vector whose chunks represent the flattening of some defined Array or Number, which remain accessible as property. It's an expressive implementation of the vectorization operation, which is commonly used in mathematical modelling, system theory, and optimization.

using NamedVectorizations

A = [4 5; 2 1]
b = [9; -2]
c = 7

nv = NV(A=A, b=b, c=c)
julia> nv7-element NV{Int64} with layout:
├ A: Matrix 2x2, [1-4]
├ b: 2-element Vector, [5-6]
└ c: Number, [7]:
  4
  2
  5
  1
  9
 -2
  7

NV vectorizes the passed parameters and stacks them, just like the usual vectorization.

julia> nv == [vec(A); b; c]true

However, you can still easily access the initial Array and Number constituting the NV as views.

julia> nv.A2×2 reshape(view(::Vector{Int64}, 1:4), 2, 2) with eltype Int64:
 4  5
 2  1
julia> nv.b2-element view(::Vector{Int64}, 5:6) with eltype Int64: 9 -2
julia> nv.c7

An NV is characterized by a vector, the internal representation of the vectorization

julia> vector(nv)7-element Vector{Int64}:
  4
  2
  5
  1
  9
 -2
  7

and a layout, i.e., how the Arrays and Numbers are arranged in the NV.

julia> layout(nv)(A = ((2, 2), 1, 4), b = ((2,), 5, 6), c = ((), 7, 7))

Specifically, each Symbol of the NamedTuple points to a Tuple (size, start, end), where size is the size of the Array to be vectorized (() in case of a Number), while start and end indicate the slice of vector(nv) where the vectorized Array is placed.