27 #define VIENNACL_WITH_UBLAS
42 #include "boost/numeric/ublas/vector.hpp"
43 #include "boost/numeric/ublas/matrix.hpp"
44 #include "boost/numeric/ublas/matrix_proxy.hpp"
45 #include "boost/numeric/ublas/io.hpp"
51 int main (
int,
const char **)
55 typedef boost::numeric::ublas::matrix<ScalarType> MatrixType;
62 std::size_t dim_large = 5;
63 std::size_t dim_small = 3;
65 MatrixType ublas_A(dim_large, dim_large);
66 MatrixType ublas_B(dim_small, dim_small);
67 MatrixType ublas_C(dim_large, dim_small);
68 MatrixType ublas_D(dim_small, dim_large);
71 for (std::size_t i=0; i<ublas_A.size1(); ++i)
72 for (std::size_t j=0; j<ublas_A.size2(); ++j)
73 ublas_A(i,j) =
static_cast<ScalarType
>((i+1) + (j+1)*(i+1));
75 for (std::size_t i=0; i<ublas_B.size1(); ++i)
76 for (std::size_t j=0; j<ublas_B.size2(); ++j)
77 ublas_B(i,j) =
static_cast<ScalarType
>((i+1) + (j+1)*(i+1));
79 for (std::size_t i=0; i<ublas_C.size1(); ++i)
80 for (std::size_t j=0; j<ublas_C.size2(); ++j)
81 ublas_C(i,j) =
static_cast<ScalarType
>((j+2) + (j+1)*(i+1));
83 for (std::size_t i=0; i<ublas_D.size1(); ++i)
84 for (std::size_t j=0; j<ublas_D.size2(); ++j)
85 ublas_D(i,j) =
static_cast<ScalarType
>((j+2) + (j+1)*(i+1));
92 boost::numeric::ublas::matrix_range<MatrixType> ublas_A_sub1(ublas_A, ublas_r1, ublas_r1);
93 boost::numeric::ublas::matrix_range<MatrixType> ublas_A_sub2(ublas_A, ublas_r2, ublas_r2);
95 boost::numeric::ublas::matrix_range<MatrixType> ublas_C_sub(ublas_C, ublas_r1, ublas_r1);
96 boost::numeric::ublas::matrix_range<MatrixType> ublas_D_sub(ublas_D, ublas_r1, ublas_r1);
101 VCLMatrixType vcl_A(dim_large, dim_large);
102 VCLMatrixType vcl_B(dim_small, dim_small);
103 VCLMatrixType vcl_C(dim_large, dim_small);
104 VCLMatrixType vcl_D(dim_small, dim_large);
126 ublas_A_sub1 = ublas_B;
135 ublas_A_sub2 += ublas_A_sub2;
136 vcl_A_sub2 += vcl_A_sub2;
139 ublas_B += ublas_A_sub2;
146 ublas_A_sub1 +=
prod(ublas_C_sub, ublas_D_sub);
152 std::cout <<
"Result ublas: " << ublas_A << std::endl;
153 std::cout <<
"Result ViennaCL: " << vcl_A << std::endl;
158 std::cout <<
"!!!! TUTORIAL COMPLETED SUCCESSFULLY !!!!" << std::endl;
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Implementation of the dense matrix class.
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
Proxy classes for matrices.
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)
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 range class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
Class for representing non-strided submatrices of a bigger matrix A.
Implementation of the ViennaCL scalar class.