29 #include <boost/numeric/ublas/io.hpp>
30 #include <boost/numeric/ublas/triangular.hpp>
31 #include <boost/numeric/ublas/matrix_sparse.hpp>
32 #include <boost/numeric/ublas/matrix.hpp>
33 #include <boost/numeric/ublas/matrix_proxy.hpp>
34 #include <boost/numeric/ublas/vector_proxy.hpp>
35 #include <boost/numeric/ublas/lu.hpp>
36 #include <boost/numeric/ublas/io.hpp>
40 #define VIENNACL_WITH_UBLAS 1
68 ublas::vector<ScalarType> rhs(12);
69 for (
unsigned int i = 0; i < rhs.size(); ++i)
70 rhs(i) = randomNumber();
71 ublas::vector<ScalarType> rhs2 = rhs;
72 ublas::vector<ScalarType> result = ublas::zero_vector<ScalarType>(10);
73 ublas::vector<ScalarType> result2 = result;
74 ublas::vector<ScalarType> rhs_trans = rhs;
75 rhs_trans.resize(result.size(),
true);
76 ublas::vector<ScalarType> result_trans = ublas::zero_vector<ScalarType>(rhs.size());
78 ublas::matrix<ScalarType> matrix(result.size(),rhs.size());
83 for (
unsigned int i = 0; i < matrix.size1(); ++i)
84 for (
unsigned int j = 0; j < matrix.size2(); ++j)
85 matrix(i,j) = randomNumber();
90 std::vector< ScalarType > stl_result(result.size());
91 std::vector< ScalarType > stl_rhs(rhs.size());
92 std::vector< std::vector<ScalarType> > stl_matrix(result.size());
93 for (
unsigned int i=0; i < result.size(); ++i)
95 stl_matrix[i].resize(rhs.size());
96 for (
unsigned int j = 0; j < matrix.size2(); ++j)
99 stl_matrix[i][j] = matrix(i,j);
117 vcl_matrix2 = vcl_matrix;
118 vcl_matrix2 += vcl_matrix;
119 vcl_matrix2 -= vcl_matrix;
120 vcl_matrix2 = vcl_matrix2 + vcl_matrix;
121 vcl_matrix2 = vcl_matrix2 - vcl_matrix;
126 vcl_matrix2 *= vcl_3;
127 vcl_matrix2 /= vcl_3;
148 std::cout <<
"----- Matrix-Vector product -----" << std::endl;
156 std::cout <<
"----- Transposed Matrix-Vector product -----" << std::endl;
157 result_trans =
prod(
trans(matrix), rhs_trans);
161 viennacl::copy(rhs_trans.begin(), rhs_trans.end(), vcl_rhs_trans.begin());
172 ublas::matrix<ScalarType> tri_matrix(10,10);
173 for (std::size_t i=0; i<tri_matrix.size1(); ++i)
175 for (std::size_t j=0; j<i; ++j)
176 tri_matrix(i,j) = 0.0;
178 for (std::size_t j=i; j<tri_matrix.size2(); ++j)
179 tri_matrix(i,j) = matrix(i,j);
186 rhs.resize(tri_matrix.size1(),
true);
187 rhs2.resize(tri_matrix.size1(),
true);
188 vcl_rhs.resize(tri_matrix.size1(),
true);
191 vcl_result.resize(10);
197 std::cout <<
"----- Upper Triangular solve -----" << std::endl;
198 result =
ublas::solve(tri_matrix, rhs, ublas::upper_tag());
211 std::cout <<
"----- LU factorization -----" << std::endl;
212 std::size_t lu_dim = 300;
213 ublas::matrix<ScalarType> square_matrix(lu_dim, lu_dim);
214 ublas::vector<ScalarType> lu_rhs(lu_dim);
218 for (std::size_t i=0; i<lu_dim; ++i)
219 for (std::size_t j=0; j<lu_dim; ++j)
220 square_matrix(i,j) = randomNumber();
223 for (std::size_t j=0; j<lu_dim; ++j)
226 lu_rhs(j) = randomNumber();
254 std::cout <<
"!!!! TUTORIAL COMPLETED SUCCESSFULLY !!!!" << std::endl;
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...
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
void trans(matrix_expression< const matrix_base< NumericT, SizeT, DistanceT >, const matrix_base< NumericT, SizeT, DistanceT >, op_trans > const &proxy, matrix_base< NumericT > &temp_trans)
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Implementation of the dense matrix class.
void lu_substitute(matrix< NumericT, F1, AlignmentV1 > const &A, matrix< NumericT, F2, AlignmentV2 > &B)
LU substitution for the system LU = rhs.
Represents a vector consisting of 1 at a given index and zeros otherwise. To be used as an initialize...
VectorT solve(MatrixT const &matrix, VectorT const &rhs, bicgstab_tag const &tag, PreconditionerT const &precond)
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
A tag class representing an upper triangular matrix.
Implementations of LU factorization for row-major and column-major dense matrices.
Implementations of dense direct solvers are found here.
void prod(std::vector< std::map< IndexT, NumericT > > const &stl_A, std::vector< std::map< IndexT, NumericT > > const &stl_B, std::vector< std::map< IndexT, NumericT > > &stl_C)
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
A small collection of sequential random number generators.
Implementation of the ViennaCL scalar class.
void lu_factorize(matrix< NumericT, viennacl::row_major > &A)
LU factorization of a row-major dense matrix.