Backend Base Classes
Base Vector
-
template<typename
NumType>
classBaseVector Base vector class.
- Template Parameters
NumType: Number type (double and float currently supported).
Subclassed by DeviceVector< NumType >, HostVector< NumType >
Public Functions
-
BaseVector() Default constructor.
-
virtual
~BaseVector() Destructor.
-
virtual void
allocate(int n) = 0 Allocate a size of
nto the vector.- Parameters
n: The size of vector.
-
virtual void
clear() = 0 Clear vector.
-
virtual void
copy_from(const NumType *w) = 0 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) = 0 Copy from the inputted vector to itself.
- Parameters
w: The vector to copy from.
-
virtual void
copy_to(NumType *w) const = 0 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 = 0 Copy the vector to outputted vector.
- Parameters
w: The vector to copy to.
-
int
n() const - Return
- The size of the vector.
-
virtual NumType
norm() const = 0 - Return
- The L2 norm of the vector.
-
virtual NumType
dot(const BaseVector<NumType> &w) const = 0 Return the dot product between itself and another vector.
- Return
- The dot product.
- Parameters
w: The other vector
-
virtual void
zeros() = 0 Sets all values of the vector to zero.
-
virtual void
ones() = 0 Sets all values of the vector to one.
-
virtual void
scale(NumType alpha) = 0 Scale the vector.
- Parameters
alpha: the value by which to scale the vector.
-
virtual void
add(NumType alpha, const BaseVector<NumType> &w, NumType beta) = 0 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) = 0 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) = 0 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) = 0 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) = 0 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.
Base Matrix
-
template<typename
NumType>
classBaseMatrix Base matrix class.
- Template Parameters
NumType: Number type (double and float currently supported).
Subclassed by DeviceMatrix< NumType >, HostMatrix< NumType >, HostMatrixCOO< NumType >
Public Functions
-
BaseMatrix() Default constructor.
-
virtual
~BaseMatrix() Destructor.
-
virtual void
allocate(int m, int n, int nnz) = 0 Allocate a matrix of size
mxnwithnnznon-zero entries.- Parameters
m: The number of rows.n: The number of columns.nnz: The number of non-zero entries.
-
virtual void
clear() = 0 Clear matrix.
-
virtual void
copy_from(const BaseMatrix<NumType> &B) = 0 A=B, whereAis the matrix itself.- Parameters
B: The matrix to copy.
-
virtual void
copy_to(BaseMatrix<NumType> &B) const = 0 B=A, whereAis the matrix itself.- Parameters
B: The matrix to copy to.
-
int
m() const - Return
- The row dimension of the matrix.
-
int
n() const - Return
- The column dimension of the matrix.
-
int
nnz() const - Return
- The number of non-zero entries in the matrix.
-
bool
is_square() const - Return
- True if the matrix is square and false if it is not.
-
virtual NumType
norm() const = 0 - Return
- The Frobenius norm of the matrix.
-
virtual void
scale(NumType alpha) = 0 A=alpha*A, whereAis the matrix itself.- Parameters
alpha: The value by which to scale the entries in the matrix.
-
virtual void
multiply(const BaseVector<NumType> &v_in, BaseVector<NumType> *w_out) const = 0 w_out=A*v_in, whereAis the matrix itself.- Parameters
v_in: The vector right-multiplying the vector.w_out: The outputted vector.
-
virtual void
get_diagonals(BaseVector<NumType> *diag) const = 0 Outputs the diagonal entries of the matrix.
- Parameters
w_out: The outputted vector storing the diagonal entries.
-
virtual void
compute_inverse_diagonals(BaseVector<NumType> *inv_diag) const = 0 Compute the inverse of the diagonal entries of the matrix.
- Parameters
w_out: The outputted vector storing the inverse of the diagonal entries.
-
virtual void
lower_solve(const BaseVector<NumType> &b, BaseVector<NumType> *x) const = 0 Solvers for
xin (L+D) *x=b, whereLandDare respectively the lower triangular and diagonal parts of the matrix itself. \param[in] b The vector in the above equation \param[out] x The vector in the above equation
-
virtual void
upper_solve(const BaseVector<NumType> &b, BaseVector<NumType> *x) const = 0 Solvers for
xin (U+D) *x=b, whereUandDare respectively the upper triangular and diagonal parts of the matrix itself. \param[in] b The vector in the above equation \param[out] x The vector in the above equation
-
virtual bool
read_matrix_market(const std::string filename) = 0 Read a matrix market.
- Return
- True if successfully read, and False otherwise.
- Parameters
filename: The matrix market file.