A lightweight class describing a Vector object. Vectors are array with size n (>0) of doubles.
More...
#include <vector.h>
|
static Vector | basis (uint16_t, uint16_t) |
| Construct vector of the canonical basis of \(\mathbb{R}^n\). More...
|
|
static Vector | zeros (uint16_t) |
| Construct a Vector object of length n filled with zeros. More...
|
|
static Vector | ones (uint16_t) |
| Construct a Vector object of length n filled with ones. More...
|
|
static Vector | rand (uint16_t) |
| Construct a Vector object of length \(n\) filled with random values sampled from 0. to 1. More...
|
|
static Vector | randn (uint16_t) |
| Construct a Vector object of length \(n\) filled with random values sampled from the Gaussian random number distribution: mean is 0. and standart deviation is 1. More...
|
|
static Vector | randn (uint16_t, double, double) |
| Construct a Vector object of length \(n\) filled with random values sampled from a Gaussian random number distribution. More...
|
|
static Vector | linspace (double, double, uint16_t) |
| Construct a Vector object of length n filled with equally points spaced between t0 and t1 included. More...
|
|
|
bool | operator== (const Vector &, const Vector &) |
| Overload of the equality operator for Vector objects. Two vectors are said to be equal if and only if they have the same dimension and they have exactly the same values. More...
|
|
double | operator* (const Vector &, const Vector &) |
| Dot product between vectors. More...
|
|
Vector | operator* (const double, const Vector &) |
| Operator of multiplication of a Vector object by a scalar. More...
|
|
Vector | operator* (const Vector &, const double) |
| Operator of multiplication of a Vector object by a scalar. More...
|
|
Vector | operator+ (const Vector &, const Vector &) |
| Addition of two vector objects. More...
|
|
Vector | operator+ (const double, const Vector &) |
| Operator of addition of a Vector object with a scalar. More...
|
|
Vector | operator+ (const Vector &, const double) |
| Operator of addition of a Vector object with a scalar. More...
|
|
Vector | operator- (const Vector &, const Vector &) |
| Substract two vector objects. More...
|
|
Vector | operator- (const double, const Vector &) |
| Operator of remove a scalar to a Vector. More...
|
|
Vector | operator- (const Vector &, const double) |
| Operator of remove a scalar to a Vector. More...
|
|
Vector | operator/ (const Vector &, const double) |
| Operator to divide a Vector by a scalar. More...
|
|
std::ostream & | operator<< (std::ostream &, const Vector &) |
| Overload output stream operator for Vector object. More...
|
|
Vector | abs (const Vector &) |
| Elementwise absolute value of a vector. More...
|
|
Vector | pow2 (const Vector &) |
| Elementwise square of a vector. More...
|
|
double | prod (const Vector &) |
| Compute the product of the element of a vector. More...
|
|
Vector | prod (const Vector &, const Vector &) |
| Compute the elementwise product of two vectors. More...
|
|
Vector | sqrt (const Vector &) |
| Elementwise square root of a vector. More...
|
|
double | sum (const Vector &) |
| Compute the sum of the element of a vector. More...
|
|
A lightweight class describing a Vector object. Vectors are array with size n (>0) of doubles.
- Warning
- Maximum dimension of a Vector is 65 535
-
Indices are 0-based. Math formulae must be adapted consequently.
- Todo:
Template this class to use different data types (double, float, complex)
Parallelize the class
Interface with eigen or other lib if exists
◆ Vector() [1/4]
Construct a new Vector object. Default constructor. Return an empty vector of 0 dimension.
◆ Vector() [2/4]
Vector::Vector |
( |
uint16_t |
n | ) |
|
Construct a new Vector object. Return a Vector with dimension \(n\) filled with zeros.
- Parameters
-
n | Dimension of the desired vector (must be greater or equal than \(1\)) |
◆ Vector() [3/4]
Vector::Vector |
( |
double * |
dat, |
|
|
uint16_t |
n |
|
) |
| |
Construct a new Vector object. Construct a vector object from an array of double.
- Parameters
-
dat | Array of double of size n |
n | Size of the input array |
◆ Vector() [4/4]
Vector::Vector |
( |
const Vector & |
v | ) |
|
Construct a new Vector object. Copy constructor.
- Parameters
-
◆ ~Vector()
◆ basis()
Vector Vector::basis |
( |
uint16_t |
n, |
|
|
uint16_t |
k |
|
) |
| |
|
static |
Construct vector of the canonical basis of \(\mathbb{R}^n\).
- Parameters
-
n | Dimension of the vector space (must be greater or equal than 1) |
k | Number of the basis vector (must be between 0 and n-1). |
- Returns
- Vector k-th vector of the canonical basis of \(\mathbb{R}^n\).
- Warning
- Indices are 0-based.
◆ get_dim()
uint16_t Vector::get_dim |
( |
| ) |
const |
Get the dimension of a Vector object.
- Returns
- uint16_t Dimension of the Vector.
◆ linspace()
Vector Vector::linspace |
( |
double |
t0, |
|
|
double |
t1, |
|
|
uint16_t |
n |
|
) |
| |
|
static |
Construct a Vector object of length n filled with equally points spaced between t0 and t1 included.
- Parameters
-
t0 | Starting value |
t1 | Final value (must be greater than t0) |
n | Number of timestep including t0 and t1 (must be greater or equal than 2) |
- Returns
- Vector of size n of equally spaced timestep between t0 and t1
◆ norm()
double Vector::norm |
( |
uint8_t |
type | ) |
|
A general method to compute the norm of a Vector object.
- Parameters
-
type | Unisgned integer to decide the norm to choose: type = 0 compute the \(L^{\infty}\) norm type >= 1 Compute the \(L^p\) norm |
- Returns
- double \(L^p\) norm of the Vector.
◆ norm1()
Compute the \(L^1\) norm of a Vector object.
- Returns
- double \(L^1\) norm of the Vector.
◆ norm2()
Compute the Euclidean norm of a Vector object.
- Returns
- double Euclidean of the Vector.
◆ normInf()
double Vector::normInf |
( |
| ) |
|
Compute the \(L^{\infty}\) norm of a Vector object.
- Returns
- double \(L^{\infty}\) norm of the Vector.
◆ normp()
double Vector::normp |
( |
uint8_t |
p | ) |
|
Compute the \(L^p\) norm of a Vector object.
- Parameters
-
- Returns
- double \(L^p\) norm of the Vector.
◆ ones()
Vector Vector::ones |
( |
uint16_t |
n | ) |
|
|
static |
Construct a Vector object of length n filled with ones.
- Parameters
-
n | Dimension of the vector (must be greater or equal than 1). |
- Returns
- Vector A Vector object of size n filled with ones
◆ operator()()
double & Vector::operator() |
( |
uint16_t |
n | ) |
const |
Access the n-th value of a Vector object. Same as operator [].
- Parameters
-
n | index of the required value (must be between 0 and dim-1) |
- Returns
- double & address of the n-th element of the Vector object.
- Warning
- indices are 0-based.
◆ operator+=()
Overload operator += for vectors objects.
- Parameters
-
- Returns
- Vector& Addition of current object with rhs
- Warning
- Both vector must be of the same dimension
◆ operator-()
Vector Vector::operator- |
( |
| ) |
const |
Operator to get the opposite vector.
- Parameters
-
- Returns
- Vector the opposite of v, i.e. -v
◆ operator-=()
Overload operator -= for vectors objects.
- Parameters
-
- Returns
- Vector& Difference of current object with rhs
- Warning
- Both vector must be of the same dimension
◆ operator=()
Overload the assignement operator. Acts like a copy constructor.
- Parameters
-
v | The vector to be copied. |
- Returns
- Vector& A copy of vector v.
◆ operator[]()
double & Vector::operator[] |
( |
uint16_t |
n | ) |
const |
Access the n-th value of a Vector object.
- Parameters
-
n | index of the required value (must be between 0 and dim-1) |
- Returns
- double & address of the n-th element of the Vector object.
- Warning
- indices are 0-based.
◆ rand()
Vector Vector::rand |
( |
uint16_t |
n | ) |
|
|
static |
Construct a Vector object of length \(n\) filled with random values sampled from 0. to 1.
- Parameters
-
n | Dimension of the vector (must be greater or equal than 1). |
- Returns
- Vector A Vector object of size n filled with random values
◆ randn() [1/2]
Vector Vector::randn |
( |
uint16_t |
n | ) |
|
|
static |
Construct a Vector object of length \(n\) filled with random values sampled from the Gaussian random number distribution: mean is 0. and standart deviation is 1.
- Parameters
-
n | Dimension of the vector (must be greater or equal than 1). |
- Returns
- Vector A Vector object of size \(n\) filled with random values picked following a \(\mathcal{N}(0,1)\) law.
◆ randn() [2/2]
Vector Vector::randn |
( |
uint16_t |
n, |
|
|
double |
m, |
|
|
double |
s |
|
) |
| |
|
static |
Construct a Vector object of length \(n\) filled with random values sampled from a Gaussian random number distribution.
- Parameters
-
n | Dimension of the vector (must be greater or equal than 1). |
m | Mean of the Gaussian distribution. |
s | Standart deviation of the Gaussian distribution |
- Returns
- Vector A Vector object of size \(n\) filled with random values picked following a \(\mathcal{N}(m,s)\) law.
◆ sort()
Sort the vector with the quickSort algorithm.
◆ to_std_vector()
std::vector< double > Vector::to_std_vector |
( |
| ) |
|
Conversion to a standard library vector object.
- Returns
- std::vector<double> a standard vector object with the same data as the current object
◆ zeros()
Vector Vector::zeros |
( |
uint16_t |
n | ) |
|
|
static |
Construct a Vector object of length n filled with zeros.
- Parameters
-
n | Dimension of the Mector (must be greater or equal than 1). |
- Returns
- Vector A Vector object of size n filled with zeros
◆ abs
Elementwise absolute value of a vector.
- Parameters
-
- Returns
- Vector a vector whose components are the absolute value of the components of v
◆ operator* [1/3]
Operator of multiplication of a Vector object by a scalar.
- Parameters
-
d | Double value to multiply v with |
v | Vector to be multiplied |
- Returns
- Vector whose components are v[i]*d
◆ operator* [2/3]
Operator of multiplication of a Vector object by a scalar.
- Parameters
-
v | Vector to be multiplied |
d | Double value to multiply v with |
- Returns
- Vector whose components are v[i]*d
◆ operator* [3/3]
Dot product between vectors.
- Parameters
-
lhs | Left Hand Side
|
rhs | Right Hand Side |
- Returns
- double Dot product between vetcor object and v
- Warning
- Both vectors must be of the same dimension.
◆ operator+ [1/3]
Operator of addition of a Vector object with a scalar.
- Parameters
-
d | Double value added to v |
v | Vector to be additioned |
- Returns
- Vector whose components are v[i] + d
◆ operator+ [2/3]
Operator of addition of a Vector object with a scalar.
- Parameters
-
v | Vector to be additioned |
d | Double value added to v |
- Returns
- Vector whose components are v[i] + d
◆ operator+ [3/3]
Addition of two vector objects.
- Parameters
-
lhs | A vector of dimension \(n\), |
rhs | A vector of dimension \(n\) |
- Warning
- lhs and rhs must be of the same dimension.
- Returns
- Vector Sum of lhs and rhs.
◆ operator- [1/3]
Operator of remove a scalar to a Vector.
- Parameters
-
d | Double value to remove fro v |
v | Right Hand Side |
- Returns
- Vector whose components are d - v[i]
◆ operator- [2/3]
Operator of remove a scalar to a Vector.
- Parameters
-
v | Left Hand Side |
d | Double value to remove from v |
- Returns
- Vector whose components are v[i] - d
◆ operator- [3/3]
Substract two vector objects.
- Parameters
-
lhs | A vector of dimension \(n\), |
rhs | A vector of dimension \(n\) |
- Warning
- lhs and rhs must be of the same dimension.
- Returns
- Vector Difference of lhs and rhs.
◆ operator/
Operator to divide a Vector by a scalar.
- Parameters
-
v | Vector v |
d | Double value to divide v (must be non-zero) |
- Returns
- Vector whose components are v[i] / d
- Warning
- d must me non-zero
◆ operator<<
std::ostream& operator<< |
( |
std::ostream & |
os, |
|
|
const Vector & |
v |
|
) |
| |
|
friend |
Overload output stream operator for Vector object.
- Parameters
-
os | Output stream. |
v | Vector object. |
- Returns
- std::ostream & updated output stream
◆ operator==
Overload of the equality operator for Vector objects. Two vectors are said to be equal if and only if they have the same dimension and they have exactly the same values.
- Parameters
-
lhs | Left hand side |
rhs | Right hand side |
- Returns
- true If all values of both vectors coincide.
-
false If at least of the value of the two vectors differ.
◆ pow2
Elementwise square of a vector.
- Parameters
-
- Returns
- Vector a vector whose components are the square of the components of v
◆ prod [1/2]
double prod |
( |
const Vector & |
v | ) |
|
|
friend |
Compute the product of the element of a vector.
- Parameters
-
- Returns
- double product of the components of \(v\)
- Warning
- If v has zero length then we return 1
◆ prod [2/2]
Compute the elementwise product of two vectors.
- Parameters
-
- Returns
- Vector a vector whose elements are the product of the corresponding elements of v1 and v2
- Warning
- v1 and v2 must have the same dimension
◆ sqrt
Elementwise square root of a vector.
- Parameters
-
- Returns
- Vector a vector whose components are the square root of the components of v
- Warning
- the components must be non negative
◆ sum
double sum |
( |
const Vector & |
v | ) |
|
|
friend |
Compute the sum of the element of a vector.
- Parameters
-
- Returns
- double sum of the components of \(v\)
- Warning
- If v has zero length then we return 0
The documentation for this class was generated from the following files: