1 #ifndef VIENNACL_LINALG_SPARSE_MATRIX_OPERATIONS_HPP_
2 #define VIENNACL_LINALG_SPARSE_MATRIX_OPERATIONS_HPP_
32 #ifdef VIENNACL_WITH_OPENCL
36 #ifdef VIENNACL_WITH_CUDA
48 template<
typename SparseMatrixType,
typename SCALARTYPE,
unsigned int VEC_ALIGNMENT>
59 #ifdef VIENNACL_WITH_OPENCL
64 #ifdef VIENNACL_WITH_CUDA
90 template<
typename SparseMatrixType,
class ScalarType>
96 assert( (mat.size1() == result.
size()) &&
bool(
"Size check failed for compressed matrix-vector product: size1(mat) != size(result)"));
97 assert( (mat.size2() == vec.
size()) &&
bool(
"Size check failed for compressed matrix-vector product: size2(mat) != size(x)"));
104 #ifdef VIENNACL_WITH_OPENCL
109 #ifdef VIENNACL_WITH_CUDA
131 template<
typename SparseMatrixType,
class ScalarType>
137 assert( (sp_mat.size1() == result.
size1()) &&
bool(
"Size check failed for compressed matrix - dense matrix product: size1(sp_mat) != size1(result)"));
138 assert( (sp_mat.size2() == d_mat.
size1()) &&
bool(
"Size check failed for compressed matrix - dense matrix product: size2(sp_mat) != size1(d_mat)"));
145 #ifdef VIENNACL_WITH_OPENCL
150 #ifdef VIENNACL_WITH_CUDA
171 template<
typename SparseMatrixType,
class ScalarType>
179 assert( (sp_mat.size1() == result.
size1()) &&
bool(
"Size check failed for compressed matrix - dense matrix product: size1(sp_mat) != size1(result)"));
180 assert( (sp_mat.size2() == d_mat.size1()) &&
bool(
"Size check failed for compressed matrix - dense matrix product: size2(sp_mat) != size1(d_mat)"));
187 #ifdef VIENNACL_WITH_OPENCL
192 #ifdef VIENNACL_WITH_CUDA
215 template<
typename NumericT>
221 assert( (A.
size2() == B.
size1()) &&
bool(
"Size check failed for sparse matrix-matrix product: size2(A) != size1(B)"));
222 assert( (C.
size1() == 0 || C.
size1() == A.
size1()) &&
bool(
"Size check failed for sparse matrix-matrix product: size1(A) != size1(C)"));
223 assert( (C.
size2() == 0 || C.
size2() == B.
size2()) &&
bool(
"Size check failed for sparse matrix-matrix product: size2(B) != size2(B)"));
230 #ifdef VIENNACL_WITH_OPENCL
235 #ifdef VIENNACL_WITH_CUDA
254 template<
typename SparseMatrixType,
class ScalarType,
typename SOLVERTAG>
260 assert( (mat.size1() == mat.size2()) &&
bool(
"Size check failed for triangular solve on compressed matrix: size1(mat) != size2(mat)"));
261 assert( (mat.size2() == vec.
size()) &&
bool(
"Size check failed for compressed matrix-vector product: size2(mat) != size(x)"));
268 #ifdef VIENNACL_WITH_OPENCL
273 #ifdef VIENNACL_WITH_CUDA
292 template<
typename SparseMatrixType,
class ScalarType,
typename SOLVERTAG>
298 assert( (mat.
size1() == mat.
size2()) &&
bool(
"Size check failed for triangular solve on transposed compressed matrix: size1(mat) != size2(mat)"));
299 assert( (mat.
size1() == vec.
size()) &&
bool(
"Size check failed for transposed compressed matrix triangular solve: size1(mat) != size(x)"));
306 #ifdef VIENNACL_WITH_OPENCL
311 #ifdef VIENNACL_WITH_CUDA
328 template<
typename SparseMatrixType,
class ScalarType,
typename SOLVERTAG>
336 assert( (mat.
size1() == mat.
size2()) &&
bool(
"Size check failed for triangular solve on transposed compressed matrix: size1(mat) != size2(mat)"));
337 assert( (mat.
size1() == vec.
size()) &&
bool(
"Size check failed for transposed compressed matrix triangular solve: size1(mat) != size(x)"));
344 #ifdef VIENNACL_WITH_OPENCL
349 #ifdef VIENNACL_WITH_CUDA
370 template<
typename M1>
372 matrix_expression< const M1, const M1, op_trans>
385 template<
typename SCALARTYPE,
typename SparseMatrixType>
391 assert(proxy.lhs().size1() == result.
size() && bool(
"Dimensions for addition of sparse matrix-vector product to vector don't match!"));
403 template<
typename SCALARTYPE,
typename SparseMatrixType>
409 assert(proxy.lhs().size1() == result.
size() && bool(
"Dimensions for addition of sparse matrix-vector product to vector don't match!"));
const vcl_size_t & size2() const
Returns the number of columns.
Simple enable-if variant that uses the SFINAE pattern.
void inplace_solve(matrix_base< NumericT > const &A, matrix_base< NumericT > &B, SolverTagT tag)
Direct inplace solver for triangular systems with multiple right hand sides, i.e. A \ B (MATLAB notat...
void inplace_solve(const matrix_base< NumericT > &A, matrix_base< NumericT > &B, SolverTagT)
Direct inplace solver for triangular systems with multiple right hand sides, i.e. A \ B (MATLAB notat...
viennacl::enable_if< viennacl::is_any_sparse_matrix< M1 >::value, matrix_expression< const M1, const M1, op_trans > >::type trans(const M1 &mat)
Returns an expression template class representing a transposed matrix.
Exception class in case of memory errors.
const vcl_size_t & size1() const
Returns the number of rows.
Implementation of the dense matrix class.
Implementations of operations using sparse matrices on the CPU using a single thread or OpenMP...
void inplace_solve(matrix_base< NumericT > const &A, matrix_base< NumericT > &B, SolverTagT)
Direct inplace solver for triangular systems with multiple right hand sides, i.e. A \ B (MATLAB notat...
Expression template class for representing a tree of expressions which ultimately result in a matrix...
This file provides the forward declarations for the main types used within ViennaCL.
void row_info(compressed_matrix< NumericT, AligmentV > const &mat, vector_base< NumericT > &vec, viennacl::linalg::detail::row_info_types info_selector)
void prod_impl(const matrix_base< NumericT > &mat, bool mat_transpose, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
An expression template class that represents a binary operation that yields a vector.
vcl_size_t size1() const
Returns the size of the result vector.
viennacl::vector< NumericT > operator-(const vector_base< NumericT > &v1, const vector_expression< const matrix_base< NumericT >, const vector_base< NumericT >, op_prod > &proxy)
Implementation of the operation 'result = v1 - A * v2', where A is a matrix.
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
void prod_impl(const matrix_base< NumericT > &mat, bool trans, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
Implementations of operations using sparse matrices using CUDA.
void block_inplace_solve(const matrix_expression< const compressed_matrix< NumericT, AlignmentV >, const compressed_matrix< NumericT, AlignmentV >, op_trans > &L, viennacl::backend::mem_handle const &, vcl_size_t, vector_base< NumericT > const &, vector_base< NumericT > &vec, viennacl::linalg::unit_lower_tag)
void block_inplace_solve(const matrix_expression< const compressed_matrix< NumericT, AlignmentV >, const compressed_matrix< NumericT, AlignmentV >, op_trans > &L, viennacl::backend::mem_handle const &block_indices, vcl_size_t num_blocks, vector_base< NumericT > const &, vector_base< NumericT > &vec, viennacl::linalg::unit_lower_tag)
size_type size1() const
Returns the number of rows.
Implementations of operations using sparse matrices and OpenCL.
void inplace_solve(matrix_base< NumericT > const &A, matrix_base< NumericT > &B, SolverTagT)
Direct inplace solver for dense triangular systems. Matlab notation: A \ B.
viennacl::vector< NumericT > operator+(const vector_base< NumericT > &v1, const vector_expression< const matrix_base< NumericT >, const vector_base< NumericT >, op_prod > &proxy)
Implementation of the operation 'result = v1 + A * v2', where A is a matrix.
A tag class representing matrix-vector products and element-wise multiplications. ...
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
size_type size() const
Returns the length of the vector (cf. std::vector)
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
A tag class representing transposed matrices.
void row_info(compressed_matrix< NumericT, AlignmentV > const &mat, vector_base< NumericT > &vec, viennacl::linalg::detail::row_info_types info_selector)
void prod_impl(const matrix_base< NumericT > &mat, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
void block_inplace_solve(const matrix_expression< const compressed_matrix< NumericT, AlignmentV >, const compressed_matrix< NumericT, AlignmentV >, op_trans > &L, viennacl::backend::mem_handle const &block_indices, vcl_size_t num_blocks, vector_base< NumericT > const &, vector_base< NumericT > &x, viennacl::linalg::unit_lower_tag)
LHS & lhs() const
Get left hand side operand.
viennacl::enable_if< viennacl::is_any_sparse_matrix< SparseMatrixType >::value >::type row_info(SparseMatrixType const &mat, vector< SCALARTYPE, VEC_ALIGNMENT > &vec, row_info_types info_selector)
Implementation of the ViennaCL scalar class.
void prod_impl(const matrix_base< NumericT > &A, bool trans_A, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
void row_info(compressed_matrix< NumericT, AlignmentV > const &A, vector_base< NumericT > &x, viennacl::linalg::detail::row_info_types info_selector)
memory_types get_active_handle_id() const
Returns an ID for the currently active memory buffer. Other memory buffers might contain old or no da...
viennacl::enable_if< viennacl::is_any_sparse_matrix< SparseMatrixType >::value >::type block_inplace_solve(const matrix_expression< const SparseMatrixType, const SparseMatrixType, op_trans > &mat, viennacl::backend::mem_handle const &block_index_array, vcl_size_t num_blocks, viennacl::vector_base< ScalarType > const &mat_diagonal, viennacl::vector_base< ScalarType > &vec, SOLVERTAG tag)