Skip to content

Latest commit

 

History

History
54 lines (36 loc) · 2.39 KB

File metadata and controls

54 lines (36 loc) · 2.39 KB

VectorInterface

Documentation Build Status License
CI license

A small Julia interface for vector-like objects. VectorInterface.jl proposes a minimal, unified set of methods that any type representing an element of a vector space should support, so that generic algorithms (Krylov methods, ODE integrators, gradient optimizers, ...) can be written once and reused across 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")

Quick example

using VectorInterface

v = [1.0, 2.0, 3.0]
w = [4.0, 5.0, 6.0]

scalartype(v)            # Float64
zerovector(v)            # [0.0, 0.0, 0.0]
scale!!(v, 2.0)          # tries in place: [2.0, 4.0, 6.0]
add!!(v, w, 0.5)         # v <- v + 0.5 * w
inner(v, w)              # conjugate-linear inner product
norm(v)                  # re-exported from LinearAlgebra

Every mutating operation comes in three variants: f (allocating), f! (strict in-place), and f!! (try in-place, fall back to allocating), following the convention from BangBang.jl.