1 #ifndef VIENNACL_VECTOR_HPP_
2 #define VIENNACL_VECTOR_HPP_
46 template<
typename SCALARTYPE>
47 class implicit_vector_base
91 template <
typename SCALARTYPE>
99 assert( (ind < s) &&
bool(
"Provided index out of range!") );
105 template <
typename SCALARTYPE>
106 class zero_vector :
public implicit_vector_base<SCALARTYPE>
108 typedef implicit_vector_base<SCALARTYPE> base_type;
116 template <
typename SCALARTYPE>
117 class one_vector :
public implicit_vector_base<SCALARTYPE>
119 typedef implicit_vector_base<SCALARTYPE> base_type;
128 template <
typename SCALARTYPE>
129 class scalar_vector :
public implicit_vector_base<SCALARTYPE>
131 typedef implicit_vector_base<SCALARTYPE> base_type;
164 template <
typename LHS,
typename RHS,
typename OP>
165 class vector_expression
167 typedef typename viennacl::result_of::reference_if_nonscalar<LHS>::type lhs_reference_type;
168 typedef typename viennacl::result_of::reference_if_nonscalar<RHS>::type rhs_reference_type;
181 lhs_reference_type
lhs()
const {
return lhs_; }
184 rhs_reference_type
rhs()
const {
return rhs_; }
191 lhs_reference_type lhs_;
193 rhs_reference_type rhs_;
214 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
215 class const_vector_iterator
217 typedef const_vector_iterator<SCALARTYPE, ALIGNMENT> self_type;
310 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
362 template<
class SCALARTYPE,
typename SizeType ,
typename DistanceType >
365 typedef vector_base<SCALARTYPE> self_type;
380 explicit vector_base() : size_(0), start_(0), stride_(1), internal_size_(0) { }
393 : size_(vec_size), start_(vec_start), stride_(vec_stride), internal_size_(vec_size), elements_(h) {}
408 : size_(vec_size), start_(
start), stride_(
stride), internal_size_(vec_size)
412 #ifdef VIENNACL_WITH_CUDA
414 elements_.cuda_handle().reset(reinterpret_cast<char*>(ptr_to_mem));
415 elements_.cuda_handle().inc();
427 elements_.
raw_size(
sizeof(SCALARTYPE) * vec_size);
431 #ifdef VIENNACL_WITH_OPENCL
441 : size_(vec_size), start_(
start), stride_(
stride), internal_size_(vec_size)
444 elements_.opencl_handle() = existing_mem;
445 elements_.opencl_handle().inc();
446 elements_.opencl_handle().context(ctx.opencl_context());
447 elements_.
raw_size(
sizeof(SCALARTYPE) * vec_size);
462 template <
typename LHS,
typename RHS,
typename OP>
485 && bool(
"Incompatible vector sizes!"));
492 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_,
alignment);
510 template <
typename LHS,
typename RHS,
typename OP>
514 &&
bool(
"Incompatible vector sizes!"));
520 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_,
alignment);
531 template <
typename T>
535 assert( ( (v1.size() ==
size()) || (
size() == 0) )
536 && bool(
"Incompatible vector sizes!"));
543 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_,
alignment);
550 v1, SCALARTYPE(1.0), 1,
false,
false);
559 && bool(
"Incompatible vector sizes!"));
564 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_,
alignment);
583 assert( ( (v.size() ==
size()) || (
size() == 0) )
584 && bool(
"Incompatible vector sizes!"));
589 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_,
alignment);
605 assert( ( (v.size() ==
size()) || (
size() == 0) )
606 && bool(
"Incompatible vector sizes!"));
611 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_,
alignment);
637 template <
typename F>
662 template <
typename F>
691 assert( (
size() > 0) &&
bool(
"Cannot apply operator() to vector of size zero!"));
692 assert( index <
size() &&
bool(
"Index out of bounds!") );
701 assert( (
size() > 0) &&
bool(
"Cannot apply operator() to vector of size zero!"));
702 assert( index <
size() &&
bool(
"Index out of bounds!") );
712 assert( (
size() > 0) &&
bool(
"Cannot apply operator() to vector of size zero!"));
713 assert( index <
size() &&
bool(
"Index out of bounds!") );
722 assert( (
size() > 0) &&
bool(
"Cannot apply operator() to vector of size zero!"));
723 assert( index <
size() &&
bool(
"Index out of bounds!") );
733 assert(vec.
size() ==
size() && bool(
"Incompatible vector sizes!"));
737 *
this, SCALARTYPE(1.0), 1,
false,
false,
738 vec, SCALARTYPE(1.0), 1,
false,
false);
744 assert(vec.
size() ==
size() && bool(
"Incompatible vector sizes!"));
748 *
this, SCALARTYPE(1.0), 1,
false,
false,
749 vec, SCALARTYPE(-1.0), 1,
false,
false);
753 template <
typename LHS,
typename RHS,
typename OP>
757 assert( (
size() > 0) &&
bool(
"Vector not yet initialized!") );
764 template <
typename LHS,
typename RHS,
typename OP>
768 assert( (
size() > 0) &&
bool(
"Vector not yet initialized!") );
781 *
this, val, 1,
false,
false);
791 *
this, val, 1,
true,
false);
827 return iterator(*
this, 0, start_, stride_);
875 bool empty()
const {
return size_ == 0; }
906 assert(this->size_ == other.size_ &&
bool(
"Vector size mismatch"));
907 this->elements_.
swap(other.elements_);
923 viennacl::backend::switch_memory_context<SCALARTYPE>(elements_, new_ctx);
949 resize_impl(new_size, ctx, preserve);
956 assert(new_size > 0 &&
bool(
"Positive size required when resizing vector!"));
958 if (new_size != size_)
960 vcl_size_t new_internal_size = viennacl::tools::align_to_multiple<vcl_size_t>(new_size,
alignment);
962 std::vector<SCALARTYPE> temp(size_);
963 if (preserve && size_ > 0)
965 temp.resize(new_size);
966 temp.resize(new_internal_size);
975 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_,
alignment);
999 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
1000 class vector :
public vector_base<SCALARTYPE>
1002 typedef vector<SCALARTYPE, ALIGNMENT> self_type;
1003 typedef vector_base<SCALARTYPE> base_type;
1024 #ifdef VIENNACL_WITH_OPENCL
1043 template <
typename LHS,
typename RHS,
typename OP>
1049 base_type::operator=(v);
1055 base_type::operator=(v);
1062 this->
operator()(v.
index()) = SCALARTYPE(1);;
1080 template <
typename T>
1087 using base_type::operator+=;
1088 using base_type::operator-=;
1122 template <
typename ScalarT>
1125 typedef vector_base<ScalarT> VectorType;
1132 const_vectors_[0] = &v0;
1133 const_vectors_[1] = &v1;
1137 const_vectors_[0] = &v0; non_const_vectors_[0] = &v0;
1138 const_vectors_[1] = &v1; non_const_vectors_[1] = &v1;
1145 const_vectors_[0] = &v0;
1146 const_vectors_[1] = &v1;
1147 const_vectors_[2] = &v2;
1151 const_vectors_[0] = &v0; non_const_vectors_[0] = &v0;
1152 const_vectors_[1] = &v1; non_const_vectors_[1] = &v1;
1153 const_vectors_[2] = &v2; non_const_vectors_[2] = &v2;
1160 const_vectors_[0] = &v0;
1161 const_vectors_[1] = &v1;
1162 const_vectors_[2] = &v2;
1163 const_vectors_[3] = &v3;
1167 const_vectors_[0] = &v0; non_const_vectors_[0] = &v0;
1168 const_vectors_[1] = &v1; non_const_vectors_[1] = &v1;
1169 const_vectors_[2] = &v2; non_const_vectors_[2] = &v2;
1170 const_vectors_[3] = &v3; non_const_vectors_[3] = &v3;
1177 vector_tuple(std::vector<VectorType const *>
const & vecs) : const_vectors_(vecs.
size()), non_const_vectors_()
1180 const_vectors_[i] = vecs[i];
1183 vector_tuple(std::vector<VectorType *>
const & vecs) : const_vectors_(vecs.
size()), non_const_vectors_(vecs.
size())
1187 const_vectors_[i] = vecs[i];
1188 non_const_vectors_[i] = vecs[i];
1199 std::vector<VectorType const *> const_vectors_;
1200 std::vector<VectorType *> non_const_vectors_;
1204 template <
typename ScalarT>
1207 template <
typename ScalarT>
1211 template <
typename ScalarT>
1214 template <
typename ScalarT>
1218 template <
typename ScalarT>
1224 template <
typename ScalarT>
1231 template <
typename ScalarT>
1239 std::vector<VectorPointerType> vec(5);
1248 template <
typename ScalarT>
1256 std::vector<VectorPointerType> vec(5);
1283 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1286 CPU_ITERATOR cpu_begin )
1288 if (gpu_begin != gpu_end)
1290 if (gpu_begin.stride() == 1)
1293 sizeof(SCALARTYPE)*gpu_begin.offset(),
1294 sizeof(SCALARTYPE)*gpu_begin.stride() * (gpu_end - gpu_begin),
1300 std::vector<SCALARTYPE> temp_buffer(gpu_begin.stride() * gpu_size);
1301 viennacl::backend::memory_read(gpu_begin.handle(),
sizeof(SCALARTYPE)*gpu_begin.offset(),
sizeof(SCALARTYPE)*temp_buffer.size(), &(temp_buffer[0]));
1305 (&(*cpu_begin))[i] = temp_buffer[i * gpu_begin.stride()];
1316 template <
typename NumericT,
typename CPUVECTOR>
1333 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1336 CPU_ITERATOR cpu_begin )
1338 if (gpu_begin != gpu_end)
1340 if (gpu_begin.stride() == 1)
1343 sizeof(SCALARTYPE)*gpu_begin.offset(),
1344 sizeof(SCALARTYPE)*gpu_begin.stride() * (gpu_end - gpu_begin),
1349 fast_copy(gpu_begin, gpu_end, cpu_begin);
1358 template <
typename NumericT,
typename CPUVECTOR>
1371 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1374 CPU_ITERATOR cpu_begin )
1376 assert(gpu_end - gpu_begin >= 0 &&
bool(
"Iterators incompatible"));
1377 if (gpu_end - gpu_begin != 0)
1379 std::vector<SCALARTYPE> temp_buffer(gpu_end - gpu_begin);
1380 fast_copy(gpu_begin, gpu_end, temp_buffer.begin());
1383 std::copy(temp_buffer.begin(), temp_buffer.end(), cpu_begin);
1393 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1396 CPU_ITERATOR cpu_begin )
1409 template <
typename NumericT,
typename CPUVECTOR>
1417 #ifdef VIENNACL_WITH_EIGEN
1418 template <
unsigned int ALIGNMENT>
1419 void copy(vector<float, ALIGNMENT>
const & gpu_vec,
1420 Eigen::VectorXf & eigen_vec)
1425 template <
unsigned int ALIGNMENT>
1426 void copy(vector<double, ALIGNMENT> & gpu_vec,
1427 Eigen::VectorXd & eigen_vec)
1449 template <
typename CPU_ITERATOR,
typename SCALARTYPE,
unsigned int ALIGNMENT>
1451 CPU_ITERATOR
const & cpu_end,
1454 if (cpu_end - cpu_begin > 0)
1456 if (gpu_begin.
stride() == 1)
1459 sizeof(SCALARTYPE)*gpu_begin.
offset(),
1460 sizeof(SCALARTYPE)*gpu_begin.
stride() * (cpu_end - cpu_begin), &(*cpu_begin));
1465 std::vector<SCALARTYPE> temp_buffer(gpu_begin.
stride() * cpu_size);
1470 temp_buffer[i * gpu_begin.
stride()] = (&(*cpu_begin))[i];
1483 template <
typename CPUVECTOR,
typename NumericT>
1499 template <
typename CPU_ITERATOR,
typename SCALARTYPE,
unsigned int ALIGNMENT>
1501 CPU_ITERATOR
const & cpu_end,
1504 if (cpu_end - cpu_begin > 0)
1506 if (gpu_begin.
stride() == 1)
1509 sizeof(SCALARTYPE)*gpu_begin.
offset(),
1510 sizeof(SCALARTYPE)*gpu_begin.
stride() * (cpu_end - cpu_begin), &(*cpu_begin),
1514 fast_copy(cpu_begin, cpu_end, gpu_begin);
1524 template <
typename CPUVECTOR,
typename NumericT>
1537 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1538 void copy(CPU_ITERATOR
const & cpu_begin,
1539 CPU_ITERATOR
const & cpu_end,
1542 assert(cpu_end - cpu_begin > 0 &&
bool(
"Iterators incompatible"));
1543 if (cpu_begin != cpu_end)
1546 std::vector<SCALARTYPE> temp_buffer(cpu_end - cpu_begin);
1547 std::copy(cpu_begin, cpu_end, temp_buffer.begin());
1559 template <
typename CPUVECTOR,
typename T>
1566 #ifdef VIENNACL_WITH_EIGEN
1567 template <
unsigned int ALIGNMENT>
1568 void copy(Eigen::VectorXf
const & eigen_vec,
1569 vector<float, ALIGNMENT> & gpu_vec)
1571 std::vector<float> entries(eigen_vec.size());
1572 for (
vcl_size_t i = 0; i<entries.size(); ++i)
1573 entries[i] = eigen_vec(i);
1577 template <
unsigned int ALIGNMENT>
1578 void copy(Eigen::VectorXd
const & eigen_vec,
1579 vector<double, ALIGNMENT> & gpu_vec)
1581 std::vector<double> entries(eigen_vec.size());
1582 for (
vcl_size_t i = 0; i<entries.size(); ++i)
1583 entries[i] = eigen_vec(i);
1599 template <
typename SCALARTYPE,
unsigned int ALIGNMENT_SRC,
unsigned int ALIGNMENT_DEST>
1604 assert(gpu_src_end - gpu_src_begin >= 0);
1605 assert(gpu_src_begin.stride() == 1 && bool(
"ViennaCL ERROR: copy() for GPU->GPU not implemented for slices! Use operator= instead for the moment."));
1607 if (gpu_src_begin.stride() == 1 && gpu_dest_begin.
stride() == 1)
1609 if (gpu_src_begin != gpu_src_end)
1611 sizeof(SCALARTYPE) * gpu_src_begin.offset(),
1612 sizeof(SCALARTYPE) * gpu_dest_begin.
offset(),
1613 sizeof(SCALARTYPE) * (gpu_src_end.offset() - gpu_src_begin.offset()));
1617 assert(
false &&
bool(
"not implemented yet"));
1627 template <
typename SCALARTYPE,
unsigned int ALIGNMENT_SRC,
unsigned int ALIGNMENT_DEST>
1642 template <
typename SCALARTYPE,
unsigned int ALIGNMENT_SRC,
unsigned int ALIGNMENT_DEST>
1646 viennacl::copy(gpu_src_vec.begin(), gpu_src_vec.end(), gpu_dest_vec.begin());
1659 template <
typename T>
1660 std::ostream & operator<<(std::ostream & os, vector_base<T>
const & val)
1662 std::vector<T> tmp(val.size());
1664 os <<
"[" << val.size() <<
"](";
1665 for (
typename std::vector<T>::size_type i=0; i<val.size(); ++i)
1675 template <
typename LHS,
typename RHS,
typename OP>
1676 std::ostream & operator<<(std::ostream & os, vector_expression<LHS, RHS, OP>
const & proxy)
1690 template <
typename T>
1701 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
1705 return v1.fast_swap(v2);
1725 template <
typename T,
typename S1>
1745 template <
typename T,
typename S1>
1768 template <
typename LHS1,
typename RHS1,
typename OP1,
1769 typename LHS2,
typename RHS2,
typename OP2>
1770 vector_expression< const vector_expression< LHS1, RHS1, OP1>,
1771 const vector_expression< LHS2, RHS2, OP2>,
1776 assert(proxy1.size() == proxy2.size() && bool(
"Incompatible vector sizes!"));
1787 template <
typename LHS,
typename RHS,
typename OP,
typename T>
1788 vector_expression< const vector_expression<LHS, RHS, OP>,
1789 const vector_base<T>,
1794 assert(proxy.size() == vec.size() && bool(
"Incompatible vector sizes!"));
1805 template <
typename T,
typename LHS,
typename RHS,
typename OP>
1806 vector_expression< const vector_base<T>,
1807 const vector_expression<LHS, RHS, OP>,
1812 assert(proxy.size() == vec.size() && bool(
"Incompatible vector sizes!"));
1820 template <
typename T>
1821 vector_expression< const vector_base<T>,
const vector_base<T>, op_add>
1838 template <
typename LHS1,
typename RHS1,
typename OP1,
1839 typename LHS2,
typename RHS2,
typename OP2>
1840 vector_expression< const vector_expression< LHS1, RHS1, OP1>,
1841 const vector_expression< LHS2, RHS2, OP2>,
1846 assert(proxy1.size() == proxy2.size() && bool(
"Incompatible vector sizes!"));
1858 template <
typename LHS,
typename RHS,
typename OP,
typename T>
1859 vector_expression< const vector_expression<LHS, RHS, OP>,
1860 const vector_base<T>,
1865 assert(proxy.size() == vec.size() && bool(
"Incompatible vector sizes!"));
1876 template <
typename T,
typename LHS,
typename RHS,
typename OP>
1877 vector_expression< const vector_base<T>,
1878 const vector_expression<LHS, RHS, OP>,
1883 assert(proxy.size() == vec.size() && bool(
"Incompatible vector sizes!"));
1891 template <
typename T>
1892 vector_expression< const vector_base<T>,
const vector_base<T>, op_sub>
1909 template <
typename S1,
typename T>
1911 vector_expression< const vector_base<T>,
const S1, op_mult> >::type
1922 template <
typename T>
1923 vector_expression< const vector_base<T>,
const T, op_mult>
1934 template <
typename T>
1935 vector_expression< const vector_base<T>,
const T, op_mult>
1946 template <
typename T>
1947 vector_expression< const vector_base<T>,
const T, op_mult>
1958 template <
typename T>
1959 vector_expression< const vector_base<T>,
const T, op_mult>
1973 template <
typename LHS,
typename RHS,
typename OP,
typename T>
1974 vector_expression< const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
1982 template <
typename T,
typename S1>
1984 vector_expression< const vector_base<T>,
const S1, op_mult> >::type
1990 template <
typename T>
1991 vector_expression< const vector_base<T>,
const T, op_mult>
2002 template <
typename LHS,
typename RHS,
typename OP,
typename S1>
2016 template <
typename S1,
typename LHS,
typename RHS,
typename OP>
2034 template <
typename S1,
typename LHS,
typename RHS,
typename OP>
2046 template <
typename T,
typename S1>
2048 vector_expression< const vector_base<T>,
const S1, op_div> >::type
2067 template <
typename T>
2068 struct op_executor<vector_base<T>, op_assign, vector_base<T> >
2070 static void apply(vector_base<T> & lhs, vector_base<T>
const & rhs)
2077 template <
typename T>
2078 struct op_executor<vector_base<T>, op_assign, vector_expression<const vector_base<T>, const vector_tuple<T>, op_inner_prod> >
2080 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_tuple<T>, op_inner_prod>
const & rhs)
2087 template <
typename T>
2088 struct op_executor<vector_base<T>, op_inplace_add, vector_base<T> >
2090 static void apply(vector_base<T> & lhs, vector_base<T>
const & rhs)
2092 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, rhs, T(1), 1,
false,
false);
2097 template <
typename T>
2098 struct op_executor<vector_base<T>, op_inplace_sub, vector_base<T> >
2100 static void apply(vector_base<T> & lhs, vector_base<T>
const & rhs)
2102 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, rhs, T(1), 1,
false,
true);
2110 template <
typename T,
typename ScalarType>
2111 struct op_executor<vector_base<T>, op_assign, vector_expression<const vector_base<T>, const ScalarType, op_mult> >
2114 template <
typename LHS,
typename RHS,
typename OP>
2115 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
const & proxy)
2117 T alpha = proxy.rhs();
2121 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar<T>, op_mult>
const & proxy)
2126 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const T, op_mult>
const & proxy)
2133 template <
typename T,
typename ScalarType>
2134 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_base<T>, const ScalarType, op_mult> >
2137 template <
typename LHS,
typename RHS,
typename OP>
2138 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
const & proxy)
2140 T alpha = proxy.rhs();
2141 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), alpha, 1,
false,
false);
2144 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar<T>, op_mult>
const & proxy)
2146 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
false);
2149 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const T, op_mult>
const & proxy)
2151 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
false);
2156 template <
typename T,
typename ScalarType>
2157 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vector_base<T>, const ScalarType, op_mult> >
2160 template <
typename LHS,
typename RHS,
typename OP>
2161 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
const & proxy)
2163 T alpha = proxy.rhs();
2164 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), alpha, 1,
false,
true);
2167 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar<T>, op_mult>
const & proxy)
2169 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
true);
2172 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const T, op_mult>
const & proxy)
2174 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
true);
2182 template <
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2183 struct op_executor<vector_base<T>, op_assign, vector_expression<const vector_expression<const LHS, const RHS, OP>, const ScalarType, op_mult> >
2185 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_mult>
const & proxy)
2187 vector<T> temp(proxy.lhs());
2188 lhs = temp * proxy.rhs();
2193 template <
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2194 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_expression<const LHS, const RHS, OP>, const ScalarType, op_mult> >
2196 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_mult>
const & proxy)
2198 vector<T> temp(proxy.lhs());
2199 lhs += temp * proxy.rhs();
2204 template <
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2205 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vector_expression<const LHS, const RHS, OP>, const ScalarType, op_mult> >
2207 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_mult>
const & proxy)
2209 vector<T> temp(proxy.lhs());
2210 lhs -= temp * proxy.rhs();
2218 template <
typename T,
typename ScalarType>
2219 struct op_executor<vector_base<T>, op_assign, vector_expression<const vector_base<T>, const ScalarType, op_div> >
2221 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const ScalarType, op_div>
const & proxy)
2228 template <
typename T,
typename ScalarType>
2229 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_base<T>, const ScalarType, op_div> >
2231 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const ScalarType, op_div>
const & proxy)
2233 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
true,
false);
2238 template <
typename T,
typename ScalarType>
2239 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vector_base<T>, const ScalarType, op_div> >
2241 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const ScalarType, op_div>
const & proxy)
2243 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
true,
true);
2251 template <
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2252 struct op_executor<vector_base<T>, op_assign, vector_expression<const vector_expression<const LHS, const RHS, OP>, const ScalarType, op_div> >
2254 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_div>
const & proxy)
2256 vector<T> temp(proxy.lhs());
2257 lhs = temp / proxy.rhs();
2262 template <
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2263 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_expression<const LHS, const RHS, OP>, const ScalarType, op_div> >
2265 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_div>
const & proxy)
2267 vector<T> temp(proxy.lhs());
2268 lhs += temp / proxy.rhs();
2273 template <
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2274 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vector_expression<const LHS, const RHS, OP>, const ScalarType, op_div> >
2276 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_div>
const & proxy)
2278 vector<T> temp(proxy.lhs());
2279 lhs -= temp / proxy.rhs();
2286 template <
typename T,
typename LHS,
typename RHS>
2287 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const RHS, op_add> >
2290 template <
typename LHS1,
typename RHS1>
2291 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_add>
const & proxy)
2293 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2294 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2296 if (op_aliasing_lhs || op_aliasing_rhs)
2298 vector_base<T> temp(proxy.lhs());
2299 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2304 op_executor<vector_base<T>, op_assign, LHS>::apply(lhs, proxy.lhs());
2305 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2310 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_add>
const & proxy)
2313 proxy.lhs(), T(1), 1,
false,
false,
2314 proxy.rhs(), T(1), 1,
false,
false);
2318 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_mult>,
2319 const vector_base<T>,
2320 op_add>
const & proxy)
2323 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2324 proxy.rhs(), T(1), 1,
false,
false);
2328 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_div>,
2329 const vector_base<T>,
2330 op_add>
const & proxy)
2333 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2334 proxy.rhs(), T(1), 1,
false,
false);
2338 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2339 const vector_expression<
const vector_base<T>,
const T, op_mult>,
2340 op_add>
const & proxy)
2343 proxy.lhs(), T(1), 1,
false,
false,
2344 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2348 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2349 const vector_expression<
const vector_base<T>,
const T, op_div>,
2350 op_add>
const & proxy)
2353 proxy.lhs(), T(1), 1,
false,
false,
2354 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2358 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_mult>,
2359 const vector_expression<
const vector_base<T>,
const T, op_mult>,
2360 op_add>
const & proxy)
2363 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2364 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2368 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_mult>,
2369 const vector_expression<
const vector_base<T>,
const T, op_div>,
2370 op_add>
const & proxy)
2373 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2374 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2378 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_div>,
2379 const vector_expression<
const vector_base<T>,
const T, op_mult>,
2380 op_add>
const & proxy)
2383 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2384 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2388 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_div>,
2389 const vector_expression<
const vector_base<T>,
const T, op_div>,
2390 op_add>
const & proxy)
2393 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2394 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2400 template <
typename T,
typename LHS,
typename RHS>
2401 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_add> >
2404 template <
typename LHS1,
typename RHS1>
2405 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_add>
const & proxy)
2407 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2408 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2410 if (op_aliasing_lhs || op_aliasing_rhs)
2412 vector_base<T> temp(proxy.lhs());
2413 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2418 op_executor<vector_base<T>, op_inplace_add, LHS>::apply(lhs, proxy.lhs());
2419 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2424 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_add>
const & proxy)
2427 proxy.lhs(), T(1), 1,
false,
false,
2428 proxy.rhs(), T(1), 1,
false,
false);
2432 template <
typename ScalarType>
2433 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2434 const vector_base<T>,
2435 op_add>
const & proxy)
2438 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2439 proxy.rhs(), T(1), 1,
false,
false);
2443 template <
typename ScalarType>
2444 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2445 const vector_base<T>,
2446 op_add>
const & proxy)
2449 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2450 proxy.rhs(), T(1), 1,
false,
false);
2454 template <
typename ScalarType>
2455 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2456 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2457 op_add>
const & proxy)
2460 proxy.lhs(), T(1), 1,
false,
false,
2461 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2465 template <
typename ScalarType>
2466 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2467 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2468 op_add>
const & proxy)
2471 proxy.lhs(), T(1), 1,
false,
false,
2472 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2476 template <
typename ScalarType1,
typename ScalarType2>
2477 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2478 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2479 op_add>
const & proxy)
2482 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2483 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2487 template <
typename ScalarType1,
typename ScalarType2>
2488 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2489 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2490 op_add>
const & proxy)
2493 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2494 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2498 template <
typename ScalarType1,
typename ScalarType2>
2499 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2500 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2501 op_add>
const & proxy)
2504 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2505 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2509 template <
typename ScalarType1,
typename ScalarType2>
2510 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2511 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2512 op_add>
const & proxy)
2515 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2516 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2523 template <
typename T,
typename LHS,
typename RHS>
2524 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_add> >
2527 template <
typename LHS1,
typename RHS1>
2528 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_add>
const & proxy)
2530 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2531 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2533 if (op_aliasing_lhs || op_aliasing_rhs)
2535 vector_base<T> temp(proxy.lhs());
2536 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2541 op_executor<vector_base<T>, op_inplace_sub, LHS>::apply(lhs, proxy.lhs());
2542 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2547 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_add>
const & proxy)
2550 proxy.lhs(), T(1), 1,
false,
true,
2551 proxy.rhs(), T(1), 1,
false,
true);
2555 template <
typename ScalarType>
2556 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2557 const vector_base<T>,
2558 op_add>
const & proxy)
2561 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2562 proxy.rhs(), T(1), 1,
false,
true);
2566 template <
typename ScalarType>
2567 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2568 const vector_base<T>,
2569 op_add>
const & proxy)
2572 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2573 proxy.rhs(), T(1), 1,
false,
true);
2577 template <
typename ScalarType>
2578 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2579 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2580 op_add>
const & proxy)
2583 proxy.lhs(), T(1), 1,
false,
true,
2584 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2588 template <
typename ScalarType>
2589 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2590 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2591 op_add>
const & proxy)
2594 proxy.lhs(), T(1), 1,
false,
true,
2595 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2599 template <
typename ScalarType1,
typename ScalarType2>
2600 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2601 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2602 op_add>
const & proxy)
2605 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2606 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2610 template <
typename ScalarType1,
typename ScalarType2>
2611 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2612 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2613 op_add>
const & proxy)
2616 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2617 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2621 template <
typename ScalarType1,
typename ScalarType2>
2622 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2623 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2624 op_add>
const & proxy)
2627 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2628 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2632 template <
typename ScalarType1,
typename ScalarType2>
2633 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2634 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2635 op_add>
const & proxy)
2638 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2639 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2650 template <
typename T,
typename LHS,
typename RHS>
2651 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const RHS, op_sub> >
2654 template <
typename LHS1,
typename RHS1>
2655 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2657 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2658 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2660 if (op_aliasing_lhs || op_aliasing_rhs)
2662 vector_base<T> temp(proxy.lhs());
2663 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2668 op_executor<vector_base<T>, op_assign, LHS>::apply(lhs, proxy.lhs());
2669 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2674 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_sub>
const & proxy)
2677 proxy.lhs(), T(1), 1,
false,
false,
2678 proxy.rhs(), T(1), 1,
false,
true);
2682 template <
typename ScalarType>
2683 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2684 const vector_base<T>,
2685 op_sub>
const & proxy)
2688 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2689 proxy.rhs(), T(1), 1,
false,
true);
2693 template <
typename ScalarType>
2694 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2695 const vector_base<T>,
2696 op_sub>
const & proxy)
2699 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2700 proxy.rhs(), T(1), 1,
false,
true);
2704 template <
typename ScalarType>
2705 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2706 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2707 op_sub>
const & proxy)
2710 proxy.lhs(), T(1), 1,
false,
false,
2711 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2715 template <
typename ScalarType>
2716 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2717 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2718 op_sub>
const & proxy)
2721 proxy.lhs(), T(1), 1,
false,
false,
2722 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2726 template <
typename ScalarType1,
typename ScalarType2>
2727 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2728 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2729 op_sub>
const & proxy)
2732 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2733 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2737 template <
typename ScalarType1,
typename ScalarType2>
2738 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2739 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2740 op_sub>
const & proxy)
2743 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2744 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2748 template <
typename ScalarType1,
typename ScalarType2>
2749 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2750 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2751 op_sub>
const & proxy)
2754 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2755 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2759 template <
typename ScalarType1,
typename ScalarType2>
2760 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2761 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2762 op_sub>
const & proxy)
2765 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2766 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2772 template <
typename T,
typename LHS,
typename RHS>
2773 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_sub> >
2776 template <
typename LHS1,
typename RHS1>
2777 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2779 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2780 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2782 if (op_aliasing_lhs || op_aliasing_rhs)
2784 vector_base<T> temp(proxy.lhs());
2785 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2790 op_executor<vector_base<T>, op_inplace_add, LHS>::apply(lhs, proxy.lhs());
2791 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2796 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_sub>
const & proxy)
2799 proxy.lhs(), T(1), 1,
false,
false,
2800 proxy.rhs(), T(1), 1,
false,
true);
2804 template <
typename ScalarType>
2805 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2806 const vector_base<T>,
2807 op_sub>
const & proxy)
2810 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2811 proxy.rhs(), T(1), 1,
false,
true);
2815 template <
typename ScalarType>
2816 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2817 const vector_base<T>,
2818 op_sub>
const & proxy)
2821 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2822 proxy.rhs(), T(1), 1,
false,
true);
2826 template <
typename ScalarType>
2827 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2828 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2829 op_sub>
const & proxy)
2832 proxy.lhs(), T(1), 1,
false,
false,
2833 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2837 template <
typename ScalarType>
2838 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2839 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2840 op_sub>
const & proxy)
2843 proxy.lhs(), T(1), 1,
false,
false,
2844 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2848 template <
typename ScalarType1,
typename ScalarType2>
2849 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2850 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2851 op_sub>
const & proxy)
2854 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2855 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2859 template <
typename ScalarType1,
typename ScalarType2>
2860 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2861 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2862 op_sub>
const & proxy)
2865 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2866 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2870 template <
typename ScalarType1,
typename ScalarType2>
2871 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2872 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2873 op_sub>
const & proxy)
2876 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2877 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2881 template <
typename ScalarType1,
typename ScalarType2>
2882 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2883 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2884 op_sub>
const & proxy)
2887 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2888 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2895 template <
typename T,
typename LHS,
typename RHS>
2896 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_sub> >
2899 template <
typename LHS1,
typename RHS1>
2900 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2902 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2903 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2905 if (op_aliasing_lhs || op_aliasing_rhs)
2907 vector_base<T> temp(proxy.lhs());
2908 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2913 op_executor<vector_base<T>, op_inplace_sub, LHS>::apply(lhs, proxy.lhs());
2914 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2919 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_sub>
const & proxy)
2922 proxy.lhs(), T(1), 1,
false,
true,
2923 proxy.rhs(), T(1), 1,
false,
false);
2927 template <
typename ScalarType>
2928 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2929 const vector_base<T>,
2930 op_sub>
const & proxy)
2933 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2934 proxy.rhs(), T(1), 1,
false,
false);
2938 template <
typename ScalarType>
2939 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2940 const vector_base<T>,
2941 op_sub>
const & proxy)
2944 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2945 proxy.rhs(), T(1), 1,
false,
false);
2949 template <
typename ScalarType>
2950 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2951 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2952 op_sub>
const & proxy)
2955 proxy.lhs(), T(1), 1,
false,
true,
2956 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2960 template <
typename ScalarType>
2961 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2962 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2963 op_sub>
const & proxy)
2966 proxy.lhs(), T(1), 1,
false,
true,
2967 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2971 template <
typename ScalarType1,
typename ScalarType2>
2972 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2973 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2974 op_sub>
const & proxy)
2977 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2978 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2982 template <
typename ScalarType1,
typename ScalarType2>
2983 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2984 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2985 op_sub>
const & proxy)
2988 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2989 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2993 template <
typename ScalarType1,
typename ScalarType2>
2994 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2995 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2996 op_sub>
const & proxy)
2999 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
3000 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
3004 template <
typename ScalarType1,
typename ScalarType2>
3005 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
3006 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
3007 op_sub>
const & proxy)
3010 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
3011 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
3035 template <
typename T,
typename LHS,
typename RHS,
typename OP>
3036 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const RHS, op_element_binary<OP> > >
3039 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3045 template <
typename LHS2,
typename RHS2,
typename OP2>
3046 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_expression<const LHS2, const RHS2, OP2>, op_element_binary<OP> >
const & proxy)
3048 vector<T> temp(proxy.rhs());
3053 template <
typename LHS1,
typename RHS1,
typename OP1>
3054 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3056 vector<T> temp(proxy.lhs());
3061 template <
typename LHS1,
typename RHS1,
typename OP1,
3062 typename LHS2,
typename RHS2,
typename OP2>
3063 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
3064 const vector_expression<const LHS2, const RHS2, OP2>,
3065 op_element_binary<OP> >
const & proxy)
3067 vector<T> temp1(proxy.lhs());
3068 vector<T> temp2(proxy.rhs());
3074 template <
typename T,
typename LHS,
typename RHS,
typename OP>
3075 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_element_binary<OP> > >
3078 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3085 template <
typename LHS2,
typename RHS2,
typename OP2>
3086 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_expression<const LHS2, const RHS2, OP2>, op_element_binary<OP> >
const & proxy)
3088 vector<T> temp(proxy.rhs());
3089 vector<T> temp2(temp.size());
3095 template <
typename LHS1,
typename RHS1,
typename OP1>
3096 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3098 vector<T> temp(proxy.lhs());
3099 vector<T> temp2(temp.size());
3105 template <
typename LHS1,
typename RHS1,
typename OP1,
3106 typename LHS2,
typename RHS2,
typename OP2>
3107 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
3108 const vector_expression<const LHS2, const RHS2, OP2>,
3109 op_element_binary<OP> >
const & proxy)
3111 vector<T> temp1(proxy.lhs());
3112 vector<T> temp2(proxy.rhs());
3113 vector<T> temp3(temp1.size());
3120 template <
typename T,
typename LHS,
typename RHS,
typename OP>
3121 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_element_binary<OP> > >
3125 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3132 template <
typename LHS2,
typename RHS2,
typename OP2>
3133 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_expression<const LHS2, const RHS2, OP2>, op_element_binary<OP> >
const & proxy)
3135 vector<T> temp(proxy.rhs());
3136 vector<T> temp2(temp.size());
3142 template <
typename LHS1,
typename RHS1,
typename OP1>
3143 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3145 vector<T> temp(proxy.lhs());
3146 vector<T> temp2(temp.size());
3152 template <
typename LHS1,
typename RHS1,
typename OP1,
3153 typename LHS2,
typename RHS2,
typename OP2>
3154 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
3155 const vector_expression<const LHS2, const RHS2, OP2>,
3156 op_element_binary<OP> >
const & proxy)
3158 vector<T> temp1(proxy.lhs());
3159 vector<T> temp2(proxy.rhs());
3160 vector<T> temp3(temp1.size());
3168 template <
typename T,
typename LHS,
typename RHS,
typename OP>
3169 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const RHS, op_element_unary<OP> > >
3172 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_unary<OP> >
const & proxy)
3178 template <
typename LHS2,
typename RHS2,
typename OP2>
3179 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS2, const RHS2, OP2>,
3180 const vector_expression<const LHS2, const RHS2, OP2>,
3181 op_element_unary<OP> >
const & proxy)
3183 vector<T> temp(proxy.rhs());
3188 template <
typename T,
typename LHS,
typename RHS,
typename OP>
3189 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_element_unary<OP> > >
3192 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_unary<OP> >
const & proxy)
3194 vector<T> temp(proxy);
3199 template <
typename LHS2,
typename RHS2,
typename OP2>
3200 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS2, const RHS2, OP2>,
3201 const vector_expression<const LHS2, const RHS2, OP2>,
3202 op_element_unary<OP> >
const & proxy)
3204 vector<T> temp(proxy.rhs());
3210 template <
typename T,
typename LHS,
typename RHS,
typename OP>
3211 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_element_unary<OP> > >
3214 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_unary<OP> >
const & proxy)
3216 vector<T> temp(proxy);
3221 template <
typename LHS2,
typename RHS2,
typename OP2>
3222 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS2, const RHS2, OP2>,
3223 const vector_expression<const LHS2, const RHS2, OP2>,
3224 op_element_unary<OP> >
const & proxy)
3226 vector<T> temp(proxy.rhs());
Simple enable-if variant that uses the SFINAE pattern.
Definition: enable_if.hpp:29
viennacl::enable_if< viennacl::is_any_scalar< S1 >::value, matrix_expression< const matrix_expression< const LHS, const RHS, OP >, const S1, op_div > >::type operator/(matrix_expression< const LHS, const RHS, OP > const &proxy, S1 const &val)
Operator overload for the division of a matrix expression by a scalar from the right, e.g. (beta * m1) / alpha. Here, beta * m1 is wrapped into a matrix_expression and then divided by alpha.
Definition: matrix.hpp:1419
vector_iterator()
Definition: vector.hpp:319
bool is_value_static() const
Definition: vector.hpp:64
handle_type const & handle() const
Definition: vector.hpp:347
Represents a vector consisting of zeros only.
Definition: forwards.h:193
vector_iterator(vector_base< SCALARTYPE > &vec, vcl_size_t index, vcl_size_t start=0, vcl_ptrdiff_t stride=1)
Constructor.
Definition: vector.hpp:330
self_type & operator=(const vector_expression< const LHS, const RHS, OP > &proxy)
Implementation of the operation v1 = v2 @ alpha, where @ denotes either multiplication or division...
Definition: vector.hpp:511
A tag class representing multiplication by a scalar.
Definition: forwards.h:74
VectorType const & const_at(vcl_size_t i) const
Definition: vector.hpp:1196
self_type & swap(self_type &other)
Swaps the entries of the two vectors.
Definition: vector.hpp:850
A STL-type const-iterator for vector elements. Elements can be accessed, but cannot be manipulated...
Definition: forwards.h:187
SizeType size_type
Definition: vector.hpp:371
std::size_t vcl_size_t
Definition: forwards.h:58
void resize(size_type new_size, viennacl::context ctx, bool preserve=true)
Definition: vector.hpp:1101
Definition: forwards.h:498
scalar< SCALARTYPE > value_type
Definition: vector.hpp:219
SCALARTYPE const & const_reference
Definition: vector.hpp:134
void memory_write(mem_handle &dst_buffer, vcl_size_t dst_offset, vcl_size_t bytes_to_write, const void *ptr, bool async=false)
Writes data from main RAM identified by 'ptr' to the buffer identified by 'dst_buffer'.
Definition: memory.hpp:220
self_type & operator+=(const self_type &vec)
Definition: vector.hpp:731
static const size_type alignment
Definition: vector.hpp:376
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:172
size_type size() const
Returns the length of the vector (cf. std::vector)
Definition: vector.hpp:859
ram_handle_type & ram_handle()
Returns the handle to a buffer in CPU RAM. NULL is returned if no such buffer has been allocated...
Definition: mem_handle.hpp:72
base_type::size_type size_type
Definition: vector.hpp:121
viennacl::context ctx_
Definition: vector.hpp:87
Worker class for decomposing expression templates.
Definition: op_executor.hpp:79
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
Definition: entry_proxy.hpp:178
vector_tuple(VectorType const &v0, VectorType const &v1, VectorType const &v2)
Definition: vector.hpp:1143
self_type & operator=(const self_type &vec)
Assignment operator. Other vector needs to be of the same size, or this vector is not yet initialized...
Definition: vector.hpp:482
vector(size_type vec_size)
An explicit constructor for the vector, allocating the given amount of memory (plus a padding specifi...
Definition: vector.hpp:1017
cpu_value_type operator()(size_type i) const
Definition: vector.hpp:70
Defines the worker class for decomposing an expression tree into small chunks, which can be processed...
bool operator!=(self_type const &other) const
Definition: vector.hpp:258
Implementations of vector operations.
vector_base(SCALARTYPE *ptr_to_mem, viennacl::memory_types mem_type, size_type vec_size, vcl_size_t start=0, difference_type stride=1)
Definition: vector.hpp:407
viennacl::context context() const
Definition: vector.hpp:58
void inner_prod_impl(vector_base< T > const &vec1, vector_base< T > const &vec2, scalar< T > &result)
Computes the inner product of two vectors - dispatcher interface.
Definition: vector_operations.hpp:351
zero_vector(size_type s, viennacl::context ctx=viennacl::context())
Definition: vector.hpp:112
Helper struct for checking whether a type represents a sign flip on a viennacl::scalar<> ...
Definition: forwards.h:377
vcl_size_t start_
Definition: vector.hpp:286
Represents a vector consisting of 1 at a given index and zeros otherwise.
Definition: forwards.h:196
vcl_size_t index() const
Definition: vector.hpp:66
vector_tuple(std::vector< VectorType const * > const &vecs)
Definition: vector.hpp:1177
unit_vector(size_type s, size_type ind, viennacl::context ctx=viennacl::context())
Definition: vector.hpp:97
vector_iterator(handle_type &elements, vcl_size_t index, vcl_size_t start=0, vcl_ptrdiff_t stride=1)
Definition: vector.hpp:320
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
Definition: size.hpp:216
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Definition: context.hpp:51
A tag class representing subtraction.
Definition: forwards.h:72
vector_base()
Default constructor in order to be compatible with various containers.
Definition: vector.hpp:380
self_type & operator=(const viennacl::vector_expression< const matrix_base< SCALARTYPE, F >, const vector_base< SCALARTYPE >, viennacl::op_prod > &proxy)
Operator overload for v1 = A * v2, where v1, v2 are vectors and A is a dense matrix.
Definition: vector.hpp:638
A proxy class for entries in a vector.
void avbv_v(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< T > const &vec3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:115
vcl_size_t offset() const
Offset of the current element index with respect to the beginning of the buffer.
Definition: vector.hpp:276
implicit_vector_base(size_type s, std::pair< SCALARTYPE, bool > v, viennacl::context ctx)
Definition: vector.hpp:52
bool has_index() const
Definition: vector.hpp:68
const_vector_iterator< SCALARTYPE, 1 > const_iterator
Definition: vector.hpp:373
Expression template class for representing a tree of expressions which ultimately result in a matrix...
Definition: forwards.h:283
vector_base(size_type vec_size, viennacl::context ctx=viennacl::context())
Creates a vector and allocates the necessary memory.
Definition: vector.hpp:396
implicit_vector_base(size_type s, vcl_size_t i, std::pair< SCALARTYPE, bool > v, viennacl::context ctx)
Definition: vector.hpp:51
cpu_value_type operator[](size_type i) const
Definition: vector.hpp:76
vector_iterator< SCALARTYPE, 1 > iterator
Definition: vector.hpp:374
const_vector_iterator(vector_base< SCALARTYPE > const &vec, vcl_size_t index, vcl_size_t start=0, vcl_ptrdiff_t stride=1)
Constructor.
Definition: vector.hpp:231
base_type::difference_type difference_type
Definition: vector.hpp:317
vector_tuple(VectorType const &v0, VectorType const &v1, VectorType const &v2, VectorType const &v3)
Definition: vector.hpp:1158
const_iterator end() const
Returns a const-iterator pointing to the end of the vector (STL like)
Definition: vector.hpp:843
entry_proxy< SCALARTYPE > operator()(size_type index)
Read-write access to a single element of the vector.
Definition: vector.hpp:689
vector(const base_type &v)
Definition: vector.hpp:1046
size_type size() const
Definition: vector.hpp:60
This file provides the forward declarations for the main types used within ViennaCL.
A tag class representing division.
Definition: forwards.h:80
void memory_read(mem_handle const &src_buffer, vcl_size_t src_offset, vcl_size_t bytes_to_read, void *ptr, bool async=false)
Reads data from a buffer back to main RAM.
Definition: memory.hpp:261
handle_type & handle()
Definition: vector.hpp:346
base_type::size_type size_type
Definition: vector.hpp:110
size_type start() const
Returns the offset within the buffer.
Definition: vector.hpp:867
base_type::handle_type handle_type
Definition: vector.hpp:316
vector_expression< const self_type, const SCALARTYPE, op_mult > operator-() const
Sign flip for the vector. Emulated to be equivalent to -1.0 * vector.
Definition: vector.hpp:815
VectorType & at(vcl_size_t i) const
Definition: vector.hpp:1195
self_type & fast_swap(self_type &other)
Swaps the handles of two vectors by swapping the OpenCL handles only, no data copy.
Definition: vector.hpp:1108
size_type size() const
Returns the size of the result vector.
Definition: vector.hpp:187
self_type & operator=(T const &other)
Definition: vector.hpp:1081
A proxy for scalar expressions (e.g. from inner vector products)
Definition: forwards.h:175
An expression template class that represents a binary operation that yields a vector.
Definition: forwards.h:181
SCALARTYPE cpu_value_type
Definition: vector.hpp:369
const_vector_iterator(handle_type const &elements, vcl_size_t index, vcl_size_t start=0, vcl_ptrdiff_t stride=1)
Constructor for vector-like treatment of arbitrary buffers.
Definition: vector.hpp:242
viennacl::enable_if< viennacl::is_scalar< S1 >::value, matrix_base< NumericT, F > & >::type operator/=(matrix_base< NumericT, F > &m1, S1 const &gpu_val)
Scales a matrix by a GPU scalar value.
Definition: matrix.hpp:1445
Definition: forwards.h:481
memory_types
Definition: forwards.h:476
viennacl::memory_types memory_domain() const
Definition: vector.hpp:890
self_type & operator/=(SCALARTYPE val)
Scales this vector by a CPU scalar value.
Definition: vector.hpp:787
void swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector.hpp:1691
Implementation of a OpenCL-like context, which serves as a unification of {OpenMP, CUDA, OpenCL} at the user API.
vector_expression(LHS &l, RHS &r)
Definition: vector.hpp:177
self_type operator+(difference_type diff) const
Definition: vector.hpp:344
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
Definition: context.hpp:39
memory_types get_active_handle_id() const
Returns an ID for the currently active memory buffer. Other memory buffers might contain old or no da...
Definition: mem_handle.hpp:91
void copy(vector< SCALARTYPE, ALIGNMENT_SRC > const &gpu_src_vec, vector< SCALARTYPE, ALIGNMENT_DEST > &gpu_dest_vec)
Transfer from a ViennaCL vector to another ViennaCL vector. Convenience wrapper for viennacl::linalg:...
Definition: vector.hpp:1643
rhs_reference_type rhs() const
Get right hand side operand.
Definition: vector.hpp:184
SCALARTYPE const_reference
Definition: vector.hpp:122
vcl_ptrdiff_t difference_type
Definition: vector.hpp:220
base_type::size_type size_type
Definition: vector.hpp:133
vector(SCALARTYPE *ptr_to_mem, viennacl::memory_types mem_type, size_type vec_size, size_type start=0, difference_type stride=1)
Definition: vector.hpp:1021
viennacl::enable_if< viennacl::is_any_scalar< S1 >::value, matrix_expression< const matrix_base< NumericT, F >, const S1, op_mult > >::type operator*(S1 const &value, matrix_base< NumericT, F > const &m1)
Operator overload for the expression alpha * m1, where alpha is a host scalar (float or double) and m...
Definition: matrix.hpp:1345
self_type & fast_swap(self_type &other)
Swaps the handles of two vectors by swapping the OpenCL handles only, no data copy.
Definition: vector.hpp:904
void clear()
Resets all entries to zero. Does not change the size of the vector.
Definition: vector.hpp:885
vector_tuple(std::vector< VectorType * > const &vecs)
Definition: vector.hpp:1183
vector(zero_vector< SCALARTYPE > const &v)
Creates the vector from the supplied zero vector.
Definition: vector.hpp:1066
self_type & operator-=(const self_type &vec)
Definition: vector.hpp:742
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:144
self_type & operator*=(SCALARTYPE val)
Scales a vector (or proxy) by a CPU scalar value.
Definition: vector.hpp:777
Definition: forwards.h:480
difference_type operator-(self_type const &other) const
Definition: vector.hpp:267
vector()
Default constructor in order to be compatible with various containers.
Definition: vector.hpp:1011
handle_type const & elements_
The index of the entry the iterator is currently pointing to.
Definition: vector.hpp:284
Tuple class holding pointers to multiple vectors. Mainly used as a temporary object returned from vie...
Definition: forwards.h:211
vector_expression< const self_type, const SCALARTYPE, op_div > operator/(SCALARTYPE value) const
Scales the vector by a CPU scalar 'alpha' and returns an expression template.
Definition: vector.hpp:808
vcl_size_t size() const
Definition: vector.hpp:1192
vector< SCALARTYPE, ALIGNMENT > & fast_swap(vector< SCALARTYPE, ALIGNMENT > &v1, vector< SCALARTYPE, ALIGNMENT > &v2)
Swaps the content of two vectors by swapping OpenCL handles only, NO data is copied.
Definition: vector.hpp:1702
A STL-type iterator for vector elements. Elements can be accessed and manipulated. VERY SLOW!!
Definition: forwards.h:184
result_of::size_type< T >::type start(T const &obj)
Definition: start.hpp:43
void switch_memory_context(viennacl::context new_ctx)
Definition: vector.hpp:1114
base_type::size_type size_type
Definition: vector.hpp:1006
void vector_swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector_operations.hpp:189
lhs_reference_type lhs() const
Get left hand side operand.
Definition: vector.hpp:181
void resize(size_type new_size, bool preserve=true)
Resizes the allocated memory for the vector. Pads the memory to be a multiple of 'ALIGNMENT'.
Definition: vector.hpp:1096
A tag class representing addition.
Definition: forwards.h:70
void copy(std::vector< SCALARTYPE > &cpu_vec, circulant_matrix< SCALARTYPE, ALIGNMENT > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
Definition: circulant_matrix.hpp:150
vector(unit_vector< SCALARTYPE > const &v)
Creates the vector from the supplied unit vector.
Definition: vector.hpp:1059
void resize(size_type new_size, bool preserve=true)
Resizes the allocated memory for the vector. Pads the memory to be a multiple of 'ALIGNMENT'.
Definition: vector.hpp:936
vector(size_type vec_size, viennacl::context ctx)
Definition: vector.hpp:1019
viennacl::backend::mem_handle handle_type
Definition: vector.hpp:221
void element_op(matrix_base< T, F > &A, matrix_expression< const matrix_base< T, F >, const matrix_base< T, F >, OP > const &proxy)
Implementation of the element-wise operation A = B .* C and A = B ./ C for matrices (using MATLAB syn...
Definition: matrix_operations.hpp:598
vector_tuple< ScalarT > tie(vector_base< ScalarT > const &v0, vector_base< ScalarT > const &v1)
Definition: vector.hpp:1205
vcl_size_t stride() const
Index increment in the underlying buffer when incrementing the iterator to the next element...
Definition: vector.hpp:279
vector(scalar_vector< SCALARTYPE > const &v)
Creates the vector from the supplied scalar vector.
Definition: vector.hpp:1073
A vector class representing a linear memory sequence on the GPU. Inspired by boost::numeric::ublas::v...
Definition: forwards.h:208
vector_base(viennacl::backend::mem_handle &h, size_type vec_size, size_type vec_start, difference_type vec_stride)
An explicit constructor for wrapping an existing vector into a vector_range or vector_slice.
Definition: vector.hpp:391
self_type operator+(difference_type diff) const
Definition: vector.hpp:272
vector(vector_expression< const LHS, const RHS, OP > const &proxy)
Definition: vector.hpp:1044
SCALARTYPE const_reference
Definition: vector.hpp:111
handle_type & handle()
Returns the memory handle.
Definition: vector.hpp:881
viennacl::vector< NumericT > operator-(const vector_base< NumericT > &v1, const vector_expression< const matrix_base< NumericT, F >, const vector_base< NumericT >, op_prod > &proxy)
Implementation of the operation 'result = v1 - A * v2', where A is a matrix.
Definition: matrix_operations.hpp:858
void avbv(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< T > const &vec3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:78
void resize(size_type new_size, viennacl::context ctx, bool preserve=true)
Resizes the allocated memory for the vector. Convenience function for setting an OpenCL context in ca...
Definition: vector.hpp:947
SCALARTYPE const & const_reference
Definition: vector.hpp:55
Definition: vector.hpp:171
base_type::value_type operator*(void)
Definition: vector.hpp:336
entry_proxy< SCALARTYPE > operator[](size_type index)
Read-write access to a single element of the vector.
Definition: vector.hpp:699
iterator begin()
Returns an iterator pointing to the beginning of the vector (STL like)
Definition: vector.hpp:825
void set_handle(viennacl::backend::mem_handle const &h)
Definition: vector.hpp:897
DistanceType difference_type
Definition: vector.hpp:372
vcl_ptrdiff_t stride_
Definition: vector.hpp:287
void memory_copy(mem_handle const &src_buffer, mem_handle &dst_buffer, vcl_size_t src_offset, vcl_size_t dst_offset, vcl_size_t bytes_to_copy)
Copies 'bytes_to_copy' bytes from address 'src_buffer + src_offset' to memory starting at address 'ds...
Definition: memory.hpp:140
A tag class representing matrix-vector products and element-wise multiplications. ...
Definition: forwards.h:76
vcl_size_t raw_size() const
Returns the number of bytes of the currently active buffer.
Definition: mem_handle.hpp:203
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
Definition: context.hpp:41
const_entry_proxy< SCALARTYPE > operator[](size_type index) const
Read access to a single element of the vector.
Definition: vector.hpp:720
vcl_size_t size_type
Definition: vector.hpp:50
T::ERROR_CANNOT_DEDUCE_CPU_SCALAR_TYPE_FOR_T type
Definition: result_of.hpp:276
const_iterator begin() const
Returns a const-iterator pointing to the beginning of the vector (STL like)
Definition: vector.hpp:837
std::pair< bool, vcl_size_t > index_
Definition: vector.hpp:85
difference_type operator-(self_type const &other) const
Definition: vector.hpp:343
base_type::size_type size_type
Definition: vector.hpp:96
viennacl::enable_if< viennacl::is_scalar< S1 >::value, matrix_base< NumericT, F > & >::type operator*=(matrix_base< NumericT, F > &m1, S1 const &gpu_val)
Scales a matrix by a GPU scalar value.
Definition: matrix.hpp:1399
const_entry_proxy< SCALARTYPE > operator()(size_type index) const
Read access to a single element of the vector.
Definition: vector.hpp:710
Definition: forwards.h:479
scalar_vector(size_type s, SCALARTYPE val, viennacl::context ctx=viennacl::context())
Definition: vector.hpp:136
void swap(mem_handle &other)
Implements a fast swapping method. No data is copied, only the handles are exchanged.
Definition: mem_handle.hpp:179
void av(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: vector_operations.hpp:49
SCALARTYPE cpu_value_type
Definition: vector.hpp:56
iterator end()
Returns an iterator pointing to the end of the vector (STL like)
Definition: vector.hpp:831
base_type::difference_type difference_type
Definition: vector.hpp:1007
std::ptrdiff_t vcl_ptrdiff_t
Definition: forwards.h:59
vector_tuple(VectorType &v0, VectorType &v1, VectorType &v2)
Definition: vector.hpp:1149
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:62
A tag class representing transposed matrices.
Definition: forwards.h:165
self_type & operator=(const vector_expression< const matrix_expression< const matrix_base< SCALARTYPE, F >, const matrix_base< SCALARTYPE, F >, op_trans >, const vector_base< SCALARTYPE >, op_prod > &proxy)
Operator overload for v1 = trans(A) * v2, where v1, v2 are vectors and A is a dense matrix...
Definition: vector.hpp:663
size_type size_
Definition: vector.hpp:84
vcl_size_t index_
Definition: vector.hpp:285
self_type operator++(void)
Definition: vector.hpp:254
void prod_impl(const matrix_base< NumericT, F > &mat, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
Definition: matrix_operations.hpp:350
void memory_create(mem_handle &handle, vcl_size_t size_in_bytes, viennacl::context const &ctx, const void *host_ptr=NULL)
Creates an array of the specified size. If the second argument is provided, the buffer is initialized...
Definition: memory.hpp:87
void vector_assign(vector_base< T > &vec1, const T &alpha, bool up_to_internal_size=false)
Assign a constant value to a vector (-range/-slice)
Definition: vector_operations.hpp:158
bool empty() const
Returns true is the size is zero.
Definition: vector.hpp:875
Common base class for representing vectors where the entries are not all stored explicitly.
Definition: forwards.h:190
handle_type const & handle() const
Definition: vector.hpp:280
value_type operator*(void) const
Dereferences the iterator and returns the value of the element. For convenience only, performance is poor due to OpenCL overhead!
Definition: vector.hpp:248
void switch_active_handle_id(memory_types new_id)
Switches the currently active handle. If no support for that backend is provided, an exception is thr...
Definition: mem_handle.hpp:94
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
self_type operator++(int)
Definition: vector.hpp:255
const handle_type & handle() const
Returns the memory handle.
Definition: vector.hpp:878
one_vector(size_type s, viennacl::context ctx=viennacl::context())
Definition: vector.hpp:123
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
Definition: forwards.h:178
vcl_size_t size_type
Extracts the vector type from the two operands.
Definition: vector.hpp:175
bool op_aliasing(vector_base< T > const &, B const &)
Definition: op_executor.hpp:35
vector_tuple(VectorType const &v0, VectorType const &v1)
Definition: vector.hpp:1130
Implementation of the ViennaCL scalar class.
void fast_copy(const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_begin, const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_end, CPU_ITERATOR cpu_begin)
STL-like transfer of a GPU vector to the CPU. The cpu type is assumed to reside in a linear piece of ...
Definition: vector.hpp:1284
void async_copy(const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_begin, const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_end, CPU_ITERATOR cpu_begin)
Asynchronous version of fast_copy(), copying data from device to host. The host iterator cpu_begin ne...
Definition: vector.hpp:1334
viennacl::vector< NumericT > operator+(const vector_base< NumericT > &v1, const vector_expression< const matrix_base< NumericT, F >, const vector_base< NumericT >, op_prod > &proxy)
Implementation of the operation 'result = v1 + A * v2', where A is a matrix.
Definition: matrix_operations.hpp:840
A collection of compile time type deductions.
bool operator==(self_type const &other) const
Definition: vector.hpp:257
vector_tuple(VectorType &v0, VectorType &v1)
Definition: vector.hpp:1135
Represents a vector consisting of scalars 's' only, i.e. v[i] = s for all i. To be used as an initial...
Definition: forwards.h:202
size_type internal_size() const
Returns the internal length of the vector, which is given by size() plus the extra memory due to padd...
Definition: vector.hpp:863
cpu_value_type value() const
Definition: vector.hpp:62
vector_expression< const self_type, const SCALARTYPE, op_mult > operator*(SCALARTYPE value) const
Scales the vector by a CPU scalar 'alpha' and returns an expression template.
Definition: vector.hpp:799
Main interface routines for memory management.
size_type stride() const
Returns the stride within the buffer (in multiples of sizeof(SCALARTYPE))
Definition: vector.hpp:871
vector_tuple(VectorType &v0, VectorType &v1, VectorType &v2, VectorType &v3)
Definition: vector.hpp:1165
std::pair< SCALARTYPE, bool > value_
Definition: vector.hpp:86
void switch_memory_context(viennacl::context new_ctx)
Definition: vector.hpp:921
scalar< SCALARTYPE > value_type
Definition: vector.hpp:368
void pad()
Pads vectors with alignment > 1 with trailing zeros if the internal size is larger than the visible s...
Definition: vector.hpp:912
vector(const self_type &v)
Definition: vector.hpp:1052
viennacl::backend::mem_handle handle_type
Definition: vector.hpp:370
vector_base(vector_expression< const LHS, const RHS, OP > const &proxy)
Creates the vector from the supplied random vector.
Definition: vector.hpp:463
vcl_size_t const_size() const
Definition: vector.hpp:1193