VectorInterface.jl
A small Julia interface for vector-like objects.
VectorInterface.jl proposes a minimal set of methods that any type representing an element of a vector space should support. Code written against this interface can then operate uniformly on Numbers, AbstractArrays, nested arrays, tuples, named tuples, and arbitrary user-defined types — without conflating vector-space operations with the iteration, container, or LinearAlgebra interfaces.
Installation
julia> using Pkg; Pkg.add("VectorInterface")What's provided
- A scalar-type query:
scalartype. - Construction of zero vectors:
zerovector,zerovector!,zerovector!!. - Scalar multiplication:
scale,scale!,scale!!. - Linear combinations:
add,add!,add!!. - Inner product and norm:
inner, andnormis re-exported fromLinearAlgebra. - Singleton helpers
OneandZerofor hard-coded coefficients in linear combinations.
Each !-suffixed method modifies its first argument in place. Each !!-suffixed method tries to do so but falls back to allocating when in-place updates are not possible (e.g. for immutable types or incompatible scalar types). This convention follows BangBang.jl.