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);
759 *
this, val, 1,
false,
false);
769 *
this, val, 1,
true,
false);
805 return iterator(*
this, 0, start_, stride_);
853 bool empty()
const {
return size_ == 0; }
884 assert(this->size_ == other.size_ &&
bool(
"Vector size mismatch"));
885 this->elements_.
swap(other.elements_);
901 viennacl::backend::switch_memory_context<SCALARTYPE>(elements_, new_ctx);
927 resize_impl(new_size, ctx, preserve);
934 assert(new_size > 0 &&
bool(
"Positive size required when resizing vector!"));
936 if (new_size != size_)
938 vcl_size_t new_internal_size = viennacl::tools::align_to_multiple<vcl_size_t>(new_size,
alignment);
940 std::vector<SCALARTYPE> temp(size_);
941 if (preserve && size_ > 0)
943 temp.resize(new_size);
944 temp.resize(new_internal_size);
953 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_,
alignment);
977 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
978 class vector :
public vector_base<SCALARTYPE>
980 typedef vector<SCALARTYPE, ALIGNMENT> self_type;
981 typedef vector_base<SCALARTYPE> base_type;
1002 #ifdef VIENNACL_WITH_OPENCL
1021 template <
typename LHS,
typename RHS,
typename OP>
1027 base_type::operator=(v);
1033 base_type::operator=(v);
1040 this->
operator()(v.
index()) = SCALARTYPE(1);;
1058 template <
typename T>
1065 using base_type::operator+=;
1066 using base_type::operator-=;
1100 template <
typename ScalarT>
1103 typedef vector_base<ScalarT> VectorType;
1110 const_vectors_[0] = &v0;
1111 const_vectors_[1] = &v1;
1115 const_vectors_[0] = &v0; non_const_vectors_[0] = &v0;
1116 const_vectors_[1] = &v1; non_const_vectors_[1] = &v1;
1123 const_vectors_[0] = &v0;
1124 const_vectors_[1] = &v1;
1125 const_vectors_[2] = &v2;
1129 const_vectors_[0] = &v0; non_const_vectors_[0] = &v0;
1130 const_vectors_[1] = &v1; non_const_vectors_[1] = &v1;
1131 const_vectors_[2] = &v2; non_const_vectors_[2] = &v2;
1138 const_vectors_[0] = &v0;
1139 const_vectors_[1] = &v1;
1140 const_vectors_[2] = &v2;
1141 const_vectors_[3] = &v3;
1145 const_vectors_[0] = &v0; non_const_vectors_[0] = &v0;
1146 const_vectors_[1] = &v1; non_const_vectors_[1] = &v1;
1147 const_vectors_[2] = &v2; non_const_vectors_[2] = &v2;
1148 const_vectors_[3] = &v3; non_const_vectors_[3] = &v3;
1155 vector_tuple(std::vector<VectorType const *>
const & vecs) : const_vectors_(vecs.
size()), non_const_vectors_()
1158 const_vectors_[i] = vecs[i];
1161 vector_tuple(std::vector<VectorType *>
const & vecs) : const_vectors_(vecs.
size()), non_const_vectors_(vecs.
size())
1165 const_vectors_[i] = vecs[i];
1166 non_const_vectors_[i] = vecs[i];
1177 std::vector<VectorType const *> const_vectors_;
1178 std::vector<VectorType *> non_const_vectors_;
1182 template <
typename ScalarT>
1185 template <
typename ScalarT>
1189 template <
typename ScalarT>
1192 template <
typename ScalarT>
1196 template <
typename ScalarT>
1202 template <
typename ScalarT>
1209 template <
typename ScalarT>
1217 std::vector<VectorPointerType> vec(5);
1226 template <
typename ScalarT>
1234 std::vector<VectorPointerType> vec(5);
1261 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1264 CPU_ITERATOR cpu_begin )
1266 if (gpu_begin != gpu_end)
1268 if (gpu_begin.stride() == 1)
1271 sizeof(SCALARTYPE)*gpu_begin.offset(),
1272 sizeof(SCALARTYPE)*gpu_begin.stride() * (gpu_end - gpu_begin),
1278 std::vector<SCALARTYPE> temp_buffer(gpu_begin.stride() * gpu_size);
1279 viennacl::backend::memory_read(gpu_begin.handle(),
sizeof(SCALARTYPE)*gpu_begin.offset(),
sizeof(SCALARTYPE)*temp_buffer.size(), &(temp_buffer[0]));
1283 (&(*cpu_begin))[i] = temp_buffer[i * gpu_begin.stride()];
1294 template <
typename NumericT,
typename CPUVECTOR>
1311 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1314 CPU_ITERATOR cpu_begin )
1316 if (gpu_begin != gpu_end)
1318 if (gpu_begin.stride() == 1)
1321 sizeof(SCALARTYPE)*gpu_begin.offset(),
1322 sizeof(SCALARTYPE)*gpu_begin.stride() * (gpu_end - gpu_begin),
1327 fast_copy(gpu_begin, gpu_end, cpu_begin);
1336 template <
typename NumericT,
typename CPUVECTOR>
1349 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1352 CPU_ITERATOR cpu_begin )
1354 assert(gpu_end - gpu_begin >= 0 &&
bool(
"Iterators incompatible"));
1355 if (gpu_end - gpu_begin != 0)
1357 std::vector<SCALARTYPE> temp_buffer(gpu_end - gpu_begin);
1358 fast_copy(gpu_begin, gpu_end, temp_buffer.begin());
1361 std::copy(temp_buffer.begin(), temp_buffer.end(), cpu_begin);
1371 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1374 CPU_ITERATOR cpu_begin )
1387 template <
typename NumericT,
typename CPUVECTOR>
1395 #ifdef VIENNACL_WITH_EIGEN
1396 template <
unsigned int ALIGNMENT>
1397 void copy(vector<float, ALIGNMENT>
const & gpu_vec,
1398 Eigen::VectorXf & eigen_vec)
1403 template <
unsigned int ALIGNMENT>
1404 void copy(vector<double, ALIGNMENT> & gpu_vec,
1405 Eigen::VectorXd & eigen_vec)
1427 template <
typename CPU_ITERATOR,
typename SCALARTYPE,
unsigned int ALIGNMENT>
1429 CPU_ITERATOR
const & cpu_end,
1432 if (cpu_end - cpu_begin > 0)
1434 if (gpu_begin.
stride() == 1)
1437 sizeof(SCALARTYPE)*gpu_begin.
offset(),
1438 sizeof(SCALARTYPE)*gpu_begin.
stride() * (cpu_end - cpu_begin), &(*cpu_begin));
1443 std::vector<SCALARTYPE> temp_buffer(gpu_begin.
stride() * cpu_size);
1448 temp_buffer[i * gpu_begin.
stride()] = (&(*cpu_begin))[i];
1461 template <
typename CPUVECTOR,
typename NumericT>
1477 template <
typename CPU_ITERATOR,
typename SCALARTYPE,
unsigned int ALIGNMENT>
1479 CPU_ITERATOR
const & cpu_end,
1482 if (cpu_end - cpu_begin > 0)
1484 if (gpu_begin.
stride() == 1)
1487 sizeof(SCALARTYPE)*gpu_begin.
offset(),
1488 sizeof(SCALARTYPE)*gpu_begin.
stride() * (cpu_end - cpu_begin), &(*cpu_begin),
1492 fast_copy(cpu_begin, cpu_end, gpu_begin);
1502 template <
typename CPUVECTOR,
typename NumericT>
1515 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename CPU_ITERATOR>
1516 void copy(CPU_ITERATOR
const & cpu_begin,
1517 CPU_ITERATOR
const & cpu_end,
1520 assert(cpu_end - cpu_begin > 0 &&
bool(
"Iterators incompatible"));
1521 if (cpu_begin != cpu_end)
1524 std::vector<SCALARTYPE> temp_buffer(cpu_end - cpu_begin);
1525 std::copy(cpu_begin, cpu_end, temp_buffer.begin());
1537 template <
typename CPUVECTOR,
typename T>
1544 #ifdef VIENNACL_WITH_EIGEN
1545 template <
unsigned int ALIGNMENT>
1546 void copy(Eigen::VectorXf
const & eigen_vec,
1547 vector<float, ALIGNMENT> & gpu_vec)
1549 std::vector<float> entries(eigen_vec.size());
1550 for (
vcl_size_t i = 0; i<entries.size(); ++i)
1551 entries[i] = eigen_vec(i);
1555 template <
unsigned int ALIGNMENT>
1556 void copy(Eigen::VectorXd
const & eigen_vec,
1557 vector<double, ALIGNMENT> & gpu_vec)
1559 std::vector<double> entries(eigen_vec.size());
1560 for (
vcl_size_t i = 0; i<entries.size(); ++i)
1561 entries[i] = eigen_vec(i);
1577 template <
typename SCALARTYPE,
unsigned int ALIGNMENT_SRC,
unsigned int ALIGNMENT_DEST>
1582 assert(gpu_src_end - gpu_src_begin >= 0);
1583 assert(gpu_src_begin.stride() == 1 && bool(
"ViennaCL ERROR: copy() for GPU->GPU not implemented for slices! Use operator= instead for the moment."));
1585 if (gpu_src_begin.stride() == 1 && gpu_dest_begin.
stride() == 1)
1587 if (gpu_src_begin != gpu_src_end)
1589 sizeof(SCALARTYPE) * gpu_src_begin.offset(),
1590 sizeof(SCALARTYPE) * gpu_dest_begin.
offset(),
1591 sizeof(SCALARTYPE) * (gpu_src_end.offset() - gpu_src_begin.offset()));
1595 assert(
false &&
bool(
"not implemented yet"));
1605 template <
typename SCALARTYPE,
unsigned int ALIGNMENT_SRC,
unsigned int ALIGNMENT_DEST>
1620 template <
typename SCALARTYPE,
unsigned int ALIGNMENT_SRC,
unsigned int ALIGNMENT_DEST>
1624 viennacl::copy(gpu_src_vec.begin(), gpu_src_vec.end(), gpu_dest_vec.begin());
1637 template <
typename T>
1638 std::ostream & operator<<(std::ostream & os, vector_base<T>
const & val)
1640 std::vector<T> tmp(val.size());
1642 os <<
"[" << val.size() <<
"](";
1643 for (
typename std::vector<T>::size_type i=0; i<val.size(); ++i)
1653 template <
typename LHS,
typename RHS,
typename OP>
1654 std::ostream & operator<<(std::ostream & os, vector_expression<LHS, RHS, OP>
const & proxy)
1668 template <
typename T>
1679 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
1683 return v1.fast_swap(v2);
1703 template <
typename T,
typename S1>
1723 template <
typename T,
typename S1>
1746 template <
typename LHS1,
typename RHS1,
typename OP1,
1747 typename LHS2,
typename RHS2,
typename OP2>
1748 vector_expression< const vector_expression< LHS1, RHS1, OP1>,
1749 const vector_expression< LHS2, RHS2, OP2>,
1754 assert(proxy1.size() == proxy2.size() && bool(
"Incompatible vector sizes!"));
1765 template <
typename LHS,
typename RHS,
typename OP,
typename T>
1766 vector_expression< const vector_expression<LHS, RHS, OP>,
1767 const vector_base<T>,
1772 assert(proxy.size() == vec.size() && bool(
"Incompatible vector sizes!"));
1783 template <
typename T,
typename LHS,
typename RHS,
typename OP>
1784 vector_expression< const vector_base<T>,
1785 const vector_expression<LHS, RHS, OP>,
1790 assert(proxy.size() == vec.size() && bool(
"Incompatible vector sizes!"));
1798 template <
typename T>
1799 vector_expression< const vector_base<T>,
const vector_base<T>, op_add>
1816 template <
typename LHS1,
typename RHS1,
typename OP1,
1817 typename LHS2,
typename RHS2,
typename OP2>
1818 vector_expression< const vector_expression< LHS1, RHS1, OP1>,
1819 const vector_expression< LHS2, RHS2, OP2>,
1824 assert(proxy1.size() == proxy2.size() && bool(
"Incompatible vector sizes!"));
1836 template <
typename LHS,
typename RHS,
typename OP,
typename T>
1837 vector_expression< const vector_expression<LHS, RHS, OP>,
1838 const vector_base<T>,
1843 assert(proxy.size() == vec.size() && bool(
"Incompatible vector sizes!"));
1854 template <
typename T,
typename LHS,
typename RHS,
typename OP>
1855 vector_expression< const vector_base<T>,
1856 const vector_expression<LHS, RHS, OP>,
1861 assert(proxy.size() == vec.size() && bool(
"Incompatible vector sizes!"));
1869 template <
typename T>
1870 vector_expression< const vector_base<T>,
const vector_base<T>, op_sub>
1887 template <
typename S1,
typename T>
1889 vector_expression< const vector_base<T>,
const S1, op_mult> >::type
1900 template <
typename T>
1901 vector_expression< const vector_base<T>,
const T, op_mult>
1912 template <
typename T>
1913 vector_expression< const vector_base<T>,
const T, op_mult>
1924 template <
typename T>
1925 vector_expression< const vector_base<T>,
const T, op_mult>
1936 template <
typename T>
1937 vector_expression< const vector_base<T>,
const T, op_mult>
1951 template <
typename LHS,
typename RHS,
typename OP,
typename T>
1952 vector_expression< const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
1960 template <
typename T,
typename S1>
1962 vector_expression< const vector_base<T>,
const S1, op_mult> >::type
1968 template <
typename T>
1969 vector_expression< const vector_base<T>,
const T, op_mult>
1980 template <
typename LHS,
typename RHS,
typename OP,
typename S1>
1994 template <
typename S1,
typename LHS,
typename RHS,
typename OP>
2012 template <
typename S1,
typename LHS,
typename RHS,
typename OP>
2024 template <
typename T,
typename S1>
2026 vector_expression< const vector_base<T>,
const S1, op_div> >::type
2045 template <
typename T>
2046 struct op_executor<vector_base<T>, op_assign, vector_base<T> >
2048 static void apply(vector_base<T> & lhs, vector_base<T>
const & rhs)
2055 template <
typename T>
2056 struct op_executor<vector_base<T>, op_assign, vector_expression<const vector_base<T>, const vector_tuple<T>, op_inner_prod> >
2058 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_tuple<T>, op_inner_prod>
const & rhs)
2065 template <
typename T>
2066 struct op_executor<vector_base<T>, op_inplace_add, vector_base<T> >
2068 static void apply(vector_base<T> & lhs, vector_base<T>
const & rhs)
2070 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, rhs, T(1), 1,
false,
false);
2075 template <
typename T>
2076 struct op_executor<vector_base<T>, op_inplace_sub, vector_base<T> >
2078 static void apply(vector_base<T> & lhs, vector_base<T>
const & rhs)
2080 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, rhs, T(1), 1,
false,
true);
2088 template <
typename T,
typename ScalarType>
2089 struct op_executor<vector_base<T>, op_assign, vector_expression<const vector_base<T>, const ScalarType, op_mult> >
2092 template <
typename LHS,
typename RHS,
typename OP>
2093 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
const & proxy)
2095 T alpha = proxy.rhs();
2099 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar<T>, op_mult>
const & proxy)
2104 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const T, op_mult>
const & proxy)
2111 template <
typename T,
typename ScalarType>
2112 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_base<T>, const ScalarType, op_mult> >
2115 template <
typename LHS,
typename RHS,
typename OP>
2116 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
const & proxy)
2118 T alpha = proxy.rhs();
2119 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), alpha, 1,
false,
false);
2122 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar<T>, op_mult>
const & proxy)
2124 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
false);
2127 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const T, op_mult>
const & proxy)
2129 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
false);
2134 template <
typename T,
typename ScalarType>
2135 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vector_base<T>, const ScalarType, op_mult> >
2138 template <
typename LHS,
typename RHS,
typename OP>
2139 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
const & proxy)
2141 T alpha = proxy.rhs();
2142 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), alpha, 1,
false,
true);
2145 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar<T>, op_mult>
const & proxy)
2147 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
true);
2150 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const T, op_mult>
const & proxy)
2152 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
true);
2160 template <
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2161 struct op_executor<vector_base<T>, op_assign, vector_expression<const vector_expression<const LHS, const RHS, OP>, const ScalarType, op_mult> >
2163 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_mult>
const & proxy)
2165 vector<T> temp(proxy.lhs());
2166 lhs = temp * proxy.rhs();
2171 template <
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2172 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_expression<const LHS, const RHS, OP>, const ScalarType, op_mult> >
2174 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_mult>
const & proxy)
2176 vector<T> temp(proxy.lhs());
2177 lhs += temp * proxy.rhs();
2182 template <
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2183 struct op_executor<vector_base<T>, op_inplace_sub, 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();
2196 template <
typename T,
typename ScalarType>
2197 struct op_executor<vector_base<T>, op_assign, vector_expression<const vector_base<T>, const ScalarType, op_div> >
2199 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const ScalarType, op_div>
const & proxy)
2206 template <
typename T,
typename ScalarType>
2207 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_base<T>, const ScalarType, op_div> >
2209 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const ScalarType, op_div>
const & proxy)
2211 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
true,
false);
2216 template <
typename T,
typename ScalarType>
2217 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vector_base<T>, const ScalarType, op_div> >
2219 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const ScalarType, op_div>
const & proxy)
2221 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
true,
true);
2229 template <
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2230 struct op_executor<vector_base<T>, op_assign, vector_expression<const vector_expression<const LHS, const RHS, OP>, const ScalarType, op_div> >
2232 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_div>
const & proxy)
2234 vector<T> temp(proxy.lhs());
2235 lhs = temp / proxy.rhs();
2240 template <
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2241 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_expression<const LHS, const RHS, OP>, const ScalarType, op_div> >
2243 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_div>
const & proxy)
2245 vector<T> temp(proxy.lhs());
2246 lhs += temp / proxy.rhs();
2251 template <
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2252 struct op_executor<vector_base<T>, op_inplace_sub, 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();
2264 template <
typename T,
typename LHS,
typename RHS>
2265 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const RHS, op_add> >
2268 template <
typename LHS1,
typename RHS1>
2269 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_add>
const & proxy)
2271 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2272 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2274 if (op_aliasing_lhs || op_aliasing_rhs)
2276 vector_base<T> temp(proxy.lhs());
2277 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2282 op_executor<vector_base<T>, op_assign, LHS>::apply(lhs, proxy.lhs());
2283 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2288 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_add>
const & proxy)
2291 proxy.lhs(), T(1), 1,
false,
false,
2292 proxy.rhs(), T(1), 1,
false,
false);
2296 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_mult>,
2297 const vector_base<T>,
2298 op_add>
const & proxy)
2301 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2302 proxy.rhs(), T(1), 1,
false,
false);
2306 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_div>,
2307 const vector_base<T>,
2308 op_add>
const & proxy)
2311 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2312 proxy.rhs(), T(1), 1,
false,
false);
2316 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2317 const vector_expression<
const vector_base<T>,
const T, op_mult>,
2318 op_add>
const & proxy)
2321 proxy.lhs(), T(1), 1,
false,
false,
2322 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2326 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2327 const vector_expression<
const vector_base<T>,
const T, op_div>,
2328 op_add>
const & proxy)
2331 proxy.lhs(), T(1), 1,
false,
false,
2332 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2336 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_mult>,
2337 const vector_expression<
const vector_base<T>,
const T, op_mult>,
2338 op_add>
const & proxy)
2341 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2342 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2346 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_mult>,
2347 const vector_expression<
const vector_base<T>,
const T, op_div>,
2348 op_add>
const & proxy)
2351 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2352 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2356 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_div>,
2357 const vector_expression<
const vector_base<T>,
const T, op_mult>,
2358 op_add>
const & proxy)
2361 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2362 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2366 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_div>,
2367 const vector_expression<
const vector_base<T>,
const T, op_div>,
2368 op_add>
const & proxy)
2371 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2372 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2378 template <
typename T,
typename LHS,
typename RHS>
2379 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_add> >
2382 template <
typename LHS1,
typename RHS1>
2383 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_add>
const & proxy)
2385 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2386 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2388 if (op_aliasing_lhs || op_aliasing_rhs)
2390 vector_base<T> temp(proxy.lhs());
2391 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2396 op_executor<vector_base<T>, op_inplace_add, LHS>::apply(lhs, proxy.lhs());
2397 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2402 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_add>
const & proxy)
2405 proxy.lhs(), T(1), 1,
false,
false,
2406 proxy.rhs(), T(1), 1,
false,
false);
2410 template <
typename ScalarType>
2411 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2412 const vector_base<T>,
2413 op_add>
const & proxy)
2416 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2417 proxy.rhs(), T(1), 1,
false,
false);
2421 template <
typename ScalarType>
2422 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2423 const vector_base<T>,
2424 op_add>
const & proxy)
2427 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
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_base<T>,
2434 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2435 op_add>
const & proxy)
2438 proxy.lhs(), T(1), 1,
false,
false,
2439 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2443 template <
typename ScalarType>
2444 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2445 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2446 op_add>
const & proxy)
2449 proxy.lhs(), T(1), 1,
false,
false,
2450 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2454 template <
typename ScalarType1,
typename ScalarType2>
2455 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2456 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2457 op_add>
const & proxy)
2460 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2461 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2465 template <
typename ScalarType1,
typename ScalarType2>
2466 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2467 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2468 op_add>
const & proxy)
2471 proxy.lhs().lhs(), proxy.lhs().rhs(), 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_div>,
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,
true,
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_div>,
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,
true,
false,
2494 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2501 template <
typename T,
typename LHS,
typename RHS>
2502 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_add> >
2505 template <
typename LHS1,
typename RHS1>
2506 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_add>
const & proxy)
2508 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2509 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2511 if (op_aliasing_lhs || op_aliasing_rhs)
2513 vector_base<T> temp(proxy.lhs());
2514 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2519 op_executor<vector_base<T>, op_inplace_sub, LHS>::apply(lhs, proxy.lhs());
2520 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2525 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_add>
const & proxy)
2528 proxy.lhs(), T(1), 1,
false,
true,
2529 proxy.rhs(), T(1), 1,
false,
true);
2533 template <
typename ScalarType>
2534 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2535 const vector_base<T>,
2536 op_add>
const & proxy)
2539 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2540 proxy.rhs(), T(1), 1,
false,
true);
2544 template <
typename ScalarType>
2545 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2546 const vector_base<T>,
2547 op_add>
const & proxy)
2550 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
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_base<T>,
2557 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2558 op_add>
const & proxy)
2561 proxy.lhs(), T(1), 1,
false,
true,
2562 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2566 template <
typename ScalarType>
2567 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2568 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2569 op_add>
const & proxy)
2572 proxy.lhs(), T(1), 1,
false,
true,
2573 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2577 template <
typename ScalarType1,
typename ScalarType2>
2578 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2579 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2580 op_add>
const & proxy)
2583 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2584 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2588 template <
typename ScalarType1,
typename ScalarType2>
2589 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2590 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2591 op_add>
const & proxy)
2594 proxy.lhs().lhs(), proxy.lhs().rhs(), 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_div>,
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,
true,
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_div>,
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,
true,
true,
2617 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2628 template <
typename T,
typename LHS,
typename RHS>
2629 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const RHS, op_sub> >
2632 template <
typename LHS1,
typename RHS1>
2633 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2635 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2636 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2638 if (op_aliasing_lhs || op_aliasing_rhs)
2640 vector_base<T> temp(proxy.lhs());
2641 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2646 op_executor<vector_base<T>, op_assign, LHS>::apply(lhs, proxy.lhs());
2647 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2652 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_sub>
const & proxy)
2655 proxy.lhs(), T(1), 1,
false,
false,
2656 proxy.rhs(), T(1), 1,
false,
true);
2660 template <
typename ScalarType>
2661 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2662 const vector_base<T>,
2663 op_sub>
const & proxy)
2666 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2667 proxy.rhs(), T(1), 1,
false,
true);
2671 template <
typename ScalarType>
2672 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2673 const vector_base<T>,
2674 op_sub>
const & proxy)
2677 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
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_base<T>,
2684 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2685 op_sub>
const & proxy)
2688 proxy.lhs(), T(1), 1,
false,
false,
2689 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2693 template <
typename ScalarType>
2694 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2695 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2696 op_sub>
const & proxy)
2699 proxy.lhs(), T(1), 1,
false,
false,
2700 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2704 template <
typename ScalarType1,
typename ScalarType2>
2705 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2706 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2707 op_sub>
const & proxy)
2710 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2711 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2715 template <
typename ScalarType1,
typename ScalarType2>
2716 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2717 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2718 op_sub>
const & proxy)
2721 proxy.lhs().lhs(), proxy.lhs().rhs(), 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_div>,
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,
true,
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_div>,
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,
true,
false,
2744 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2750 template <
typename T,
typename LHS,
typename RHS>
2751 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_sub> >
2754 template <
typename LHS1,
typename RHS1>
2755 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2757 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2758 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2760 if (op_aliasing_lhs || op_aliasing_rhs)
2762 vector_base<T> temp(proxy.lhs());
2763 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2768 op_executor<vector_base<T>, op_inplace_add, LHS>::apply(lhs, proxy.lhs());
2769 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2774 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_sub>
const & proxy)
2777 proxy.lhs(), T(1), 1,
false,
false,
2778 proxy.rhs(), T(1), 1,
false,
true);
2782 template <
typename ScalarType>
2783 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2784 const vector_base<T>,
2785 op_sub>
const & proxy)
2788 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2789 proxy.rhs(), T(1), 1,
false,
true);
2793 template <
typename ScalarType>
2794 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2795 const vector_base<T>,
2796 op_sub>
const & proxy)
2799 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
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_base<T>,
2806 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2807 op_sub>
const & proxy)
2810 proxy.lhs(), T(1), 1,
false,
false,
2811 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2815 template <
typename ScalarType>
2816 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2817 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2818 op_sub>
const & proxy)
2821 proxy.lhs(), T(1), 1,
false,
false,
2822 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2826 template <
typename ScalarType1,
typename ScalarType2>
2827 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2828 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2829 op_sub>
const & proxy)
2832 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2833 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2837 template <
typename ScalarType1,
typename ScalarType2>
2838 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2839 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2840 op_sub>
const & proxy)
2843 proxy.lhs().lhs(), proxy.lhs().rhs(), 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_div>,
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,
true,
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_div>,
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,
true,
false,
2866 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2873 template <
typename T,
typename LHS,
typename RHS>
2874 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_sub> >
2877 template <
typename LHS1,
typename RHS1>
2878 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2880 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2881 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2883 if (op_aliasing_lhs || op_aliasing_rhs)
2885 vector_base<T> temp(proxy.lhs());
2886 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2891 op_executor<vector_base<T>, op_inplace_sub, LHS>::apply(lhs, proxy.lhs());
2892 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2897 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_sub>
const & proxy)
2900 proxy.lhs(), T(1), 1,
false,
true,
2901 proxy.rhs(), T(1), 1,
false,
false);
2905 template <
typename ScalarType>
2906 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2907 const vector_base<T>,
2908 op_sub>
const & proxy)
2911 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2912 proxy.rhs(), T(1), 1,
false,
false);
2916 template <
typename ScalarType>
2917 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2918 const vector_base<T>,
2919 op_sub>
const & proxy)
2922 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
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_base<T>,
2929 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2930 op_sub>
const & proxy)
2933 proxy.lhs(), T(1), 1,
false,
true,
2934 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2938 template <
typename ScalarType>
2939 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2940 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2941 op_sub>
const & proxy)
2944 proxy.lhs(), T(1), 1,
false,
true,
2945 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2949 template <
typename ScalarType1,
typename ScalarType2>
2950 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2951 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2952 op_sub>
const & proxy)
2955 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2956 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2960 template <
typename ScalarType1,
typename ScalarType2>
2961 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2962 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2963 op_sub>
const & proxy)
2966 proxy.lhs().lhs(), proxy.lhs().rhs(), 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_div>,
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,
true,
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_div>,
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,
true,
true,
2989 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
3013 template <
typename T,
typename LHS,
typename RHS,
typename OP>
3014 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const RHS, op_element_binary<OP> > >
3017 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3023 template <
typename LHS2,
typename RHS2,
typename OP2>
3024 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)
3026 vector<T> temp(proxy.rhs());
3031 template <
typename LHS1,
typename RHS1,
typename OP1>
3032 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)
3034 vector<T> temp(proxy.lhs());
3039 template <
typename LHS1,
typename RHS1,
typename OP1,
3040 typename LHS2,
typename RHS2,
typename OP2>
3041 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
3042 const vector_expression<const LHS2, const RHS2, OP2>,
3043 op_element_binary<OP> >
const & proxy)
3045 vector<T> temp1(proxy.lhs());
3046 vector<T> temp2(proxy.rhs());
3052 template <
typename T,
typename LHS,
typename RHS,
typename OP>
3053 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_element_binary<OP> > >
3056 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3063 template <
typename LHS2,
typename RHS2,
typename OP2>
3064 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)
3066 vector<T> temp(proxy.rhs());
3067 vector<T> temp2(temp.size());
3073 template <
typename LHS1,
typename RHS1,
typename OP1>
3074 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)
3076 vector<T> temp(proxy.lhs());
3077 vector<T> temp2(temp.size());
3083 template <
typename LHS1,
typename RHS1,
typename OP1,
3084 typename LHS2,
typename RHS2,
typename OP2>
3085 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
3086 const vector_expression<const LHS2, const RHS2, OP2>,
3087 op_element_binary<OP> >
const & proxy)
3089 vector<T> temp1(proxy.lhs());
3090 vector<T> temp2(proxy.rhs());
3091 vector<T> temp3(temp1.size());
3098 template <
typename T,
typename LHS,
typename RHS,
typename OP>
3099 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_element_binary<OP> > >
3103 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3110 template <
typename LHS2,
typename RHS2,
typename OP2>
3111 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)
3113 vector<T> temp(proxy.rhs());
3114 vector<T> temp2(temp.size());
3120 template <
typename LHS1,
typename RHS1,
typename OP1>
3121 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)
3123 vector<T> temp(proxy.lhs());
3124 vector<T> temp2(temp.size());
3130 template <
typename LHS1,
typename RHS1,
typename OP1,
3131 typename LHS2,
typename RHS2,
typename OP2>
3132 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
3133 const vector_expression<const LHS2, const RHS2, OP2>,
3134 op_element_binary<OP> >
const & proxy)
3136 vector<T> temp1(proxy.lhs());
3137 vector<T> temp2(proxy.rhs());
3138 vector<T> temp3(temp1.size());
3146 template <
typename T,
typename LHS,
typename RHS,
typename OP>
3147 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const RHS, op_element_unary<OP> > >
3150 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_unary<OP> >
const & proxy)
3156 template <
typename LHS2,
typename RHS2,
typename OP2>
3157 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS2, const RHS2, OP2>,
3158 const vector_expression<const LHS2, const RHS2, OP2>,
3159 op_element_unary<OP> >
const & proxy)
3161 vector<T> temp(proxy.rhs());
3166 template <
typename T,
typename LHS,
typename RHS,
typename OP>
3167 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_element_unary<OP> > >
3170 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_unary<OP> >
const & proxy)
3172 vector<T> temp(proxy);
3177 template <
typename LHS2,
typename RHS2,
typename OP2>
3178 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS2, const RHS2, OP2>,
3179 const vector_expression<const LHS2, const RHS2, OP2>,
3180 op_element_unary<OP> >
const & proxy)
3182 vector<T> temp(proxy.rhs());
3188 template <
typename T,
typename LHS,
typename RHS,
typename OP>
3189 struct op_executor<vector_base<T>, op_inplace_sub, 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());
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:1174
self_type & swap(self_type &other)
Swaps the entries of the two vectors.
Definition: vector.hpp:828
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:1079
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:837
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:1121
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:995
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:1155
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:1136
const_iterator end() const
Returns a const-iterator pointing to the end of the vector (STL like)
Definition: vector.hpp:821
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:1024
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:845
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:793
VectorType & at(vcl_size_t i) const
Definition: vector.hpp:1173
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:1086
size_type size() const
Returns the size of the result vector.
Definition: vector.hpp:187
self_type & operator=(T const &other)
Definition: vector.hpp:1059
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:868
self_type & operator/=(SCALARTYPE val)
Scales this vector by a CPU scalar value.
Definition: vector.hpp:765
void swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector.hpp:1669
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:1621
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:999
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:882
void clear()
Resets all entries to zero. Does not change the size of the vector.
Definition: vector.hpp:863
vector_tuple(std::vector< VectorType * > const &vecs)
Definition: vector.hpp:1161
vector(zero_vector< SCALARTYPE > const &v)
Creates the vector from the supplied zero vector.
Definition: vector.hpp:1044
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:755
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:989
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:786
vcl_size_t size() const
Definition: vector.hpp:1170
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:1680
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:1092
base_type::size_type size_type
Definition: vector.hpp:984
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:1074
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:1037
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:914
vector(size_type vec_size, viennacl::context ctx)
Definition: vector.hpp:997
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:1183
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:1051
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:1022
SCALARTYPE const_reference
Definition: vector.hpp:111
handle_type & handle()
Returns the memory handle.
Definition: vector.hpp:859
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:925
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:803
void set_handle(viennacl::backend::mem_handle const &h)
Definition: vector.hpp:875
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:815
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:809
base_type::difference_type difference_type
Definition: vector.hpp:985
std::ptrdiff_t vcl_ptrdiff_t
Definition: forwards.h:59
vector_tuple(VectorType &v0, VectorType &v1, VectorType &v2)
Definition: vector.hpp:1127
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:853
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:856
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:1108
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:1262
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:1312
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:1113
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:841
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:777
Main interface routines for memory management.
size_type stride() const
Returns the stride within the buffer (in multiples of sizeof(SCALARTYPE))
Definition: vector.hpp:849
vector_tuple(VectorType &v0, VectorType &v1, VectorType &v2, VectorType &v3)
Definition: vector.hpp:1143
std::pair< SCALARTYPE, bool > value_
Definition: vector.hpp:86
void switch_memory_context(viennacl::context new_ctx)
Definition: vector.hpp:899
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:890
vector(const self_type &v)
Definition: vector.hpp:1030
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:1171