Esempio n. 1
0
NumericT diff(std::vector<std::vector<NumericT> > const & A1, viennacl::matrix<NumericT> const & A2)
{
  std::vector<NumericT> host_values(A2.internal_size());
  for (std::size_t i=0; i<A2.size1(); ++i)
    for (std::size_t j=0; j<A2.size2(); ++j)
      host_values[i*A2.internal_size2() + j] = A1[i][j];

  std::vector<NumericT> device_values(A2.internal_size());
  viennacl::fast_copy(A2, &device_values[0]);
  viennacl::vector<NumericT> vcl_device_values(A2.internal_size());  // workaround to avoid code duplication
  viennacl::copy(device_values, vcl_device_values);

  return diff(host_values, vcl_device_values);
}
Esempio n. 2
0
File: main.cpp Progetto: Franz-S/SOC
void init_random(viennacl::matrix<T, F> & M)
{
    std::vector<T> cM(M.internal_size());
    for (std::size_t i = 0; i < M.size1(); ++i)
        for (std::size_t j = 0; j < M.size2(); ++j)
            cM[F::mem_index(i, j, M.internal_size1(), M.internal_size2())] = T(rand())/T(RAND_MAX);
    viennacl::fast_copy(&cM[0],&cM[0] + cM.size(),M);
}
Esempio n. 3
0
float matrix_compare(viennacl::matrix<ScalarType>& res,
                     viennacl::matrix<ScalarType>& ref)
{
    std::vector<ScalarType> res_std(res.internal_size());
    std::vector<ScalarType> ref_std(ref.internal_size());

    viennacl::fast_copy(res, &res_std[0]);
    viennacl::fast_copy(ref, &ref_std[0]);

    float diff = 0.0;
    float mx = 0.0;

    for(std::size_t i = 0; i < res_std.size(); i++) {
        diff = std::max(diff, std::abs(res_std[i] - ref_std[i]));
        mx = std::max(mx, res_std[i]);
    }

    return diff / mx;
}
 viennacl::vector_range<viennacl::vector_base<T> > sharedVector(){
     viennacl::vector_base<T> tmp(ptr_matrix->handle(), ptr_matrix->internal_size(), 0, 1);
     viennacl::vector_range<viennacl::vector_base<T> > v_sub(tmp, r);
     return v_sub;
 }