6 template <
typename T,
typename VEC1,
typename VEC2>
7 void matvec_core(
const matrix::LinearOperator<T> &A,
const VEC1 &x, VEC2 &y) {
12 assert(A.get_row() == y.size());
13 assert(A.get_col() == x.size());
15 if (A.get_matvec_init_flag()) {
17 const size_t xoffset = x.get_offset();
18 const size_t yoffset = y.get_offset();
20 vector<T> x_tmp(x.size(), 0);
21 if (x.get_device_mem_stat())
23 vector<T> y_tmp(y.size(), 0);
24 if (y.get_device_mem_stat())
27 internal::vcopy(x.size(), x.data() + xoffset, x_tmp.data(),
28 x.get_device_mem_stat());
30 y_tmp = A.get_matvec()(x_tmp);
32 internal::vcopy(y.size(), y_tmp.data(), y.data() + yoffset,
33 y.get_device_mem_stat());
35 throw std::runtime_error(
"error matvec is not initialized");
41 template <
typename T,
typename VEC1,
typename VEC2>
42 void rmatvec_core(
const matrix::LinearOperator<T> &A,
const VEC1 &x, VEC2 &y) {
47 assert(A.get_row() == x.size());
48 assert(A.get_col() == y.size());
50 if (A.get_rmatvec_init_flag()) {
51 const size_t xoffset = x.get_offset();
52 const size_t yoffset = y.get_offset();
54 vector<T> x_tmp(x.size(), 0);
55 if (x.get_device_mem_stat())
57 vector<T> y_tmp(y.size(), 0);
58 if (y.get_device_mem_stat())
61 internal::vcopy(x.size(), x.data() + xoffset, x_tmp.data(),
62 x.get_device_mem_stat());
64 y_tmp = A.get_rmatvec()(x_tmp);
66 internal::vcopy(y.size(), y_tmp.data(), y.data() + yoffset,
67 y.get_device_mem_stat());
69 throw std::runtime_error(
"error rmatmul is not initialized");