Vector

## Functions

template<typename T , std::size_t N>
constexpr vector< nil::crypto3::detail::remove_complex_t< T >, N > nil::crypto3::algebra::abs (const vector< T, N > &v)
computes the elementwise absolute value More...

template<typename T , std::size_t N, typename F , typename U >
constexpr U nil::crypto3::algebra::accumulate (const vector< T, N > &v, U init, F &&f)
accumulates an operation across a vector More...

template<typename T , typename U , std::size_t N>
constexpr vector< T, N > nil::crypto3::algebra::cast (const vector< U, N > &v)
casts a vector to another type More...

template<typename T , std::size_t N, std::size_t M>
constexpr vector< T, N+M > nil::crypto3::algebra::concat (vector< T, N > a, vector< T, M > b)
concatenates two vectors More...

template<typename T , std::size_t N>
constexpr vector< T, N > nil::crypto3::algebra::conj (const vector< T, N > &v)
computes the elementwise complex conjugate More...

template<typename T , std::size_t N>
constexpr T nil::crypto3::algebra::dot (const vector< T, N > &a, const vector< T, N > &b)
computes the dot product More...

template<typename F , typename T , typename... Vectors, typename U = std::invoke_result_t<F, T, typename Vectors::value_type...>, std::size_t N = detail::all_same_value<std::size_t, Vectors::size...>::value>
constexpr vector< U, N > nil::crypto3::algebra::elementwise (F f, const vector< T, N > &v, const Vectors &...vectors)
applies a function elementwise between many vectors More...

template<std::size_t N, typename T >
constexpr vector< T, N > nil::crypto3::algebra::fill (T value)
generates a vector containing a single value More...

template<std::size_t N, typename F >
constexpr decltype(auto) nil::crypto3::algebra::generate (F &&f)
generates a vector as a function of its index More...

template<typename T , std::size_t N>
constexpr vector< nil::crypto3::detail::remove_complex_t< T >, N > nil::crypto3::algebra::imag (const vector< T, N > &v)
computes the elementwise imag More...

template<std::size_t N, typename T >
constexpr vector< T, N > nil::crypto3::algebra::iota (T value=T())
generates a vector containing consecutive elements More...

template<std::size_t N, typename T >
constexpr vector< T, N > nil::crypto3::algebra::linspace (T min, T max)
generates a vector of equally spaced elements More...

template<typename... Args>
constexpr decltype(auto) nil::crypto3::algebra::make_vector (Args... args)
constructs a vector from arguments More...

template<typename T , std::size_t N>
constexpr T nil::crypto3::algebra::max (const vector< T, N > &v)
computes the maximum valued element More...

template<typename T , std::size_t N>
constexpr std::size_t nil::crypto3::algebra::max_index (const vector< T, N > &v)
computes the index of the maximum valued element More...

template<typename T , std::size_t N>
constexpr T nil::crypto3::algebra::min (const vector< T, N > &v)
computes the minimum valued element More...

template<typename T , std::size_t N>
constexpr std::size_t nil::crypto3::algebra::min_index (const vector< T, N > &v)
computes the index of the minimum valued element More...

template<typename T , std::size_t N>
constexpr bool nil::crypto3::algebra::operator!= (const vector< T, N > &a, const vector< T, N > &b)
checks inequality of two vectors More...

template<typename T , std::size_t N>
constexpr vector< T, N > nil::crypto3::algebra::operator* (const vector< T, N > &a, const vector< T, N > &b)

template<typename T , std::size_t N>
constexpr vector< T, N > nil::crypto3::algebra::operator* (const vector< T, N > &v, T a)
computes the product of a vector and a scalar More...

template<typename T , std::size_t N>
constexpr vector< T, N > nil::crypto3::algebra::operator* (T a, const vector< T, N > &v)
computes the product of a vector and a scalar More...

template<typename T , std::size_t N>
constexpr vector< T, N > nil::crypto3::algebra::operator+ (const vector< T, N > &a, const vector< T, N > &b)
computes the vector sum More...

template<typename T , std::size_t N>
constexpr vector< T, N > nil::crypto3::algebra::operator+ (const vector< T, N > &v, T a)
computes the sum of a vector and a scalar More...

template<typename T , std::size_t N>
constexpr vector< T, N > nil::crypto3::algebra::operator+ (T a, const vector< T, N > &v)
computes the sum of a vector and a scalar More...

template<typename T , std::size_t N>
constexpr vector< T, N > nil::crypto3::algebra::operator/ (const vector< T, N > &a, const vector< T, N > &b)
computes the elementwise vector quotient More...

template<typename T , std::size_t N>
constexpr vector< T, N > nil::crypto3::algebra::operator/ (T a, const vector< T, N > &v)
computes the quotient between a vector and a scalar More...

template<typename T , std::size_t N>
constexpr bool nil::crypto3::algebra::operator== (const vector< T, N > &a, const vector< T, N > &b)
checks equality of two vectors More...

template<typename T , std::size_t N>
constexpr vector< nil::crypto3::detail::remove_complex_t< T >, N > nil::crypto3::algebra::real (const vector< T, N > &v)
computes the elementwise real More...

template<std::size_t N, typename T >
constexpr vector< T, N > nil::crypto3::algebra::rotate (vector< T, N > v, int n)
shifts vector elements More...

template<std::size_t M, typename T , std::size_t N>
constexpr vector< T, M > nil::crypto3::algebra::slice (vector< T, N > v, std::size_t start=0)
slices a vector into a subvector More...

template<typename T , std::size_t N>
constexpr vector< T, N > nil::crypto3::algebra::sqrt (const vector< T, N > &v)
computes the elementwise square root More...

template<typename T , std::size_t N>
constexpr T nil::crypto3::algebra::sum (const vector< T, N > &v)
computes the sum of elements More...

## vector deduction guides

template<typename T , typename... U>
nil::crypto3::algebra::vector (T, U...) -> vector< std::enable_if_t<(std::is_same_v< T, U > &&...), T >, 1+sizeof...(U)>
deduction guide for uniform initialization More...

template<typename T , std::size_t N>
nil::crypto3::algebra::vector (const T(&)[N]) -> vector< T, N >
deduction guide for aggregate initialization More...

template<typename T , typename... U>
vector (T, U...) -> vector< std::enable_if_t<(std::is_same_v< T, U > &&...), T >, 1+sizeof...(U)>
deduction guide for uniform initialization More...

template<typename T , std::size_t N>
vector (const T(&)[N]) -> vector< T, N >
deduction guide for aggregate initialization More...

## ◆ abs()

template<typename T , std::size_t N>
 constexpr vector, N> nil::crypto3::algebra::abs ( const vector< T, N > & v )
constexpr

computes the elementwise absolute value

Parameters
 v an N-vector of type T
Returns
an N-vector of type T

Computes the elementwise absolute value of a vector.

## ◆ accumulate()

template<typename T , std::size_t N, typename F , typename U >
 constexpr U nil::crypto3::algebra::accumulate ( const vector< T, N > & v, U init, F && f )
constexpr

accumulates an operation across a vector

Parameters
 v an N-vector of type T init the initial value f a function of type F that operates between U and vector elements of type T
Returns

Accumulates an operation over the elements. This is equivalent to a functional fold.

## ◆ cast()

template<typename T , typename U , std::size_t N>
 constexpr vector nil::crypto3::algebra::cast ( const vector< U, N > & v )
constexpr

casts a vector to another type

Parameters
 v an N-vector of type U
Returns
an N-vector of type T containing the casted elements of

Casts a vector to another type by static_casting each element.

## ◆ concat()

template<typename T , std::size_t N, std::size_t M>
 constexpr vector nil::crypto3::algebra::concat ( vector< T, N > a, vector< T, M > b )
constexpr

concatenates two vectors

Parameters
 a an N-vector of type T b an M-vector of type T
Returns
an N+M-vector such that

Slices a vector into a subvector.

## ◆ conj()

template<typename T , std::size_t N>
 constexpr vector nil::crypto3::algebra::conj ( const vector< T, N > & v )
constexpr

computes the elementwise complex conjugate

Parameters
 v an N-vector of type T
Returns
an N-vector of type T such that

Computes the elementwise complex conjugate of a vector.

## ◆ dot()

template<typename T , std::size_t N>
 constexpr T nil::crypto3::algebra::dot ( const vector< T, N > & a, const vector< T, N > & b )
constexpr

computes the dot product

Parameters
 a an N-vector of type T b an N-vector of type T
Returns
a scalar of type T such that

Computes the dot (inner) product of two vectors.

## ◆ elementwise()

template<typename F , typename T , typename... Vectors, typename U = std::invoke_result_t<F, T, typename Vectors::value_type...>, std::size_t N = detail::all_same_value<std::size_t, Vectors::size...>::value>
 constexpr vector nil::crypto3::algebra::elementwise ( F f, const vector< T, N > & v, const Vectors &... vectors )
constexpr

applies a function elementwise between many vectors

Parameters
 f a function of type F that operates on many scalars of type T and returns a scalar of type U v an N-vector of type T vectors additional N-vectors of type T
Returns
an N-vector of type T with elements described by

Applies a function elementwise between many vectors.

## ◆ fill()

template<std::size_t N, typename T >
 constexpr vector nil::crypto3::algebra::fill ( T value )
constexpr

generates a vector containing a single value

Parameters
 value the scalar value of all elements
Returns
an N-vector of type T such that

Generates a vector with all elements equal to a single value.

## ◆ generate()

template<std::size_t N, typename F >
 constexpr decltype(auto) nil::crypto3::algebra::generate ( F && f )
constexpr

generates a vector as a function of its index

Parameters
 f a function that operates on an integer index
Returns
an N-vector with type matching the return type of f such that

Generates a vector as a function of its index.

## ◆ imag()

template<typename T , std::size_t N>
 constexpr vector, N> nil::crypto3::algebra::imag ( const vector< T, N > & v )
constexpr

computes the elementwise imag

Parameters
 v an N-vector of type T
Returns
an N-vector of type T such that

Computes the elementwise imag of a vector.

## ◆ iota()

template<std::size_t N, typename T >
 constexpr vector nil::crypto3::algebra::iota ( T value = T() )
constexpr

generates a vector containing consecutive elements

Parameters
 value the value of the first element of the vector
Returns
an N-vector of type T such that

Generates a vector containing consecutive elements spaced by 1.

## ◆ linspace()

template<std::size_t N, typename T >
 constexpr vector nil::crypto3::algebra::linspace ( T min, T max )
constexpr

generates a vector of equally spaced elements

Parameters
 min the value of the first element of the vector max the value of the last element of the vector
Returns
an N-vector of type T with elements spaced by

Generates a vector of equally spaced elements.

## ◆ make_vector()

template<typename... Args>
 constexpr decltype(auto) nil::crypto3::algebra::make_vector ( Args... args )
constexpr

constructs a vector from arguments

Parameters
 args scalar elements to combine into a vector
Returns
a vector containing args

Constructs a vector from its arguments, checking that all arguments are of the same type.

## ◆ max()

template<typename T , std::size_t N>
 constexpr T nil::crypto3::algebra::max ( const vector< T, N > & v )
constexpr

computes the maximum valued element

Parameters
 v an N-vector of type T
Returns
a scalar of type T where

Computes the maximum valued element of a vector.

## ◆ max_index()

template<typename T , std::size_t N>
 constexpr std::size_t nil::crypto3::algebra::max_index ( const vector< T, N > & v )
constexpr

computes the index of the maximum valued element

Parameters
 v an N-vector of type T
Returns
an index where

Computes the index of the maximum valued element of a vector. Note: the return value is zero-indexed.

## ◆ min()

template<typename T , std::size_t N>
 constexpr T nil::crypto3::algebra::min ( const vector< T, N > & v )
constexpr

computes the minimum valued element

Parameters
 v an N-vector of type T
Returns
a scalar of type T where

Computes the minimum valued element of a vector.

## ◆ min_index()

template<typename T , std::size_t N>
 constexpr std::size_t nil::crypto3::algebra::min_index ( const vector< T, N > & v )
constexpr

computes the index of the minimum valued element

Parameters
 v an N-vector of type T
Returns
an index where

Computes the index of the minimum valued element of a vector. Note: the return value is zero-indexed.

## ◆ operator!=()

template<typename T , std::size_t N>
 constexpr bool nil::crypto3::algebra::operator!= ( const vector< T, N > & a, const vector< T, N > & b )
constexpr

checks inequality of two vectors

Parameters
 a an N-vector of type T b an N-vector of type T
Returns
false if and only if

Checks the inequality of two vectors.

## ◆ operator*() [1/3]

template<typename T , std::size_t N>
 constexpr vector nil::crypto3::algebra::operator* ( const vector< T, N > & a, const vector< T, N > & b )
constexpr

Parameters
 a an N-vector of type T b an N-vector of type T
Returns
such that

Computes the Hadamard, or elementwise, product of two vectors.

## ◆ operator*() [2/3]

template<typename T , std::size_t N>
 constexpr vector nil::crypto3::algebra::operator* ( const vector< T, N > & v, T a )
constexpr

computes the product of a vector and a scalar

Parameters
 v an N-vector of type T a a scalar of type T
Returns
such that

Computes the product of a vector and a scalar.

## ◆ operator*() [3/3]

template<typename T , std::size_t N>
 constexpr vector nil::crypto3::algebra::operator* ( T a, const vector< T, N > & v )
constexpr

computes the product of a vector and a scalar

Parameters
 a a scalar of type T v an N-vector of type T
Returns
such that

Computes the product of a vector and a scalar.

## ◆ operator+() [1/3]

template<typename T , std::size_t N>
 constexpr vector nil::crypto3::algebra::operator+ ( const vector< T, N > & a, const vector< T, N > & b )
constexpr

computes the vector sum

Parameters
 a an N-vector of type T b an N-vector of type T
Returns
such that

Computes the vector sum.

## ◆ operator+() [2/3]

template<typename T , std::size_t N>
 constexpr vector nil::crypto3::algebra::operator+ ( const vector< T, N > & v, T a )
constexpr

computes the sum of a vector and a scalar

Parameters
 v an N-vector of type T a a scalar of type T
Returns
such that

Computes the sum of a vector and a scalar.

## ◆ operator+() [3/3]

template<typename T , std::size_t N>
 constexpr vector nil::crypto3::algebra::operator+ ( T a, const vector< T, N > & v )
constexpr

computes the sum of a vector and a scalar

Parameters
 a a scalar of type T v an N-vector of type T
Returns
such that

Computes the sum of a vector and a scalar.

## ◆ operator/() [1/2]

template<typename T , std::size_t N>
 constexpr vector nil::crypto3::algebra::operator/ ( const vector< T, N > & a, const vector< T, N > & b )
constexpr

computes the elementwise vector quotient

Parameters
 a an N-vector of type T b an N-vector of type T
Returns
such that and

Computes elementwise division between two vectors

## ◆ operator/() [2/2]

template<typename T , std::size_t N>
 constexpr vector nil::crypto3::algebra::operator/ ( T a, const vector< T, N > & v )
constexpr

computes the quotient between a vector and a scalar

Parameters
 v an N-vector of type T a a scalar of type T
Returns
such that

Computes division between a vector and a scalar.

## ◆ operator==()

template<typename T , std::size_t N>
 constexpr bool nil::crypto3::algebra::operator== ( const vector< T, N > & a, const vector< T, N > & b )
constexpr

checks equality of two vectors

Parameters
 a an N-vector of type T b an N-vector of type T
Returns
true if and only if

Checks the equality of two vectors.

## ◆ real()

template<typename T , std::size_t N>
 constexpr vector, N> nil::crypto3::algebra::real ( const vector< T, N > & v )
constexpr

computes the elementwise real

Parameters
 v an N-vector of type T
Returns
an N-vector of type T such that

Computes the elementwise real of a vector.

## ◆ rotate()

template<std::size_t N, typename T >
 constexpr vector nil::crypto3::algebra::rotate ( vector< T, N > v, int n )
constexpr

shifts vector elements

Parameters
 v an N-vector of type T n the amount to shift each element
Returns
an N-vector of type T such that

Rotates a vector by shifting its elements.

## ◆ slice()

template<std::size_t M, typename T , std::size_t N>
 constexpr vector nil::crypto3::algebra::slice ( vector< T, N > v, std::size_t start = 0 )
constexpr

slices a vector into a subvector

Parameters
 v an N-vector of type T start the first index of the subvector
Returns
an M-vector such that

Slices a vector into a subvector.

## ◆ sqrt()

template<typename T , std::size_t N>
 constexpr vector nil::crypto3::algebra::sqrt ( const vector< T, N > & v )
constexpr

computes the elementwise square root

Parameters
 v an N-vector of type T
Returns
an N-vector of type T

Computes the elementwise square root of a vector.

## ◆ sum()

template<typename T , std::size_t N>
 constexpr T nil::crypto3::algebra::sum ( const vector< T, N > & v )
constexpr

computes the sum of elements

Parameters
 v an N-vector of type T
Returns
a scalar of type T

Computes the sum of the elements of a vector.

## ◆ vector() [1/4]

template<typename T , std::size_t N>
 vector ( const T(&)[N] ) -> vector< T, N >
related

deduction guide for aggregate initialization

This deduction guide allows vector to be constructed like this:

vector v{{1., 2.}}; // deduces the type of v to be vector<double, 2>
vector(T, U...) -> vector< std::enable_if_t<(std::is_same_v< T, U > &&...), T >, 1+sizeof...(U)>
deduction guide for uniform initialization

## ◆ vector() [2/4]

template<typename T , std::size_t N>
 vector ( const T(&)[N] ) -> vector< T, N >

deduction guide for aggregate initialization

This deduction guide allows vector to be constructed like this:

vector v{{1., 2.}}; // deduces the type of v to be vector<double, 2>

## ◆ vector() [3/4]

template<typename T , typename... U>
 vector ( T , U... ) -> vector< std::enable_if_t<(std::is_same_v< T, U > &&...), T >, 1+sizeof...(U)>
related

deduction guide for uniform initialization

This deduction guide allows vector to be constructed like this:

vector v{1., 2.}; // deduces the type of v to be vector<double, 2>

## ◆ vector() [4/4]

template<typename T , typename... U>
 vector ( T , U... ) -> vector< std::enable_if_t<(std::is_same_v< T, U > &&...), T >, 1+sizeof...(U)>

deduction guide for uniform initialization

This deduction guide allows vector to be constructed like this:

vector v{1., 2.}; // deduces the type of v to be vector<double, 2>