Vector

Functions

template<typename T , std::size_t N>
constexpr vector< 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< 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)
 computes the Hadamard product 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 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< 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...
 

Detailed Description

Function Documentation

◆ abs()

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

computes the elementwise absolute value

Parameters
van N-vector of type T
Returns
an N-vector $ \begin{bmatrix} \lvert v_1 \rvert & \ldots & \lvert v_N \rvert \end{bmatrix} $ 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,
init,
F &&  f 
)
constexpr

accumulates an operation across a vector

Parameters
van N-vector of type T
initthe initial value
fa function of type F that operates between U and vector elements of type T
Returns
$ f\left(f\left(\ldots f\left(\textrm{init}, \textbf{v}_1\right), \ldots\right), \textbf{v}_N \right) $

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<T, N> nil::crypto3::algebra::cast ( const vector< U, N > &  v)
constexpr

casts a vector to another type

Parameters
van N-vector of type U
Returns
an N-vector of type T containing the casted elements of $ \textbf{v} $

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<T, N + M> nil::crypto3::algebra::concat ( vector< T, N >  a,
vector< T, M >  b 
)
constexpr

concatenates two vectors

Parameters
aan N-vector of type T
ban M-vector of type T
Returns
an N+M-vector $ \left[\textbf{a} \textbf{b}\right] $ such that $ \left(\left[\textbf{a} \textbf{b}\right]\right)_i = \begin{cases} \textbf{a}_i & i < N\\ \textbf{b}_{i - N} & i \ge N \end{cases} $

Slices a vector into a subvector.

◆ conj()

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

computes the elementwise complex conjugate

Parameters
van N-vector of type T
Returns
an N-vector $ \overline{\textbf{v}} $ of type T such that $ \left(\overline{\textbf{v}}\right)_i = \overline{v_i} $

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
aan N-vector of type T
ban N-vector of type T
Returns
a scalar $ \textbf{a} \cdot \textbf{b} $ of type T such that $ \left(\textbf{a}\cdot\textbf{b}\right)_i = a_i \overline{b_i} $

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<U, N> nil::crypto3::algebra::elementwise ( f,
const vector< T, N > &  v,
const Vectors &...  vectors 
)
constexpr

applies a function elementwise between many vectors

Parameters
fa function of type F that operates on many scalars of type T and returns a scalar of type U
van N-vector of type T
vectorsadditional N-vectors of type T
Returns
an N-vector of type T with elements described by $ f\left(\textbf{v}_i, \ldots\right) $

Applies a function elementwise between many vectors.

◆ fill()

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

generates a vector containing a single value

Parameters
valuethe scalar value of all elements
Returns
an N-vector of type T such that $ \textbf{v}_i = \textrm{value}\ \forall i \in 1\ .. N$

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
fa function that operates on an integer index
Returns
an N-vector with type matching the return type of f such that $ \textbf{v}_i = f(i) $

Generates a vector as a function of its index.

◆ imag()

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

computes the elementwise imag

Parameters
van N-vector of type T
Returns
an N-vector $ \textbf{u} $ of type T such that $ \textbf{u}_i = \mathbb{I}\{\textbf{v}_i\} $

Computes the elementwise imag of a vector.

◆ iota()

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

generates a vector containing consecutive elements

Parameters
valuethe value of the first element of the vector
Returns
an N-vector of type T such that $ \textbf{v}_i = \textrm{start} + i - 1 $

Generates a vector containing consecutive elements spaced by 1.

◆ linspace()

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

generates a vector of equally spaced elements

Parameters
minthe value of the first element of the vector
maxthe value of the last element of the vector
Returns
an N-vector of type T with elements spaced by $ \frac{\textbf{v}_N - \textbf{v}_1}{N-1} $

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
argsscalar 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
van N-vector of type T
Returns
a scalar $ v_i $ of type T where $ v_i \geq v_j,\ \forall j $

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
van N-vector of type T
Returns
an index $ i $ where $ v_i \geq v_j,\ \forall j $

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
van N-vector of type T
Returns
a scalar $ v_i $ of type T where $ v_i \leq v_j,\ \forall j $

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
van N-vector of type T
Returns
an index $ i $ where $ v_i \leq v_j,\ \forall j $

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
aan N-vector of type T
ban N-vector of type T
Returns
false if and only if $ \textbf{a}_i = \textbf{b}_i\ \forall i \in 1\ .. N $

Checks the inequality of two vectors.

◆ operator*() [1/3]

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 
)
constexpr

computes the Hadamard product

Parameters
aan N-vector of type T
ban N-vector of type T
Returns
$ \textbf{a} \circ \textbf{b} $ such that $ \left(\textbf{a} \circ \textbf{b}\right)_i = \textbf{a}_i \textbf{b}_i $

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

◆ operator*() [2/3]

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

computes the product of a vector and a scalar

Parameters
van N-vector of type T
aa scalar of type T
Returns
$ \textbf{v}a $ such that $ \left(\textbf{v}a\right)_i = \textbf{v}_i a $

Computes the product of a vector and a scalar.

◆ operator*() [3/3]

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

computes the product of a vector and a scalar

Parameters
aa scalar of type T
van N-vector of type T
Returns
$ a\textbf{v} $ such that $ \left(a\textbf{v}\right)_i = a\textbf{v}_i $

Computes the product of a vector and a scalar.

◆ operator+() [1/3]

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 
)
constexpr

computes the vector sum

Parameters
aan N-vector of type T
ban N-vector of type T
Returns
$ \textbf{a} + \textbf{b} $ such that $ \left(\textbf{a} + \textbf{b}\right)_i = \textbf{a}_i + \textbf{b}_i $

Computes the vector sum.

◆ operator+() [2/3]

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

computes the sum of a vector and a scalar

Parameters
van N-vector of type T
aa scalar of type T
Returns
$ \textbf{v} + a $ such that $ \left(\textbf{v} + a\right)_i = \textbf{v}_i + a $

Computes the sum of a vector and a scalar.

◆ operator+() [3/3]

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

computes the sum of a vector and a scalar

Parameters
aa scalar of type T
van N-vector of type T
Returns
$ a + \textbf{v} $ such that $ \left(a + \textbf{v}\right)_i = a + \textbf{v}_i $

Computes the sum of a vector and a scalar.

◆ operator/() [1/2]

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 
)
constexpr

computes the elementwise vector quotient

Parameters
aan N-vector of type T
ban N-vector of type T
Returns
$ \textbf{a} \circ \textbf{b}' $ such that $ {\textbf{b}_i}' = \left(\textbf{b}_i\right)^{-1}$ and $ \left(\textbf{a} \circ \textbf{b}'\right)_i = \textbf{a}_i {\textbf{b}'}_i $

Computes elementwise division between two vectors

◆ operator/() [2/2]

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

computes the quotient between a vector and a scalar

Parameters
van N-vector of type T
aa scalar of type T
Returns
$ \textbf{v}/a $ such that $ \left(\textbf{v}/a\right)_i = \frac{\textbf{v}_i}{a} $

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
aan N-vector of type T
ban N-vector of type T
Returns
true if and only if $ \textbf{a}_i = \textbf{b}_i\ \forall i \in 1\ .. N $

Checks the equality of two vectors.

◆ real()

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

computes the elementwise real

Parameters
van N-vector of type T
Returns
an N-vector $ \textbf{u} $ of type T such that $ \textbf{u}_i = \mathbb{R}\{\textbf{v}_i\} $

Computes the elementwise real of a vector.

◆ rotate()

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

shifts vector elements

Parameters
van N-vector of type T
nthe amount to shift each element
Returns
an N-vector of type T $ \textbf{v} \gg n $ such that $ \left(\textbf{v} \gg n\right)_i = \textbf{v}_{(i + n)\ \textrm{mod}\ N} $

Rotates a vector by shifting its elements.

◆ slice()

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 
)
constexpr

slices a vector into a subvector

Parameters
van N-vector of type T
startthe first index of the subvector
Returns
an M-vector $ \textbf{v}_{\textrm{start}:\left(\textrm{start} + M - 1\right)} $ such that $ \left(\textbf{v}_{\textrm{start}:\left(\textrm{start} + M - 1\right)}\right)_i = \textbf{v}_{\textrm{start} + i} $

Slices a vector into a subvector.

◆ sqrt()

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

computes the elementwise square root

Parameters
van N-vector of type T
Returns
an N-vector $ \begin{bmatrix} \sqrt{v_1} & \ldots &\sqrt{v_N} \end{bmatrix} $ 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
van N-vector of type T
Returns
a scalar $ \sum\limits_{i} v_i $ 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() [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 ( ,
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 ( ,
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>
vector(T, U...) -> vector< std::enable_if_t<(std::is_same_v< T, U > &&...), T >, 1+sizeof...(U)>
deduction guide for uniform initialization