18 #ifndef TEST_MATRIX_PRODUCT_FLOAT_DOUBLE_HPP_ 
   19 #define TEST_MATRIX_PRODUCT_FLOAT_DOUBLE_HPP_ 
   22 #define BOOST_UBLAS_NDEBUG 
   30 #include "boost/numeric/ublas/matrix.hpp" 
   31 #include "boost/numeric/ublas/matrix_proxy.hpp" 
   32 #include "boost/numeric/ublas/io.hpp" 
   36 template<
typename ScalarType, 
typename VCLMatrixType>
 
   37 ScalarType diff(boost::numeric::ublas::matrix<ScalarType> 
const & mat1, VCLMatrixType  
const & mat2)
 
   39    boost::numeric::ublas::matrix<ScalarType> mat2_cpu(mat2.size1(), mat2.size2());
 
   45     for (
unsigned int i = 0; i < mat2_cpu.size1(); ++i)
 
   47       for (
unsigned int j = 0; j < mat2_cpu.size2(); ++j)
 
   49          act = std::fabs(mat2_cpu(i,j) - mat1(i,j)) / 
std::max( std::fabs(mat2_cpu(i, j)), std::fabs(mat1(i,j)) );
 
   59 template<
class UBlasType, 
class F>
 
   62 template<
class T, 
class F>
 
   74 template<
class MatrixT, 
class F>
 
   75 struct matrix_maker< boost::numeric::ublas::matrix_range<MatrixT>, F>
 
   77   typedef typename MatrixT::value_type 
T;
 
   90 template<
class MatrixT, 
class F>
 
   91 struct matrix_maker< boost::numeric::ublas::matrix_slice<MatrixT>, F>
 
   93   typedef typename MatrixT::value_type 
T;
 
   98     viennacl::slice s0(base.start1(), std::size_t(base.stride1()), base.size1());
 
  106 template<
typename T, 
typename CType, 
typename AType, 
typename BType>
 
  107 int test_layout(CType & C, AType 
const & A, AType 
const & AT, BType 
const & B, BType 
const & BT,
 
  108                 boost::numeric::ublas::matrix<T> 
const & ground, T epsilon, 
bool with_composite)
 
  113   std::cout << 
"C = A.B" << std::endl;
 
  115   if (
diff(ground, C)>epsilon)
 
  118   std::cout << 
"C = A'.B" << std::endl;
 
  120   if (
diff(ground, C)>epsilon)
 
  123   std::cout << 
"C = A.B'" << std::endl;
 
  125   if (
diff(ground, C)>epsilon)
 
  128   std::cout << 
"C = A'.B'" << std::endl;
 
  130   if (
diff(ground, C)>epsilon)
 
  136     boost::numeric::ublas::matrix<T> ground2 = T(2) * ground;
 
  138     std::cout << 
"C = (A + A).B" << std::endl;
 
  140     if (
diff(ground2, C)>epsilon)
 
  143     std::cout << 
"C = trans(AT + AT).B" << std::endl;
 
  145     if (
diff(ground2, C)>epsilon)
 
  148     std::cout << 
"C = A.(B + B)" << std::endl;
 
  149     C = 
prod(A, T(2) * B);
 
  150     if (
diff(ground2, C)>epsilon)
 
  153     std::cout << 
"C = A.trans(BT + BT)" << std::endl;
 
  155     if (
diff(ground2, C)>epsilon)
 
  158     std::cout << 
"C = (A + A).(B + B)" << std::endl;
 
  159     C = T(0.25) * 
prod(A + A, B + B);
 
  160     if (
diff(ground, C)>epsilon)
 
  163     std::cout << 
"C = trans(AT + AT).trans(BT + BT)" << std::endl;
 
  166     if (
diff(ground, C)>epsilon)
 
  174 template<
typename T, 
typename RefAType, 
typename RefBType, 
typename RefCType>
 
  176                      std::size_t AM, std::size_t AK, RefAType & cA, RefAType & cAT,
 
  177                      std::size_t BK, std::size_t BN, RefBType & cB,  RefBType & cBT,
 
  208 #define TEST_LAYOUT(Clayout, Alayout, Blayout, composite) \ 
  209   std::cout << "> "  #Clayout " = " #Alayout "." #Blayout << std::endl;  \ 
  210   if (test_layout(C ## Clayout, A ## Alayout, AT ## Alayout, B ## Blayout, BT ## Blayout, ground, epsilon, composite) != EXIT_SUCCESS) \ 
  211     return EXIT_FAILURE; \ 
  227 template<
class MatrixType>
 
  230   typedef typename MatrixType::value_type T;
 
  234   for (
unsigned int i = 0; i < A.size1(); ++i)
 
  235     for (
unsigned int j = 0; j < A.size2(); ++j)
 
  236       A(i, j) = 
static_cast<T
>(0.1) * randomNumber();
 
  244     typedef boost::numeric::ublas::matrix<T> matrix_type;
 
  245     typedef boost::numeric::ublas::matrix_range<matrix_type> matrix_range_type;
 
  246     typedef boost::numeric::ublas::matrix_slice<matrix_type> matrix_slice_type;
 
  248     typedef typename matrix_type::difference_type difference_type;
 
  250     std::size_t matrix_holder_M = 143;
 
  251     std::size_t matrix_holder_N = 124;
 
  252     std::size_t matrix_holder_K = 184;
 
  254     std::size_t start_M = 14;
 
  255     std::size_t start_N = 20;
 
  256     std::size_t start_K = 73;
 
  258     std::size_t range_holder_M = start_M + matrix_holder_M;
 
  259     std::size_t range_holder_N = start_N + matrix_holder_N;
 
  260     std::size_t range_holder_K = start_K + matrix_holder_K;
 
  262     range_type range_M(start_M, range_holder_M);
 
  263     range_type range_N(start_N, range_holder_N);
 
  264     range_type range_K(start_K, range_holder_K);
 
  266     difference_type stride_M = 9;
 
  267     difference_type stride_N = 13;
 
  268     difference_type stride_K = 4;
 
  270     std::size_t slice_holder_M = start_M + std::size_t(stride_M)*matrix_holder_M;
 
  271     std::size_t slice_holder_N = start_N + std::size_t(stride_N)*matrix_holder_N;
 
  272     std::size_t slice_holder_K = start_K + std::size_t(stride_K)*matrix_holder_K;
 
  274     slice_type slice_M(start_M, stride_M, matrix_holder_M);
 
  275     slice_type slice_N(start_N, stride_N, matrix_holder_N);
 
  276     slice_type slice_K(start_K, stride_K, matrix_holder_K);
 
  278 #define DECLARE(NAME, size1, size2) \ 
  279     matrix_type NAME ## _matrix(matrix_holder_ ## size1, matrix_holder_ ## size2);\ 
  280     init_rand(NAME ## _matrix);\ 
  281     matrix_type NAME ## T_matrix = boost::numeric::ublas::trans(NAME ## _matrix);\ 
  283     matrix_type NAME ## _range_holder(range_holder_ ## size1, range_holder_ ## size2);\ 
  284     init_rand(NAME ## _range_holder);\ 
  285     matrix_range_type NAME ## _range(NAME ## _range_holder, range_ ## size1, range_ ## size2);\ 
  286     matrix_type NAME ## T_range_holder = boost::numeric::ublas::trans(NAME ## _range_holder);\ 
  287     matrix_range_type NAME ## T_range(NAME ## T_range_holder, range_ ## size2, range_ ## size1);\ 
  289     matrix_type NAME ## _slice_holder(slice_holder_ ## size1, slice_holder_ ## size2);\ 
  290     init_rand(NAME ## _slice_holder);\ 
  291     matrix_slice_type NAME ## _slice(NAME ## _slice_holder, slice_ ## size1, slice_ ## size2);\ 
  292     matrix_type NAME ## T_slice_holder = boost::numeric::ublas::trans(NAME ## _slice_holder);\ 
  293     matrix_slice_type NAME ## T_slice(NAME ## T_slice_holder, slice_ ## size2, slice_ ## size1);\ 
  300 #define TEST_ALL_LAYOUTS(C_TYPE, A_TYPE, B_TYPE)\ 
  301     std::cout << ">> " #C_TYPE " = " #A_TYPE "." #B_TYPE << std::endl;\ 
  302     if (test_all_layouts<T>(C_TYPE ## _holder_M, C_TYPE ## _holder_N, C_ ## C_TYPE,\ 
  303                             A_TYPE ## _holder_M, A_TYPE ## _holder_K, A_ ## A_TYPE, AT_ ## A_TYPE,\ 
  304                             B_TYPE ## _holder_K, B_TYPE ## _holder_N, B_ ## B_TYPE, BT_ ## B_TYPE, epsilon) != EXIT_SUCCESS)\ 
  305       return EXIT_FAILURE;\ 
  346 #undef TEST_ALL_LAYOUTS 
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. 
Class for representing strided submatrices of a bigger matrix A. 
std::vector< std::vector< NumericT > > trans(std::vector< std::vector< NumericT > > const &A)
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Implementation of the dense matrix class. 
void finish()
Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed. 
viennacl::scalar< float > s1
T max(const T &lhs, const T &rhs)
Maximum. 
#define DECLARE(NAME, size1, size2)
#define TEST_ALL_LAYOUTS(C_TYPE, A_TYPE, B_TYPE)
ScalarType diff(boost::numeric::ublas::matrix< ScalarType > const &mat1, VCLMatrixType const &mat2)
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
int test_all_layouts(std::size_t CM, std::size_t CN, RefCType &cC, std::size_t AM, std::size_t AK, RefAType &cA, RefAType &cAT, std::size_t BK, std::size_t BN, RefBType &cB, RefBType &cBT, T epsilon)
void init_rand(MatrixType &A)
static result_type make(viennacl::matrix< T, F > const &, boost::numeric::ublas::matrix< T > &base)
#define TEST_LAYOUT(Clayout, Alayout, Blayout, composite)
vector_expression< const matrix_base< NumericT, F >, const unsigned int, op_row > row(const matrix_base< NumericT, F > &A, unsigned int i)
Proxy classes for matrices. 
static result_type make(viennacl::matrix< T, F > &M, boost::numeric::ublas::matrix_slice< MatrixT > &base)
viennacl::matrix_slice< viennacl::matrix< T, F > > result_type
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)
static result_type make(viennacl::matrix< T, F > &M, boost::numeric::ublas::matrix_range< MatrixT > &base)
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. 
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. 
A slice class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded. 
viennacl::matrix_range< viennacl::matrix< T, F > > result_type
int test_layout(CType &C, AType const &A, AType const &AT, BType const &B, BType const &BT, boost::numeric::ublas::matrix< T > const &ground, T epsilon, bool with_composite)
viennacl::matrix< T, F > result_type