Vector

template<class T>
class zhetapi::Vector : public zhetapi::Matrix<T>

Represents a vector whose components are of type T.

tparam T

the type of each component.

Public Functions

Vector()

Default vector constructor.

Vector(const Vector&)

Copy constructor.

Parameters

other – the reference vector (to be copied from).

Vector(size_t)

Size constructor. Components are initialized to 0 or the default value of T.

Parameters

len – size of the vector.

Vector(size_t, T)

Size constructor. Each component is initialized to def.

Parameters
  • rs – the number of rows (size) of the vector.

  • def – the value each component is initialized to.

template<class A>
explicit Vector(const Vector<A>&)

Heterogenous copy constructor.

Parameters

other – the reference vector (to be copied from).

inline size_t get_cols() const

Safety getter function.

TODO: eliminate this somehow

inline __cuda_dual__ T & get (size_t)

Indexing function.

Parameters

i – the specified index.

Returns

the \(i\)th component of the vector.

inline __cuda_dual__ const T & get (size_t) const

Indexing function.

Parameters

i – the specified index.

Returns

the \(i\)th component of the vector.

inline __cuda_dual__ T & operator[] (size_t)

Indexing operator.

Parameters

i – the specified index.

Returns

the \(i\)th component of the vector.

inline __cuda_dual__ const T & operator[] (size_t) const

Indexing operator.

Parameters

i – the specified index.

Returns

the \(i\)th component of the vector.

T &x()
Returns

the first component of the vector (index 0).

T &y()
Returns

the second component of the vector (index 1).

T &z()
Returns

the third component of the vector (index 2).

const T &x() const
Returns

the first component of the vector (index 0).

const T &y() const
Returns

the second component of the vector (index 1).

const T &z() const
Returns

the third component of the vector (index 2).

T arg() const

Returns the argument of the vector. Assumes that the vector has at least two components.

Returns

the argument of the vector in radians (the angle at which the vector is pointing to).

T min() const

The minimum component of the vector.

Returns

the smallest component, \(\min v_i.\)

T max() const

The maximum component of the vector.

Returns

the largest component, \(\max v_i.\)

size_t imin() const

The index of the smallest component: essentially argmin.

Returns

the index of the smallest component.

size_t imax() const

The index of the largest component: essentially argmax.

Returns

the index of the largest component.

void normalize()

Normalizes the components of the vector (the modified vector will have unit length).

Vector normalized() const

Returns a vector with normalized components (length of 1). The direction is preserved, as with normalization.

Returns

The normalized vector.

void operator+=(const Vector&)

Add and assignment operator.

TODO: Needs to return itself

Parameters

the – vector that will be added to this.

void operator-=(const Vector&)

Subtract and assignment operator.

TODO: Needs to return itself

Parameters

the – vector that will be subtracted from this.

template<class T>
Vector(const std::vector<T> &ref)

Constructs a vector out of a list of components.

Parameters

ref – the list of components.

template<class T>
Vector(const std::initializer_list<T> &ref)

Constructs a vector out of a list of components.

Parameters

ref – the list of components.

template<class T>
Vector(size_t rs, std::function<T(size_t)> gen)

Size constructor. Each component is evaluated from a function which depends on the index.

Parameters
  • rs – the number of rows (size) of the vector.

  • gen – a pointer to the function that generates the coefficients.

template<class T>
Vector(size_t rs, std::function<T*(size_t)> gen)

Size constructor. Each component is evaluated from a function which depends on the index.

Parameters
  • rs – the number of rows (size) of the vector.

  • gen – a pointer to the function that generates pointers to the coefficients.

class index_out_of_bounds