Host Vector
-
template<typename
NumType>
classHostVector: public BaseVector<NumType> Implementation of a Vector class on the host system.
- Template Parameters
NumType: Number type (double and float currently supported).
Public Functions
-
HostVector() Default constructor.
-
virtual
~HostVector() Destructor.
-
virtual void
allocate(int n) Allocate a size of
nto the vector.- Parameters
n: The size of vector.
-
virtual void
clear() Clear vector.
-
virtual void
copy_from(const NumType *w) Copy from the inputted data to the vector.
- Note
- allocate should be called first.
- Parameters
w: The pointer to the data to copy from.
-
virtual void
copy_from(const BaseVector<NumType> &w) Copy from the inputted vector to itself.
- Parameters
w: The vector to copy from.
-
virtual void
copy_to(NumType *w) const Output the vector’s values.
- Note
- memory should be allocated to
wbefore calling this function. - Parameters
w: The pointer to the data to copy to.
-
virtual void
copy_to(BaseVector<NumType> &w) const Copy the vector to outputted vector.
- Parameters
w: The vector to copy to.
-
virtual NumType &
operator[](int i) Return the
i-th element of the vector.- Return
- The
i-th value of the vector (returns by reference). - Parameters
i: The index of the element of interest in the vector.
-
virtual NumType
norm() const - Return
- The L2 norm of the vector.
-
virtual NumType
dot(const BaseVector<NumType> &w) const Return the dot product between itself and another vector.
- Return
- The dot product.
- Parameters
w: The other vector
-
virtual void
zeros() Sets all values of the vector to zero.
-
virtual void
ones() Sets all values of the vector to one.
-
virtual void
scale(NumType alpha) Scale the vector.
- Parameters
alpha: the value by which to scale the vector.
-
virtual void
add(NumType alpha, const BaseVector<NumType> &w, NumType beta) v=alpha*v+beta*w, wherevis the vector itself.- Parameters
alpha: The value in the above equation.w: The vector in the above equation.beta: The value in the above equation.
-
virtual void
add_scale(NumType alpha, const BaseVector<NumType> &w) v=v+alpha*w, wherevis the vector itself.- Parameters
alpha: The value in the above equation.w: The vector in the above equation.
-
virtual void
scale_add(NumType alpha, const BaseVector<NumType> &w) v=alpha*v+w, wherevis the vector itself.- Parameters
alpha: The value in the above equation.w: The vector in the above equation.
-
virtual void
elementwise_multiply(const BaseVector<NumType> &w) v=v.* w, wherevis the vector itself and .* is the elementwise multiplication operator.- Parameters
w: The vector in the above equation.
-
virtual void
elementwise_multiply(const BaseVector<NumType> &w, const BaseVector<NumType> &z) v=w.* z, wherevis the vector itself and .* is the elementwise multiplication operator.- Parameters
w: The vector in the above equation.z: The vector in the above equation.