1 #ifndef VIENNACL_VECTOR_HPP_
2 #define VIENNACL_VECTOR_HPP_
57 template<
typename LHS,
typename RHS,
typename OP>
58 class vector_expression
60 typedef typename viennacl::result_of::reference_if_nonscalar<LHS>::type lhs_reference_type;
61 typedef typename viennacl::result_of::reference_if_nonscalar<RHS>::type rhs_reference_type;
74 lhs_reference_type
lhs()
const {
return lhs_; }
77 rhs_reference_type
rhs()
const {
return rhs_; }
84 lhs_reference_type lhs_;
86 rhs_reference_type rhs_;
107 template<
class NumericT,
unsigned int AlignmentV>
108 class const_vector_iterator
110 typedef const_vector_iterator<NumericT, AlignmentV> self_type;
149 self_type
operator++(
int) { self_type tmp = *
this; ++(*this);
return tmp; }
161 difference_type
operator-(self_type
const & other)
const
164 return static_cast<difference_type
>(
index_) - static_cast<difference_type>(other.
index_);
204 template<
class NumericT,
unsigned int AlignmentV>
218 size_type
stride = 1) : base_type(elements, index,
start,
stride), elements_(elements) {}
239 handle_type &
handle() {
return elements_; }
247 handle_type & elements_;
251 template<
class NumericT,
typename SizeT,
typename DistanceT>
254 template<
class NumericT,
typename SizeT,
typename DistanceT>
257 : size_(vec_size), start_(vec_start), stride_(vec_stride), internal_size_(vec_size), elements_(h) {}
259 template<
class NumericT,
typename SizeT,
typename DistanceT>
271 template<
class NumericT,
typename SizeT,
typename DistanceT>
273 : size_(vec_size), start_(start), stride_(stride), internal_size_(vec_size)
277 #ifdef VIENNACL_WITH_CUDA
279 elements_.cuda_handle().reset(reinterpret_cast<char*>(ptr_to_mem));
280 elements_.cuda_handle().inc();
292 elements_.
raw_size(
sizeof(NumericT) * vec_size);
296 #ifdef VIENNACL_WITH_OPENCL
297 template<
class NumericT,
typename SizeT,
typename DistanceT>
299 : size_(vec_size), start_(start), stride_(stride), internal_size_(vec_size)
302 elements_.opencl_handle() = existing_mem;
303 elements_.opencl_handle().inc();
304 elements_.opencl_handle().context(ctx.opencl_context());
305 elements_.
raw_size(
sizeof(NumericT) * vec_size);
310 template<
class NumericT,
typename SizeT,
typename DistanceT>
311 template<
typename LHS,
typename RHS,
typename OP>
324 template<
class NumericT,
typename SizeT,
typename DistanceT>
326 size_(other.size_), start_(0), stride_(1),
340 template<
class NumericT,
typename SizeT,
typename DistanceT>
344 && bool(
"Incompatible vector sizes!"));
354 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_, dense_padding_size);
372 template<
class NumericT,
typename SizeT,
typename DistanceT>
373 template<
typename LHS,
typename RHS,
typename OP>
377 &&
bool(
"Incompatible vector sizes!"));
383 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_, dense_padding_size);
394 template<
class NumericT,
typename SizeT,
typename DistanceT>
399 && bool(
"Incompatible vector sizes!"));
406 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_, dense_padding_size);
413 v1, NumericT(1.0), 1,
false,
false);
419 template<
class NumericT,
typename SizeT,
typename DistanceT>
423 && bool(
"Incompatible vector sizes!"));
428 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_, dense_padding_size);
439 this->operator()(v.
index()) = NumericT(1);
445 template<
class NumericT,
typename SizeT,
typename DistanceT>
449 && bool(
"Incompatible vector sizes!"));
454 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_, dense_padding_size);
468 template<
class NumericT,
typename SizeT,
typename DistanceT>
472 && bool(
"Incompatible vector sizes!"));
477 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_, dense_padding_size);
499 template<
class NumericT,
typename SizeT,
typename DistanceT>
520 template<
class NumericT,
typename SizeT,
typename DistanceT>
547 template<
class NumericT,
typename SizeT,
typename DistanceT>
550 assert( (
size() > 0) &&
bool(
"Cannot apply operator() to vector of size zero!"));
551 assert( index <
size() &&
bool(
"Index out of bounds!") );
556 template<
class NumericT,
typename SizeT,
typename DistanceT>
559 assert( (
size() > 0) &&
bool(
"Cannot apply operator() to vector of size zero!"));
560 assert( index <
size() &&
bool(
"Index out of bounds!") );
565 template<
class NumericT,
typename SizeT,
typename DistanceT>
568 assert( (
size() > 0) &&
bool(
"Cannot apply operator() to vector of size zero!"));
569 assert( index <
size() &&
bool(
"Index out of bounds!") );
574 template<
class NumericT,
typename SizeT,
typename DistanceT>
577 assert( (
size() > 0) &&
bool(
"Cannot apply operator() to vector of size zero!"));
578 assert( index <
size() &&
bool(
"Index out of bounds!") );
589 template<
class NumericT,
typename SizeT,
typename DistanceT>
592 assert(vec.
size() ==
size() && bool(
"Incompatible vector sizes!"));
596 *
this, NumericT(1.0), 1,
false,
false,
597 vec, NumericT(1.0), 1,
false,
false);
601 template<
class NumericT,
typename SizeT,
typename DistanceT>
604 assert(vec.
size() ==
size() && bool(
"Incompatible vector sizes!"));
608 *
this, NumericT(1.0), 1,
false,
false,
609 vec, NumericT(-1.0), 1,
false,
false);
614 template<
class NumericT,
typename SizeT,
typename DistanceT>
619 *
this, NumericT(val), 1,
false,
false);
623 template<
class NumericT,
typename SizeT,
typename DistanceT>
628 *
this, NumericT(val), 1,
false,
false);
632 template<
class NumericT,
typename SizeT,
typename DistanceT>
637 *
this, NumericT(val), 1,
false,
false);
641 template<
class NumericT,
typename SizeT,
typename DistanceT>
646 *
this, NumericT(val), 1,
false,
false);
650 template<
class NumericT,
typename SizeT,
typename DistanceT>
655 *
this, NumericT(val), 1,
false,
false);
659 template<
class NumericT,
typename SizeT,
typename DistanceT>
664 *
this, NumericT(val), 1,
false,
false);
670 template<
class NumericT,
typename SizeT,
typename DistanceT>
675 *
this, NumericT(val), 1,
true,
false);
679 template<
class NumericT,
typename SizeT,
typename DistanceT>
684 *
this, NumericT(val), 1,
true,
false);
688 template<
class NumericT,
typename SizeT,
typename DistanceT>
693 *
this, NumericT(val), 1,
true,
false);
697 template<
class NumericT,
typename SizeT,
typename DistanceT>
702 *
this, NumericT(val), 1,
true,
false);
706 template<
class NumericT,
typename SizeT,
typename DistanceT>
711 *
this, NumericT(val), 1,
true,
false);
715 template<
class NumericT,
typename SizeT,
typename DistanceT>
720 *
this, NumericT(val), 1,
true,
false);
726 template<
class NumericT,
typename SizeT,
typename DistanceT>
733 template<
class NumericT,
typename SizeT,
typename DistanceT>
740 template<
class NumericT,
typename SizeT,
typename DistanceT>
747 template<
class NumericT,
typename SizeT,
typename DistanceT>
754 template<
class NumericT,
typename SizeT,
typename DistanceT>
761 template<
class NumericT,
typename SizeT,
typename DistanceT>
770 template<
class NumericT,
typename SizeT,
typename DistanceT>
777 template<
class NumericT,
typename SizeT,
typename DistanceT>
784 template<
class NumericT,
typename SizeT,
typename DistanceT>
791 template<
class NumericT,
typename SizeT,
typename DistanceT>
798 template<
class NumericT,
typename SizeT,
typename DistanceT>
805 template<
class NumericT,
typename SizeT,
typename DistanceT>
814 template<
class NumericT,
typename SizeT,
typename DistanceT>
826 template<
class NumericT,
typename SizeT,
typename DistanceT>
829 return iterator(*
this, 0, start_, stride_);
833 template<
class NumericT,
typename SizeT,
typename DistanceT>
840 template<
class NumericT,
typename SizeT,
typename DistanceT>
846 template<
class NumericT,
typename SizeT,
typename DistanceT>
852 template<
class NumericT,
typename SizeT,
typename DistanceT>
860 template<
class NumericT,
typename SizeT,
typename DistanceT>
866 template<
class NumericT,
typename SizeT,
typename DistanceT>
869 assert(this->size_ == other.size_ &&
bool(
"Vector size mismatch"));
870 this->elements_.swap(other.elements_);
874 template<
class NumericT,
typename SizeT,
typename DistanceT>
884 template<
class NumericT,
typename SizeT,
typename DistanceT>
887 viennacl::backend::switch_memory_context<NumericT>(elements_, new_ctx);
894 template<
class NumericT,
typename SizeT,
typename DistanceT>
900 template<
class NumericT,
typename SizeT,
typename DistanceT>
903 resize_impl(new_size, ctx, preserve);
906 template<
class NumericT,
typename SizeT,
typename DistanceT>
909 assert(new_size > 0 &&
bool(
"Positive size required when resizing vector!"));
911 if (new_size != size_)
913 vcl_size_t new_internal_size = viennacl::tools::align_to_multiple<vcl_size_t>(new_size, dense_padding_size);
915 std::vector<NumericT> temp(size_);
916 if (preserve && size_ > 0)
918 temp.resize(new_size);
919 temp.resize(new_internal_size);
928 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_, dense_padding_size);
935 template<
class NumericT,
unsigned int AlignmentV>
936 class vector :
public vector_base<NumericT>
938 typedef vector<NumericT, AlignmentV> self_type;
939 typedef vector_base<NumericT> base_type;
953 explicit vector(size_type vec_size) : base_type(vec_size) {}
958 : base_type(ptr_to_mem, mem_type, vec_size, start, stride) {}
960 #ifdef VIENNACL_WITH_OPENCL
969 explicit vector(cl_mem existing_mem, size_type vec_size, size_type start = 0, size_type stride = 1) : base_type(existing_mem, vec_size, start, stride) {}
979 template<
typename LHS,
typename RHS,
typename OP>
985 base_type::operator=(v);
991 base_type::operator=(v);
998 this->
operator()(v.
index()) = NumericT(1);;
1016 template<
typename T>
1023 using base_type::operator+=;
1024 using base_type::operator-=;
1032 void resize(size_type new_size,
bool preserve =
true)
1058 template<
typename ScalarT>
1061 typedef vector_base<ScalarT> VectorType;
1066 vector_tuple(VectorType
const & v0, VectorType
const &
v1) : const_vectors_(2), non_const_vectors_()
1068 const_vectors_[0] = &v0;
1069 const_vectors_[1] = &
v1;
1071 vector_tuple(VectorType & v0, VectorType &
v1) : const_vectors_(2), non_const_vectors_(2)
1073 const_vectors_[0] = &v0; non_const_vectors_[0] = &v0;
1074 const_vectors_[1] = &
v1; non_const_vectors_[1] = &
v1;
1079 vector_tuple(VectorType
const & v0, VectorType
const &
v1, VectorType
const &
v2) : const_vectors_(3), non_const_vectors_()
1081 const_vectors_[0] = &v0;
1082 const_vectors_[1] = &
v1;
1083 const_vectors_[2] = &
v2;
1085 vector_tuple(VectorType & v0, VectorType &
v1, VectorType &
v2) : const_vectors_(3), non_const_vectors_(3)
1087 const_vectors_[0] = &v0; non_const_vectors_[0] = &v0;
1088 const_vectors_[1] = &
v1; non_const_vectors_[1] = &
v1;
1089 const_vectors_[2] = &
v2; non_const_vectors_[2] = &
v2;
1094 vector_tuple(VectorType
const & v0, VectorType
const &
v1, VectorType
const &
v2, VectorType
const & v3) : const_vectors_(4), non_const_vectors_()
1096 const_vectors_[0] = &v0;
1097 const_vectors_[1] = &
v1;
1098 const_vectors_[2] = &
v2;
1099 const_vectors_[3] = &v3;
1101 vector_tuple(VectorType & v0, VectorType &
v1, VectorType &
v2, VectorType & v3) : const_vectors_(4), non_const_vectors_(4)
1103 const_vectors_[0] = &v0; non_const_vectors_[0] = &v0;
1104 const_vectors_[1] = &
v1; non_const_vectors_[1] = &
v1;
1105 const_vectors_[2] = &
v2; non_const_vectors_[2] = &
v2;
1106 const_vectors_[3] = &v3; non_const_vectors_[3] = &v3;
1113 vector_tuple(std::vector<VectorType const *>
const & vecs) : const_vectors_(vecs.
size()), non_const_vectors_()
1116 const_vectors_[i] = vecs[i];
1119 vector_tuple(std::vector<VectorType *>
const & vecs) : const_vectors_(vecs.
size()), non_const_vectors_(vecs.
size())
1123 const_vectors_[i] = vecs[i];
1124 non_const_vectors_[i] = vecs[i];
1131 VectorType &
at(
vcl_size_t i)
const {
return *(non_const_vectors_.at(i)); }
1135 std::vector<VectorType const *> const_vectors_;
1136 std::vector<VectorType *> non_const_vectors_;
1140 template<
typename ScalarT>
1143 template<
typename ScalarT>
1147 template<
typename ScalarT>
1150 template<
typename ScalarT>
1154 template<
typename ScalarT>
1160 template<
typename ScalarT>
1167 template<
typename ScalarT>
1175 std::vector<VectorPointerType> vec(5);
1184 template<
typename ScalarT>
1192 std::vector<VectorPointerType> vec(5);
1219 template<
typename NumericT,
unsigned int AlignmentV,
typename CPU_ITERATOR>
1222 CPU_ITERATOR cpu_begin )
1224 if (gpu_begin != gpu_end)
1226 if (gpu_begin.stride() == 1)
1229 sizeof(NumericT)*gpu_begin.offset(),
1230 sizeof(NumericT)*gpu_begin.stride() *
static_cast<vcl_size_t>(gpu_end - gpu_begin),
1236 std::vector<NumericT> temp_buffer(gpu_begin.stride() * gpu_size);
1241 (&(*cpu_begin))[i] = temp_buffer[i * gpu_begin.stride()];
1252 template<
typename NumericT,
typename CPUVECTOR>
1269 template<
typename NumericT,
unsigned int AlignmentV,
typename CPU_ITERATOR>
1272 CPU_ITERATOR cpu_begin )
1274 if (gpu_begin != gpu_end)
1276 if (gpu_begin.stride() == 1)
1279 sizeof(NumericT)*gpu_begin.offset(),
1280 sizeof(NumericT)*gpu_begin.stride() *
static_cast<vcl_size_t>(gpu_end - gpu_begin),
1285 fast_copy(gpu_begin, gpu_end, cpu_begin);
1294 template<
typename NumericT,
typename CPUVECTOR>
1307 template<
typename NumericT,
unsigned int AlignmentV,
typename CPU_ITERATOR>
1310 CPU_ITERATOR cpu_begin )
1312 assert(gpu_end - gpu_begin >= 0 &&
bool(
"Iterators incompatible"));
1313 if (gpu_end - gpu_begin != 0)
1315 std::vector<NumericT> temp_buffer(static_cast<vcl_size_t>(gpu_end - gpu_begin));
1316 fast_copy(gpu_begin, gpu_end, temp_buffer.begin());
1319 std::copy(temp_buffer.begin(), temp_buffer.end(), cpu_begin);
1329 template<
typename NumericT,
unsigned int AlignmentV,
typename CPU_ITERATOR>
1332 CPU_ITERATOR cpu_begin )
1345 template<
typename NumericT,
typename CPUVECTOR>
1353 #ifdef VIENNACL_WITH_EIGEN
1354 template<
unsigned int AlignmentV>
1355 void copy(vector<float, AlignmentV>
const & gpu_vec,
1356 Eigen::VectorXf & eigen_vec)
1361 template<
unsigned int AlignmentV>
1362 void copy(vector<double, AlignmentV> & gpu_vec,
1363 Eigen::VectorXd & eigen_vec)
1385 template<
typename CPU_ITERATOR,
typename NumericT,
unsigned int AlignmentV>
1387 CPU_ITERATOR
const & cpu_end,
1390 if (cpu_end - cpu_begin > 0)
1392 if (gpu_begin.
stride() == 1)
1395 sizeof(NumericT)*gpu_begin.
offset(),
1396 sizeof(NumericT)*gpu_begin.
stride() *
static_cast<vcl_size_t>(cpu_end - cpu_begin), &(*cpu_begin));
1401 std::vector<NumericT> temp_buffer(gpu_begin.
stride() * cpu_size);
1406 temp_buffer[i * gpu_begin.
stride()] = (&(*cpu_begin))[i];
1419 template<
typename CPUVECTOR,
typename NumericT>
1435 template<
typename CPU_ITERATOR,
typename NumericT,
unsigned int AlignmentV>
1437 CPU_ITERATOR
const & cpu_end,
1440 if (cpu_end - cpu_begin > 0)
1442 if (gpu_begin.
stride() == 1)
1445 sizeof(NumericT)*gpu_begin.
offset(),
1446 sizeof(NumericT)*gpu_begin.
stride() *
static_cast<vcl_size_t>(cpu_end - cpu_begin), &(*cpu_begin),
1450 fast_copy(cpu_begin, cpu_end, gpu_begin);
1460 template<
typename CPUVECTOR,
typename NumericT>
1473 template<
typename NumericT,
unsigned int AlignmentV,
typename CPU_ITERATOR>
1474 void copy(CPU_ITERATOR
const & cpu_begin,
1475 CPU_ITERATOR
const & cpu_end,
1478 assert(cpu_end - cpu_begin > 0 &&
bool(
"Iterators incompatible"));
1479 if (cpu_begin != cpu_end)
1482 std::vector<NumericT> temp_buffer(static_cast<vcl_size_t>(cpu_end - cpu_begin));
1483 std::copy(cpu_begin, cpu_end, temp_buffer.begin());
1495 template<
typename HostVectorT,
typename T>
1506 template<
typename HostVectorT,
typename T,
unsigned int AlignmentV>
1509 if (gpu_vec.size() == 0)
1510 gpu_vec.resize(static_cast<vcl_size_t>(cpu_vec.end() - cpu_vec.begin()));
1515 #ifdef VIENNACL_WITH_EIGEN
1516 template<
unsigned int AlignmentV>
1517 void copy(Eigen::VectorXf
const & eigen_vec,
1518 vector<float, AlignmentV> & gpu_vec)
1520 std::vector<float> entries(eigen_vec.size());
1521 for (
vcl_size_t i = 0; i<entries.size(); ++i)
1522 entries[i] = eigen_vec(i);
1526 template<
unsigned int AlignmentV>
1527 void copy(Eigen::VectorXd
const & eigen_vec,
1528 vector<double, AlignmentV> & gpu_vec)
1530 std::vector<double> entries(eigen_vec.size());
1531 for (
vcl_size_t i = 0; i<entries.size(); ++i)
1532 entries[i] = eigen_vec(i);
1548 template<
typename NumericT,
unsigned int AlignmentV_SRC,
unsigned int AlignmentV_DEST>
1553 assert(gpu_src_end - gpu_src_begin >= 0);
1554 assert(gpu_src_begin.stride() == 1 && bool(
"ViennaCL ERROR: copy() for GPU->GPU not implemented for slices! Use operator= instead for the moment."));
1556 if (gpu_src_begin.stride() == 1 && gpu_dest_begin.
stride() == 1)
1558 if (gpu_src_begin != gpu_src_end)
1560 sizeof(NumericT) * gpu_src_begin.offset(),
1561 sizeof(NumericT) * gpu_dest_begin.
offset(),
1562 sizeof(NumericT) * (gpu_src_end.offset() - gpu_src_begin.offset()));
1566 assert(
false &&
bool(
"not implemented yet"));
1576 template<
typename NumericT,
unsigned int AlignmentV_SRC,
unsigned int AlignmentV_DEST>
1591 template<
typename NumericT,
unsigned int AlignmentV_SRC,
unsigned int AlignmentV_DEST>
1595 viennacl::copy(gpu_src_vec.begin(), gpu_src_vec.end(), gpu_dest_vec.begin());
1608 template<
typename T>
1609 std::ostream & operator<<(std::ostream & os, vector_base<T>
const & val)
1611 std::vector<T> tmp(val.size());
1613 os <<
"[" << val.size() <<
"](";
1614 for (
typename std::vector<T>::size_type i=0; i<val.size(); ++i)
1624 template<
typename LHS,
typename RHS,
typename OP>
1625 std::ostream & operator<<(std::ostream & os, vector_expression<LHS, RHS, OP>
const & proxy)
1639 template<
typename T>
1650 template<
typename NumericT,
unsigned int AlignmentV>
1654 return v1.fast_swap(v2);
1674 template<
typename T,
typename S1>
1683 v1, gpu_val, 1,
false, flip_sign);
1695 template<
typename T,
typename S1>
1704 v1, gpu_val, 1,
true, flip_sign);
1719 template<
typename LHS1,
typename RHS1,
typename OP1,
1720 typename LHS2,
typename RHS2,
typename OP2>
1721 vector_expression< const vector_expression< LHS1, RHS1, OP1>,
1722 const vector_expression< LHS2, RHS2, OP2>,
1727 assert(proxy1.size() == proxy2.size() && bool(
"Incompatible vector sizes!"));
1738 template<
typename LHS,
typename RHS,
typename OP,
typename T>
1739 vector_expression< const vector_expression<LHS, RHS, OP>,
1740 const vector_base<T>,
1743 vector_base<T>
const & vec)
1745 assert(proxy.size() == vec.
size() && bool(
"Incompatible vector sizes!"));
1747 const vector_base<T>,
1756 template<
typename T,
typename LHS,
typename RHS,
typename OP>
1757 vector_expression< const vector_base<T>,
1758 const vector_expression<LHS, RHS, OP>,
1761 vector_expression<LHS, RHS, OP>
const & proxy)
1763 assert(proxy.size() == vec.
size() && bool(
"Incompatible vector sizes!"));
1765 const vector_expression<LHS, RHS, OP>,
1771 template<
typename T>
1772 vector_expression< const vector_base<T>,
const vector_base<T>, op_add>
1789 template<
typename LHS1,
typename RHS1,
typename OP1,
1790 typename LHS2,
typename RHS2,
typename OP2>
1791 vector_expression< const vector_expression< LHS1, RHS1, OP1>,
1792 const vector_expression< LHS2, RHS2, OP2>,
1797 assert(proxy1.size() == proxy2.size() && bool(
"Incompatible vector sizes!"));
1809 template<
typename LHS,
typename RHS,
typename OP,
typename T>
1810 vector_expression< const vector_expression<LHS, RHS, OP>,
1811 const vector_base<T>,
1814 vector_base<T>
const & vec)
1816 assert(proxy.size() == vec.
size() && bool(
"Incompatible vector sizes!"));
1818 const vector_base<T>,
1827 template<
typename T,
typename LHS,
typename RHS,
typename OP>
1828 vector_expression< const vector_base<T>,
1829 const vector_expression<LHS, RHS, OP>,
1832 vector_expression<LHS, RHS, OP>
const & proxy)
1834 assert(proxy.size() == vec.
size() && bool(
"Incompatible vector sizes!"));
1836 const vector_expression<LHS, RHS, OP>,
1842 template<
typename T>
1843 vector_expression< const vector_base<T>,
const vector_base<T>, op_sub>
1860 template<
typename S1,
typename T>
1862 vector_expression< const vector_base<T>,
const S1, op_mult> >::type
1865 return vector_expression< const vector_base<T>,
const S1,
op_mult>(vec, value);
1873 template<
typename T>
1874 vector_expression< const vector_base<T>,
const T, op_mult>
1877 return vector_expression< const vector_base<T>,
const T,
op_mult>(vec, T(value));
1885 template<
typename T>
1886 vector_expression< const vector_base<T>,
const T, op_mult>
1889 return vector_expression< const vector_base<T>,
const T,
op_mult>(vec, T(value));
1897 template<
typename T>
1898 vector_expression< const vector_base<T>,
const T, op_mult>
1901 return vector_expression< const vector_base<T>,
const T,
op_mult>(vec, T(value));
1909 template<
typename T>
1910 vector_expression< const vector_base<T>,
const T, op_mult>
1913 return vector_expression< const vector_base<T>,
const T,
op_mult>(vec, T(value));
1921 template<
typename T>
1922 vector_expression< const vector_base<T>,
const T, op_mult>
1925 return vector_expression< const vector_base<T>,
const T,
op_mult>(vec, T(value));
1933 template<
typename T>
1934 vector_expression< const vector_base<T>,
const T, op_mult>
1937 return vector_expression< const vector_base<T>,
const T,
op_mult>(vec, T(value));
1947 template<
typename LHS,
typename RHS,
typename OP,
typename T>
1948 vector_expression< const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
1949 operator * (scalar_expression<LHS, RHS, OP>
const & expr, vector_base<T>
const & vec)
1951 return vector_expression< const vector_base<T>,
const scalar_expression<LHS, RHS, OP>,
op_mult>(vec, expr);
1956 template<
typename T,
typename S1>
1958 vector_expression< const vector_base<T>,
const S1, op_mult> >::type
1961 return vector_expression< const vector_base<T>,
const S1,
op_mult>(vec, value);
1964 template<
typename T>
1965 vector_expression< const vector_base<T>,
const T, op_mult>
1968 return vector_expression< const vector_base<T>,
const T,
op_mult>(vec, value);
1976 template<
typename LHS,
typename RHS,
typename OP,
typename S1>
1982 return viennacl::vector_expression<const vector_expression<LHS, RHS, OP>,
const S1,
op_mult>(proxy, val);
1990 template<
typename S1,
typename LHS,
typename RHS,
typename OP>
1992 viennacl::vector_expression<const vector_expression<LHS, RHS, OP>,
const S1, op_mult> >::type
1994 vector_expression<LHS, RHS, OP>
const & proxy)
1996 return viennacl::vector_expression<const vector_expression<LHS, RHS, OP>,
const S1,
op_mult>(proxy, val);
2008 template<
typename S1,
typename LHS,
typename RHS,
typename OP>
2010 viennacl::vector_expression<const vector_expression<LHS, RHS, OP>,
const S1, op_div> >::type
2014 return viennacl::vector_expression<const vector_expression<LHS, RHS, OP>,
const S1,
op_div>(proxy, val);
2020 template<
typename T,
typename S1>
2022 vector_expression< const vector_base<T>,
const S1, op_div> >::type
2041 template<
typename T>
2042 struct op_executor<vector_base<T>,
op_assign, vector_base<T> >
2044 static void apply(vector_base<T> & lhs, vector_base<T>
const & rhs)
2051 template<
typename T>
2052 struct op_executor<vector_base<T>,
op_assign, vector_expression<const vector_base<T>, const vector_tuple<T>, op_inner_prod> >
2054 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_tuple<T>, op_inner_prod>
const & rhs)
2061 template<
typename T>
2062 struct op_executor<vector_base<T>, op_inplace_add, vector_base<T> >
2064 static void apply(vector_base<T> & lhs, vector_base<T>
const & rhs)
2066 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, rhs, T(1), 1,
false,
false);
2071 template<
typename T>
2072 struct op_executor<vector_base<T>, op_inplace_sub, vector_base<T> >
2074 static void apply(vector_base<T> & lhs, vector_base<T>
const & rhs)
2076 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, rhs, T(1), 1,
false,
true);
2084 template<
typename T,
typename ScalarType>
2085 struct op_executor<vector_base<T>,
op_assign, vector_expression<const vector_base<T>, const
ScalarType, op_mult> >
2088 template<
typename LHS,
typename RHS,
typename OP>
2089 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
const & proxy)
2091 T alpha = proxy.rhs();
2095 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar<T>, op_mult>
const & proxy)
2100 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const T, op_mult>
const & proxy)
2107 template<
typename T,
typename ScalarType>
2108 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_base<T>, const
ScalarType, op_mult> >
2111 template<
typename LHS,
typename RHS,
typename OP>
2112 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
const & proxy)
2114 T alpha = proxy.rhs();
2115 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), alpha, 1,
false,
false);
2118 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar<T>, op_mult>
const & proxy)
2120 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
false);
2123 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const T, op_mult>
const & proxy)
2125 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
false);
2130 template<
typename T,
typename ScalarType>
2131 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vector_base<T>, const
ScalarType, op_mult> >
2134 template<
typename LHS,
typename RHS,
typename OP>
2135 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
const & proxy)
2137 T alpha = proxy.rhs();
2138 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), alpha, 1,
false,
true);
2141 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar<T>, op_mult>
const & proxy)
2143 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
true);
2146 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const T, op_mult>
const & proxy)
2148 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
true);
2156 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2157 struct op_executor<vector_base<T>,
op_assign, vector_expression<const vector_expression<const LHS, const RHS, OP>, const
ScalarType, op_mult> >
2159 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_mult>
const & proxy)
2161 vector<T> temp(proxy.lhs());
2162 lhs = temp * proxy.rhs();
2167 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2168 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_expression<const LHS, const RHS, OP>, const
ScalarType, op_mult> >
2170 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_mult>
const & proxy)
2172 vector<T> temp(proxy.lhs());
2173 lhs += temp * proxy.rhs();
2178 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2179 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vector_expression<const LHS, const RHS, OP>, const
ScalarType, op_mult> >
2181 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_mult>
const & proxy)
2183 vector<T> temp(proxy.lhs());
2184 lhs -= temp * proxy.rhs();
2192 template<
typename T,
typename ScalarType>
2193 struct op_executor<vector_base<T>,
op_assign, vector_expression<const vector_base<T>, const
ScalarType, op_div> >
2195 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const ScalarType, op_div>
const & proxy)
2202 template<
typename T,
typename ScalarType>
2203 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_base<T>, const
ScalarType, op_div> >
2205 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const ScalarType, op_div>
const & proxy)
2207 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
true,
false);
2212 template<
typename T,
typename ScalarType>
2213 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vector_base<T>, const
ScalarType, op_div> >
2215 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const ScalarType, op_div>
const & proxy)
2217 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
true,
true);
2225 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2226 struct op_executor<vector_base<T>,
op_assign, vector_expression<const vector_expression<const LHS, const RHS, OP>, const
ScalarType, op_div> >
2228 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_div>
const & proxy)
2230 vector<T> temp(proxy.lhs());
2231 lhs = temp / proxy.rhs();
2236 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2237 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_expression<const LHS, const RHS, OP>, const
ScalarType, op_div> >
2239 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_div>
const & proxy)
2241 vector<T> temp(proxy.lhs());
2242 lhs += temp / proxy.rhs();
2247 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2248 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vector_expression<const LHS, const RHS, OP>, const
ScalarType, op_div> >
2250 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_div>
const & proxy)
2252 vector<T> temp(proxy.lhs());
2253 lhs -= temp / proxy.rhs();
2260 template<
typename T,
typename LHS,
typename RHS>
2261 struct op_executor<vector_base<T>,
op_assign, vector_expression<const LHS, const RHS, op_add> >
2264 template<
typename LHS1,
typename RHS1>
2265 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_add>
const & proxy)
2267 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2268 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2270 if (op_aliasing_lhs || op_aliasing_rhs)
2272 vector_base<T> temp(proxy.lhs());
2273 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2278 op_executor<vector_base<T>,
op_assign, LHS>::apply(lhs, proxy.lhs());
2279 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2284 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_add>
const & proxy)
2287 proxy.lhs(), T(1), 1,
false,
false,
2288 proxy.rhs(), T(1), 1,
false,
false);
2292 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_mult>,
2293 const vector_base<T>,
2294 op_add>
const & proxy)
2297 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2298 proxy.rhs(), T(1), 1,
false,
false);
2302 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_div>,
2303 const vector_base<T>,
2304 op_add>
const & proxy)
2307 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2308 proxy.rhs(), T(1), 1,
false,
false);
2312 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2313 const vector_expression<
const vector_base<T>,
const T, op_mult>,
2314 op_add>
const & proxy)
2317 proxy.lhs(), T(1), 1,
false,
false,
2318 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2322 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2323 const vector_expression<
const vector_base<T>,
const T, op_div>,
2324 op_add>
const & proxy)
2327 proxy.lhs(), T(1), 1,
false,
false,
2328 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2332 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_mult>,
2333 const vector_expression<
const vector_base<T>,
const T, op_mult>,
2334 op_add>
const & proxy)
2337 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2338 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2342 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_mult>,
2343 const vector_expression<
const vector_base<T>,
const T, op_div>,
2344 op_add>
const & proxy)
2347 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2348 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2352 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_div>,
2353 const vector_expression<
const vector_base<T>,
const T, op_mult>,
2354 op_add>
const & proxy)
2357 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2358 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2362 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_div>,
2363 const vector_expression<
const vector_base<T>,
const T, op_div>,
2364 op_add>
const & proxy)
2367 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2368 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2374 template<
typename T,
typename LHS,
typename RHS>
2375 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_add> >
2378 template<
typename LHS1,
typename RHS1>
2379 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_add>
const & proxy)
2381 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2382 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2384 if (op_aliasing_lhs || op_aliasing_rhs)
2386 vector_base<T> temp(proxy.lhs());
2387 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2392 op_executor<vector_base<T>, op_inplace_add, LHS>::apply(lhs, proxy.lhs());
2393 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2398 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_add>
const & proxy)
2401 proxy.lhs(), T(1), 1,
false,
false,
2402 proxy.rhs(), T(1), 1,
false,
false);
2406 template<
typename ScalarType>
2407 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2408 const vector_base<T>,
2409 op_add>
const & proxy)
2412 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2413 proxy.rhs(), T(1), 1,
false,
false);
2417 template<
typename ScalarType>
2418 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2419 const vector_base<T>,
2420 op_add>
const & proxy)
2423 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2424 proxy.rhs(), T(1), 1,
false,
false);
2428 template<
typename ScalarType>
2429 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2430 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2431 op_add>
const & proxy)
2434 proxy.lhs(), T(1), 1,
false,
false,
2435 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2439 template<
typename ScalarType>
2440 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2441 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2442 op_add>
const & proxy)
2445 proxy.lhs(), T(1), 1,
false,
false,
2446 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2450 template<
typename ScalarType1,
typename ScalarType2>
2451 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2452 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2453 op_add>
const & proxy)
2456 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2457 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2461 template<
typename ScalarType1,
typename ScalarType2>
2462 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2463 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2464 op_add>
const & proxy)
2467 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2468 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2472 template<
typename ScalarType1,
typename ScalarType2>
2473 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2474 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2475 op_add>
const & proxy)
2478 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2479 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2483 template<
typename ScalarType1,
typename ScalarType2>
2484 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2485 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2486 op_add>
const & proxy)
2489 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2490 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2497 template<
typename T,
typename LHS,
typename RHS>
2498 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_add> >
2501 template<
typename LHS1,
typename RHS1>
2502 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_add>
const & proxy)
2504 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2505 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2507 if (op_aliasing_lhs || op_aliasing_rhs)
2509 vector_base<T> temp(proxy.lhs());
2510 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2515 op_executor<vector_base<T>, op_inplace_sub, LHS>::apply(lhs, proxy.lhs());
2516 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2521 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_add>
const & proxy)
2524 proxy.lhs(), T(1), 1,
false,
true,
2525 proxy.rhs(), T(1), 1,
false,
true);
2529 template<
typename ScalarType>
2530 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2531 const vector_base<T>,
2532 op_add>
const & proxy)
2535 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2536 proxy.rhs(), T(1), 1,
false,
true);
2540 template<
typename ScalarType>
2541 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2542 const vector_base<T>,
2543 op_add>
const & proxy)
2546 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2547 proxy.rhs(), T(1), 1,
false,
true);
2551 template<
typename ScalarType>
2552 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2553 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2554 op_add>
const & proxy)
2557 proxy.lhs(), T(1), 1,
false,
true,
2558 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2562 template<
typename ScalarType>
2563 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2564 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2565 op_add>
const & proxy)
2568 proxy.lhs(), T(1), 1,
false,
true,
2569 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2573 template<
typename ScalarType1,
typename ScalarType2>
2574 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2575 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2576 op_add>
const & proxy)
2579 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2580 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2584 template<
typename ScalarType1,
typename ScalarType2>
2585 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2586 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2587 op_add>
const & proxy)
2590 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2591 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2595 template<
typename ScalarType1,
typename ScalarType2>
2596 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2597 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2598 op_add>
const & proxy)
2601 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2602 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2606 template<
typename ScalarType1,
typename ScalarType2>
2607 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2608 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2609 op_add>
const & proxy)
2612 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2613 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2624 template<
typename T,
typename LHS,
typename RHS>
2625 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const RHS, op_sub> >
2628 template<
typename LHS1,
typename RHS1>
2629 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2631 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2632 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2634 if (op_aliasing_lhs || op_aliasing_rhs)
2636 vector_base<T> temp(proxy.lhs());
2637 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2642 op_executor<vector_base<T>, op_assign, LHS>::apply(lhs, proxy.lhs());
2643 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2648 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_sub>
const & proxy)
2651 proxy.lhs(), T(1), 1,
false,
false,
2652 proxy.rhs(), T(1), 1,
false,
true);
2656 template<
typename ScalarType>
2657 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2658 const vector_base<T>,
2659 op_sub>
const & proxy)
2662 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2663 proxy.rhs(), T(1), 1,
false,
true);
2667 template<
typename ScalarType>
2668 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2669 const vector_base<T>,
2670 op_sub>
const & proxy)
2673 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2674 proxy.rhs(), T(1), 1,
false,
true);
2678 template<
typename ScalarType>
2679 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2680 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2681 op_sub>
const & proxy)
2684 proxy.lhs(), T(1), 1,
false,
false,
2685 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2689 template<
typename ScalarType>
2690 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2691 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2692 op_sub>
const & proxy)
2695 proxy.lhs(), T(1), 1,
false,
false,
2696 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2700 template<
typename ScalarType1,
typename ScalarType2>
2701 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2702 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2703 op_sub>
const & proxy)
2706 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2707 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2711 template<
typename ScalarType1,
typename ScalarType2>
2712 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2713 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2714 op_sub>
const & proxy)
2717 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2718 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2722 template<
typename ScalarType1,
typename ScalarType2>
2723 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2724 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2725 op_sub>
const & proxy)
2728 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2729 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2733 template<
typename ScalarType1,
typename ScalarType2>
2734 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2735 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2736 op_sub>
const & proxy)
2739 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2740 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2746 template<
typename T,
typename LHS,
typename RHS>
2747 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_sub> >
2750 template<
typename LHS1,
typename RHS1>
2751 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2753 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2754 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2756 if (op_aliasing_lhs || op_aliasing_rhs)
2758 vector_base<T> temp(proxy.lhs());
2759 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2764 op_executor<vector_base<T>, op_inplace_add, LHS>::apply(lhs, proxy.lhs());
2765 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2770 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_sub>
const & proxy)
2773 proxy.lhs(), T(1), 1,
false,
false,
2774 proxy.rhs(), T(1), 1,
false,
true);
2778 template<
typename ScalarType>
2779 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2780 const vector_base<T>,
2781 op_sub>
const & proxy)
2784 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2785 proxy.rhs(), T(1), 1,
false,
true);
2789 template<
typename ScalarType>
2790 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2791 const vector_base<T>,
2792 op_sub>
const & proxy)
2795 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2796 proxy.rhs(), T(1), 1,
false,
true);
2800 template<
typename ScalarType>
2801 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2802 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2803 op_sub>
const & proxy)
2806 proxy.lhs(), T(1), 1,
false,
false,
2807 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2811 template<
typename ScalarType>
2812 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2813 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2814 op_sub>
const & proxy)
2817 proxy.lhs(), T(1), 1,
false,
false,
2818 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2822 template<
typename ScalarType1,
typename ScalarType2>
2823 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2824 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2825 op_sub>
const & proxy)
2828 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2829 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2833 template<
typename ScalarType1,
typename ScalarType2>
2834 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2835 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2836 op_sub>
const & proxy)
2839 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2840 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2844 template<
typename ScalarType1,
typename ScalarType2>
2845 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2846 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2847 op_sub>
const & proxy)
2850 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2851 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2855 template<
typename ScalarType1,
typename ScalarType2>
2856 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2857 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2858 op_sub>
const & proxy)
2861 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2862 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2869 template<
typename T,
typename LHS,
typename RHS>
2870 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_sub> >
2873 template<
typename LHS1,
typename RHS1>
2874 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2876 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2877 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2879 if (op_aliasing_lhs || op_aliasing_rhs)
2881 vector_base<T> temp(proxy.lhs());
2882 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2887 op_executor<vector_base<T>, op_inplace_sub, LHS>::apply(lhs, proxy.lhs());
2888 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2893 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_sub>
const & proxy)
2896 proxy.lhs(), T(1), 1,
false,
true,
2897 proxy.rhs(), T(1), 1,
false,
false);
2901 template<
typename ScalarType>
2902 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2903 const vector_base<T>,
2904 op_sub>
const & proxy)
2907 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2908 proxy.rhs(), T(1), 1,
false,
false);
2912 template<
typename ScalarType>
2913 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2914 const vector_base<T>,
2915 op_sub>
const & proxy)
2918 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2919 proxy.rhs(), T(1), 1,
false,
false);
2923 template<
typename ScalarType>
2924 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2925 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2926 op_sub>
const & proxy)
2929 proxy.lhs(), T(1), 1,
false,
true,
2930 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2934 template<
typename ScalarType>
2935 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2936 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2937 op_sub>
const & proxy)
2940 proxy.lhs(), T(1), 1,
false,
true,
2941 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2945 template<
typename ScalarType1,
typename ScalarType2>
2946 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2947 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2948 op_sub>
const & proxy)
2951 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2952 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2956 template<
typename ScalarType1,
typename ScalarType2>
2957 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2958 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2959 op_sub>
const & proxy)
2962 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2963 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2967 template<
typename ScalarType1,
typename ScalarType2>
2968 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2969 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2970 op_sub>
const & proxy)
2973 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2974 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2978 template<
typename ScalarType1,
typename ScalarType2>
2979 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2980 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2981 op_sub>
const & proxy)
2984 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2985 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
3009 template<
typename T,
typename LHS,
typename RHS,
typename OP>
3010 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const RHS, op_element_binary<OP> > >
3013 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3019 template<
typename LHS2,
typename RHS2,
typename OP2>
3020 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)
3022 vector<T> temp(proxy.rhs());
3027 template<
typename LHS1,
typename RHS1,
typename OP1>
3028 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)
3030 vector<T> temp(proxy.lhs());
3035 template<
typename LHS1,
typename RHS1,
typename OP1,
3036 typename LHS2,
typename RHS2,
typename OP2>
3037 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
3038 const vector_expression<const LHS2, const RHS2, OP2>,
3039 op_element_binary<OP> >
const & proxy)
3041 vector<T> temp1(proxy.lhs());
3042 vector<T> temp2(proxy.rhs());
3048 template<
typename T,
typename LHS,
typename RHS,
typename OP>
3049 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_element_binary<OP> > >
3052 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3059 template<
typename LHS2,
typename RHS2,
typename OP2>
3060 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)
3062 vector<T> temp(proxy.rhs());
3063 vector<T> temp2(temp.size());
3069 template<
typename LHS1,
typename RHS1,
typename OP1>
3070 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)
3072 vector<T> temp(proxy.lhs());
3073 vector<T> temp2(temp.size());
3079 template<
typename LHS1,
typename RHS1,
typename OP1,
3080 typename LHS2,
typename RHS2,
typename OP2>
3081 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
3082 const vector_expression<const LHS2, const RHS2, OP2>,
3083 op_element_binary<OP> >
const & proxy)
3085 vector<T> temp1(proxy.lhs());
3086 vector<T> temp2(proxy.rhs());
3087 vector<T> temp3(temp1.size());
3094 template<
typename T,
typename LHS,
typename RHS,
typename OP>
3095 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_element_binary<OP> > >
3099 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3106 template<
typename LHS2,
typename RHS2,
typename OP2>
3107 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)
3109 vector<T> temp(proxy.rhs());
3110 vector<T> temp2(temp.size());
3116 template<
typename LHS1,
typename RHS1,
typename OP1>
3117 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)
3119 vector<T> temp(proxy.lhs());
3120 vector<T> temp2(temp.size());
3126 template<
typename LHS1,
typename RHS1,
typename OP1,
3127 typename LHS2,
typename RHS2,
typename OP2>
3128 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
3129 const vector_expression<const LHS2, const RHS2, OP2>,
3130 op_element_binary<OP> >
const & proxy)
3132 vector<T> temp1(proxy.lhs());
3133 vector<T> temp2(proxy.rhs());
3134 vector<T> temp3(temp1.size());
3142 template<
typename T,
typename LHS,
typename RHS,
typename OP>
3143 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const RHS, op_element_unary<OP> > >
3146 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_unary<OP> >
const & proxy)
3152 template<
typename LHS2,
typename RHS2,
typename OP2>
3153 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS2, const RHS2, OP2>,
3154 const vector_expression<const LHS2, const RHS2, OP2>,
3155 op_element_unary<OP> >
const & proxy)
3157 vector<T> temp(proxy.rhs());
3162 template<
typename T,
typename LHS,
typename RHS,
typename OP>
3163 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_element_unary<OP> > >
3166 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_unary<OP> >
const & proxy)
3168 vector<T> temp(proxy);
3173 template<
typename LHS2,
typename RHS2,
typename OP2>
3174 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS2, const RHS2, OP2>,
3175 const vector_expression<const LHS2, const RHS2, OP2>,
3176 op_element_unary<OP> >
const & proxy)
3178 vector<T> temp(proxy.rhs());
3184 template<
typename T,
typename LHS,
typename RHS,
typename OP>
3185 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_element_unary<OP> > >
3188 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_unary<OP> >
const & proxy)
3190 vector<T> temp(proxy);
3195 template<
typename LHS2,
typename RHS2,
typename OP2>
3196 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS2, const RHS2, OP2>,
3197 const vector_expression<const LHS2, const RHS2, OP2>,
3198 op_element_unary<OP> >
const & proxy)
3200 vector<T> temp(proxy.rhs());
DistanceT difference_type
Simple enable-if variant that uses the SFINAE pattern.
self_type operator++(int)
const_vector_iterator(vector_base< NumericT > const &vec, size_type index, size_type start=0, size_type stride=1)
Constructor.
A tag class representing multiplication by a scalar.
vcl_size_t const_size() const
A STL-type const-iterator for vector elements. Elements can be accessed, but cannot be manipulated...
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!
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'.
vector_base()
Default constructor in order to be compatible with various containers.
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
vector_expression< const self_type, const NumericT, op_mult > operator*(char value) const
Scales the vector by a char (8-bit integer) 'alpha' and returns an expression template.
VectorType & at(vcl_size_t i) const
Worker class for decomposing expression templates.
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
vector< NumericT, AlignmentV > & fast_swap(vector< NumericT, AlignmentV > &v1, vector< NumericT, AlignmentV > &v2)
Swaps the content of two vectors by swapping OpenCL handles only, NO data is copied.
Defines the worker class for decomposing an expression tree into small chunks, which can be processed...
Implementations of vector operations.
size_type stride() const
Index increment in the underlying buffer when incrementing the iterator to the next element...
vector_tuple(VectorType const &v0, VectorType const &v1, VectorType const &v2, VectorType const &v3)
base_type::difference_type difference_type
Helper struct for checking whether a type represents a sign flip on a viennacl::scalar<> ...
void switch_memory_context(viennacl::context new_ctx)
base_type::size_type size_type
entry_proxy< NumericT > operator[](size_type index)
Read-write access to a single element of the vector.
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
self_type & swap(self_type &other)
Swaps the entries of the two vectors.
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
A tag class representing subtraction.
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)
difference_type operator-(self_type const &other) const
Expression template class for representing a tree of expressions which ultimately result in a matrix...
void pad()
Pads vectors with alignment > 1 with trailing zeros if the internal size is larger than the visible s...
difference_type operator-(self_type const &other) const
result_of::size_type< viennacl::vector_base< T > >::type stride(viennacl::vector_base< T > const &s)
void clear(VectorType &vec)
Generic routine for setting all entries of a vector to zero. This is the version for non-ViennaCL obj...
vector_tuple(std::vector< VectorType const * > const &vecs)
This file provides the forward declarations for the main types used within ViennaCL.
vector_tuple(VectorType &v0, VectorType &v1, VectorType &v2)
A tag class representing division.
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.
vector_expression< const self_type, const NumericT, op_div > operator/(char value) const
Scales the vector by a char (8-bit integer) 'alpha' and returns an expression template.
viennacl::enable_if< viennacl::is_scalar< S1 >::value, matrix_base< NumericT > & >::type operator/=(matrix_base< NumericT > &m1, S1 const &gpu_val)
Scales a matrix by a GPU scalar value.
viennacl::enable_if< viennacl::is_any_scalar< S1 >::value, matrix_expression< const matrix_base< NumericT >, const S1, op_mult >>::type operator*(S1 const &value, matrix_base< NumericT > const &m1)
Operator overload for the expression alpha * m1, where alpha is a host scalar (float or double) and m...
viennacl::scalar< float > s1
vcl_size_t internal_size(vector_base< NumericT > const &vec)
Helper routine for obtaining the buffer length of a ViennaCL vector.
self_type & operator-=(const self_type &vec)
lhs_reference_type lhs() const
Get left hand side operand.
An expression template class that represents a binary operation that yields a vector.
void element_op(matrix_base< T > &A, matrix_expression< const matrix_base< T >, const matrix_base< T >, OP > const &proxy)
Implementation of the element-wise operation A = B .* C and A = B ./ C for matrices (using MATLAB syn...
void resize(size_type new_size, viennacl::context ctx, bool preserve=true)
bool op_aliasing(vector_base< NumericT > const &, B const &)
void resize(size_type new_size, bool preserve=true)
Resizes the allocated memory for the vector. Pads the memory to be a multiple of 'AlignmentV'.
base_type::difference_type difference_type
self_type & operator+=(const self_type &vec)
viennacl::vector< NumericT > operator-(const vector_base< NumericT > &v1, const vector_expression< const matrix_base< NumericT >, const vector_base< NumericT >, op_prod > &proxy)
Implementation of the operation 'result = v1 - A * v2', where A is a matrix.
void swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
handle_type const & handle() const
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)
base_type::handle_type handle_type
vector_expression< const self_type, const NumericT, op_mult > operator-() const
Sign flip for the vector. Emulated to be equivalent to -1.0 * vector.
entry_proxy< NumericT > operator()(size_type index)
Read-write access to a single element of the vector.
vector_tuple(VectorType const &v0, VectorType const &v1)
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
self_type operator+(difference_type diff) const
viennacl::context context() const
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
base_type::size_type size_type
viennacl::vector< float > v1
viennacl::enable_if< viennacl::is_scalar< S1 >::value, matrix_base< NumericT > & >::type operator*=(matrix_base< NumericT > &m1, S1 const &gpu_val)
Scales a matrix by a GPU scalar value.
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
vector(unit_vector< NumericT > const &v)
Creates the vector from the supplied unit vector.
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.
iterator begin()
Returns an iterator pointing to the beginning of the vector (STL like)
Tuple class holding pointers to multiple vectors. Mainly used as a temporary object returned from vie...
vector()
Default constructor in order to be compatible with various containers.
vector(zero_vector< NumericT > const &v)
Creates the vector from the supplied zero vector.
A STL-type iterator for vector elements. Elements can be accessed and manipulated. VERY SLOW!!
result_of::size_type< T >::type start(T const &obj)
NumericT flip_sign(NumericT val)
void vector_swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
rhs_reference_type rhs() const
Get right hand side operand.
vector(size_type vec_size, viennacl::context ctx)
A tag class representing addition.
viennacl::backend::mem_handle handle_type
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.
bool operator!=(self_type const &other) const
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...
vector(const base_type &v)
vector_tuple< ScalarT > tie(vector_base< ScalarT > const &v0, vector_base< ScalarT > const &v1)
vcl_ptrdiff_t difference_type
viennacl::memory_types active_handle_id(T const &obj)
Returns an ID for the currently active memory domain of an object.
scalar< NumericT > value_type
vector(const self_type &v)
vector(scalar_vector< NumericT > const &v)
Creates the vector from the supplied scalar vector.
T::ERROR_CANNOT_DEDUCE_CPU_SCALAR_TYPE_FOR_T type
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)
vector_tuple(VectorType const &v0, VectorType const &v1, VectorType const &v2)
void resize(size_type new_size, bool preserve=true)
Resizes the allocated memory for the vector. Pads the memory to be a multiple of 'AlignmentV'.
self_type & fast_swap(self_type &other)
Swaps the handles of two vectors by swapping the OpenCL handles only, no data copy.
size_type offset() const
Offset of the current element index with respect to the beginning of the buffer.
viennacl::vector< NumericT > operator+(const vector_base< NumericT > &v1, const vector_expression< const matrix_base< NumericT >, const vector_base< NumericT >, op_prod > &proxy)
Implementation of the operation 'result = v1 + A * v2', where A is a matrix.
bool operator==(self_type const &other) const
vector_iterator(vector_base< NumericT > &vec, size_type index, size_type start=0, size_type stride=1)
Constructor.
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...
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...
A tag class representing matrix-vector products and element-wise multiplications. ...
void clear()
Resets all entries to zero. Does not change the size of the vector.
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
self_type & operator/=(char val)
Scales a vector (or proxy) by a char (8-bit integer)
Represents a vector consisting of 1 at a given index and zeros otherwise.
viennacl::vector< int > v2
size_type size() const
Returns the size of the result vector.
Represents a vector consisting of scalars 's' only, i.e. v[i] = s for all i. To be used as an initial...
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
vector(NumericT *ptr_to_mem, viennacl::memory_types mem_type, size_type vec_size, size_type start=0, size_type stride=1)
vector(size_type vec_size)
An explicit constructor for the vector, allocating the given amount of memory (plus a padding specifi...
size_type size() const
Returns the length of the vector (cf. std::vector)
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)
void copy(vector< NumericT, AlignmentV_SRC > const &gpu_src_vec, vector< NumericT, AlignmentV_DEST > &gpu_dest_vec)
Transfer from a ViennaCL vector to another ViennaCL vector. Convenience wrapper for viennacl::linalg:...
void switch_memory_context(viennacl::context new_ctx)
vector_tuple(VectorType &v0, VectorType &v1)
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
VectorType const & const_at(vcl_size_t i) const
A tag class representing transposed matrices.
vcl_size_t raw_size() const
Returns the number of bytes of the currently active buffer.
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...
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)
Forward declarations of the implicit_vector_base, vector_base class.
self_type & operator=(T const &other)
vcl_size_t size_type
Extracts the vector type from the two operands.
vector_iterator(handle_type &elements, size_type index, size_type start=0, size_type stride=1)
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
void prod_impl(const matrix_base< NumericT > &mat, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
size_type internal_size() const
Returns the internal length of the vector, which is given by size() plus the extra memory due to padd...
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
iterator end()
Returns an iterator pointing to the end of the vector (STL like)
const_vector_iterator(handle_type const &elements, size_type index, size_type start=0, size_type stride=1)
Constructor for vector-like treatment of arbitrary buffers.
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
self_type operator++(void)
ScalarType diff(ScalarType &s1, viennacl::scalar< ScalarType > &s2)
entry_proxy< NumericT > operator*(void)
void async_copy(const const_vector_iterator< NumericT, AlignmentV > &gpu_begin, const const_vector_iterator< NumericT, AlignmentV > &gpu_end, CPU_ITERATOR cpu_begin)
Asynchronous version of fast_copy(), copying data from device to host. The host iterator cpu_begin ne...
Implementation of the ViennaCL scalar class.
A collection of compile time type deductions.
self_type & operator*=(char val)
Scales a vector (or proxy) by a char (8-bit integer)
const handle_type & handle() const
Returns the memory handle.
handle_type const & elements_
The index of the entry the iterator is currently pointing to.
vector_tuple(VectorType &v0, VectorType &v1, VectorType &v2, VectorType &v3)
Main interface routines for memory management.
self_type & fast_swap(self_type &other)
Swaps the handles of two vectors by swapping the OpenCL handles only, no data copy.
self_type operator+(difference_type diff) const
ram_handle_type & ram_handle()
Returns the handle to a buffer in CPU RAM. NULL is returned if no such buffer has been allocated...
vector_tuple(std::vector< VectorType * > const &vecs)
handle_type const & handle() const
std::ptrdiff_t vcl_ptrdiff_t
vector(vector_expression< const LHS, const RHS, OP > const &proxy)
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...
void fast_copy(const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_begin, const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_end, CPU_ITERATOR cpu_begin)