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>
217 size_type
stride = 1) : base_type(elements, index,
start,
stride), elements_(elements) {}
238 handle_type &
handle() {
return elements_; }
246 handle_type elements_;
250 template<
class NumericT,
typename SizeT,
typename DistanceT>
253 template<
class NumericT,
typename SizeT,
typename DistanceT>
256 : size_(vec_size), start_(vec_start), stride_(vec_stride), internal_size_(vec_size), elements_(h) {}
258 template<
class NumericT,
typename SizeT,
typename DistanceT>
270 template<
class NumericT,
typename SizeT,
typename DistanceT>
272 : size_(vec_size), start_(start), stride_(stride), internal_size_(vec_size)
276 #ifdef VIENNACL_WITH_CUDA
278 elements_.cuda_handle().reset(reinterpret_cast<char*>(ptr_to_mem));
279 elements_.cuda_handle().inc();
295 #ifdef VIENNACL_WITH_OPENCL
296 template<
class NumericT,
typename SizeT,
typename DistanceT>
298 : size_(vec_size), start_(start), stride_(stride), internal_size_(vec_size)
301 elements_.opencl_handle() = existing_mem;
302 elements_.opencl_handle().inc();
303 elements_.opencl_handle().context(ctx.opencl_context());
309 template<
class NumericT,
typename SizeT,
typename DistanceT>
310 template<
typename LHS,
typename RHS,
typename OP>
323 template<
class NumericT,
typename SizeT,
typename DistanceT>
325 size_(other.size_), start_(0), stride_(1),
338 template<
typename NumericT,
typename SizeT,
typename DistanceT>
339 template<
typename OtherNumericT>
341 size_(other.
size()), start_(0), stride_(1),
355 template<
class NumericT,
typename SizeT,
typename DistanceT>
359 && bool(
"Incompatible vector sizes!"));
369 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_, dense_padding_size);
387 template<
class NumericT,
typename SizeT,
typename DistanceT>
388 template<
typename LHS,
typename RHS,
typename OP>
392 &&
bool(
"Incompatible vector sizes!"));
398 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_, dense_padding_size);
409 template<
class NumericT,
typename SizeT,
typename DistanceT>
410 template<
typename OtherNumericT>
414 && bool(
"Incompatible vector sizes!"));
421 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_, dense_padding_size);
433 template<
class NumericT,
typename SizeT,
typename DistanceT>
437 && bool(
"Incompatible vector sizes!"));
442 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_, dense_padding_size);
459 template<
class NumericT,
typename SizeT,
typename DistanceT>
463 && bool(
"Incompatible vector sizes!"));
468 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_, dense_padding_size);
482 template<
class NumericT,
typename SizeT,
typename DistanceT>
486 && bool(
"Incompatible vector sizes!"));
491 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_, dense_padding_size);
513 template<
class NumericT,
typename SizeT,
typename DistanceT>
534 template<
class NumericT,
typename SizeT,
typename DistanceT>
561 template<
class NumericT,
typename SizeT,
typename DistanceT>
564 assert( (
size() > 0) &&
bool(
"Cannot apply operator() to vector of size zero!"));
565 assert( index <
size() &&
bool(
"Index out of bounds!") );
570 template<
class NumericT,
typename SizeT,
typename DistanceT>
573 assert( (
size() > 0) &&
bool(
"Cannot apply operator() to vector of size zero!"));
574 assert( index <
size() &&
bool(
"Index out of bounds!") );
579 template<
class NumericT,
typename SizeT,
typename DistanceT>
582 assert( (
size() > 0) &&
bool(
"Cannot apply operator() to vector of size zero!"));
583 assert( index <
size() &&
bool(
"Index out of bounds!") );
588 template<
class NumericT,
typename SizeT,
typename DistanceT>
591 assert( (
size() > 0) &&
bool(
"Cannot apply operator() to vector of size zero!"));
592 assert( index <
size() &&
bool(
"Index out of bounds!") );
603 template<
class NumericT,
typename SizeT,
typename DistanceT>
606 assert(vec.
size() ==
size() && bool(
"Incompatible vector sizes!"));
610 *
this,
NumericT(1.0), 1,
false,
false,
611 vec,
NumericT(1.0), 1,
false,
false);
615 template<
class NumericT,
typename SizeT,
typename DistanceT>
618 assert(vec.
size() ==
size() && bool(
"Incompatible vector sizes!"));
622 *
this,
NumericT(1.0), 1,
false,
false,
623 vec,
NumericT(-1.0), 1,
false,
false);
628 template<
class NumericT,
typename SizeT,
typename DistanceT>
633 *
this,
NumericT(val), 1,
false,
false);
637 template<
class NumericT,
typename SizeT,
typename DistanceT>
642 *
this,
NumericT(val), 1,
false,
false);
646 template<
class NumericT,
typename SizeT,
typename DistanceT>
651 *
this,
NumericT(val), 1,
false,
false);
655 template<
class NumericT,
typename SizeT,
typename DistanceT>
660 *
this,
NumericT(val), 1,
false,
false);
664 template<
class NumericT,
typename SizeT,
typename DistanceT>
669 *
this,
NumericT(val), 1,
false,
false);
673 template<
class NumericT,
typename SizeT,
typename DistanceT>
678 *
this,
NumericT(val), 1,
false,
false);
684 template<
class NumericT,
typename SizeT,
typename DistanceT>
689 *
this,
NumericT(val), 1,
true,
false);
693 template<
class NumericT,
typename SizeT,
typename DistanceT>
698 *
this,
NumericT(val), 1,
true,
false);
702 template<
class NumericT,
typename SizeT,
typename DistanceT>
707 *
this,
NumericT(val), 1,
true,
false);
711 template<
class NumericT,
typename SizeT,
typename DistanceT>
716 *
this,
NumericT(val), 1,
true,
false);
720 template<
class NumericT,
typename SizeT,
typename DistanceT>
725 *
this,
NumericT(val), 1,
true,
false);
729 template<
class NumericT,
typename SizeT,
typename DistanceT>
734 *
this,
NumericT(val), 1,
true,
false);
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>
768 template<
class NumericT,
typename SizeT,
typename DistanceT>
775 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>
812 template<
class NumericT,
typename SizeT,
typename DistanceT>
819 template<
class NumericT,
typename SizeT,
typename DistanceT>
828 template<
class NumericT,
typename SizeT,
typename DistanceT>
840 template<
class NumericT,
typename SizeT,
typename DistanceT>
843 return iterator(*
this, 0, start_, stride_);
847 template<
class NumericT,
typename SizeT,
typename DistanceT>
854 template<
class NumericT,
typename SizeT,
typename DistanceT>
860 template<
class NumericT,
typename SizeT,
typename DistanceT>
866 template<
class NumericT,
typename SizeT,
typename DistanceT>
874 template<
class NumericT,
typename SizeT,
typename DistanceT>
880 template<
class NumericT,
typename SizeT,
typename DistanceT>
883 assert(this->size_ == other.size_ &&
bool(
"Vector size mismatch"));
884 this->elements_.swap(other.elements_);
888 template<
class NumericT,
typename SizeT,
typename DistanceT>
898 template<
class NumericT,
typename SizeT,
typename DistanceT>
901 viennacl::backend::switch_memory_context<NumericT>(elements_, new_ctx);
908 template<
class NumericT,
typename SizeT,
typename DistanceT>
914 template<
class NumericT,
typename SizeT,
typename DistanceT>
917 resize_impl(new_size, ctx, preserve);
920 template<
class NumericT,
typename SizeT,
typename DistanceT>
923 assert(new_size > 0 &&
bool(
"Positive size required when resizing vector!"));
925 if (new_size != size_)
927 vcl_size_t new_internal_size = viennacl::tools::align_to_multiple<vcl_size_t>(new_size, dense_padding_size);
929 std::vector<NumericT> temp(size_);
930 if (preserve && size_ > 0)
932 temp.resize(new_size);
933 temp.resize(new_internal_size);
942 internal_size_ = viennacl::tools::align_to_multiple<size_type>(size_, dense_padding_size);
949 template<
class NumericT,
unsigned int AlignmentV>
950 class vector :
public vector_base<NumericT>
952 typedef vector<NumericT, AlignmentV> self_type;
953 typedef vector_base<NumericT> base_type;
967 explicit vector(size_type vec_size) : base_type(vec_size) {}
972 : base_type(ptr_to_mem, mem_type, vec_size, start, stride) {}
974 #ifdef VIENNACL_WITH_OPENCL
983 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) {}
993 template<
typename LHS,
typename RHS,
typename OP>
999 base_type::operator=(v);
1005 base_type::operator=(v);
1030 template<
typename T>
1037 using base_type::operator+=;
1038 using base_type::operator-=;
1046 void resize(size_type new_size,
bool preserve =
true)
1072 template<
typename ScalarT>
1075 typedef vector_base<ScalarT> VectorType;
1080 vector_tuple(VectorType
const & v0, VectorType
const &
v1) : const_vectors_(2), non_const_vectors_()
1082 const_vectors_[0] = &v0;
1083 const_vectors_[1] = &
v1;
1085 vector_tuple(VectorType & v0, VectorType &
v1) : const_vectors_(2), non_const_vectors_(2)
1087 const_vectors_[0] = &v0; non_const_vectors_[0] = &v0;
1088 const_vectors_[1] = &
v1; non_const_vectors_[1] = &
v1;
1093 vector_tuple(VectorType
const & v0, VectorType
const &
v1, VectorType
const &
v2) : const_vectors_(3), non_const_vectors_()
1095 const_vectors_[0] = &v0;
1096 const_vectors_[1] = &
v1;
1097 const_vectors_[2] = &
v2;
1099 vector_tuple(VectorType & v0, VectorType &
v1, VectorType &
v2) : const_vectors_(3), non_const_vectors_(3)
1101 const_vectors_[0] = &v0; non_const_vectors_[0] = &v0;
1102 const_vectors_[1] = &
v1; non_const_vectors_[1] = &
v1;
1103 const_vectors_[2] = &
v2; non_const_vectors_[2] = &
v2;
1108 vector_tuple(VectorType
const & v0, VectorType
const &
v1, VectorType
const &
v2, VectorType
const & v3) : const_vectors_(4), non_const_vectors_()
1110 const_vectors_[0] = &v0;
1111 const_vectors_[1] = &
v1;
1112 const_vectors_[2] = &
v2;
1113 const_vectors_[3] = &v3;
1115 vector_tuple(VectorType & v0, VectorType &
v1, VectorType &
v2, VectorType & v3) : const_vectors_(4), non_const_vectors_(4)
1117 const_vectors_[0] = &v0; non_const_vectors_[0] = &v0;
1118 const_vectors_[1] = &
v1; non_const_vectors_[1] = &
v1;
1119 const_vectors_[2] = &
v2; non_const_vectors_[2] = &
v2;
1120 const_vectors_[3] = &v3; non_const_vectors_[3] = &v3;
1127 vector_tuple(std::vector<VectorType const *>
const & vecs) : const_vectors_(vecs.
size()), non_const_vectors_()
1130 const_vectors_[i] = vecs[i];
1133 vector_tuple(std::vector<VectorType *>
const & vecs) : const_vectors_(vecs.
size()), non_const_vectors_(vecs.
size())
1137 const_vectors_[i] = vecs[i];
1138 non_const_vectors_[i] = vecs[i];
1145 VectorType &
at(
vcl_size_t i)
const {
return *(non_const_vectors_.at(i)); }
1149 std::vector<VectorType const *> const_vectors_;
1150 std::vector<VectorType *> non_const_vectors_;
1154 template<
typename ScalarT>
1157 template<
typename ScalarT>
1161 template<
typename ScalarT>
1164 template<
typename ScalarT>
1168 template<
typename ScalarT>
1174 template<
typename ScalarT>
1181 template<
typename ScalarT>
1189 std::vector<VectorPointerType> vec(5);
1198 template<
typename ScalarT>
1206 std::vector<VectorPointerType> vec(5);
1233 template<
typename NumericT,
unsigned int AlignmentV,
typename CPU_ITERATOR>
1236 CPU_ITERATOR cpu_begin )
1238 if (gpu_begin != gpu_end)
1240 if (gpu_begin.stride() == 1)
1243 sizeof(
NumericT)*gpu_begin.offset(),
1250 std::vector<NumericT> temp_buffer(gpu_begin.stride() * gpu_size);
1255 (&(*cpu_begin))[i] = temp_buffer[i * gpu_begin.stride()];
1266 template<
typename NumericT,
typename CPUVECTOR>
1283 template<
typename NumericT,
unsigned int AlignmentV,
typename CPU_ITERATOR>
1286 CPU_ITERATOR cpu_begin )
1288 if (gpu_begin != gpu_end)
1290 if (gpu_begin.stride() == 1)
1293 sizeof(
NumericT)*gpu_begin.offset(),
1299 fast_copy(gpu_begin, gpu_end, cpu_begin);
1308 template<
typename NumericT,
typename CPUVECTOR>
1321 template<
typename NumericT,
unsigned int AlignmentV,
typename CPU_ITERATOR>
1324 CPU_ITERATOR cpu_begin )
1326 assert(gpu_end - gpu_begin >= 0 &&
bool(
"Iterators incompatible"));
1327 if (gpu_end - gpu_begin != 0)
1329 std::vector<NumericT> temp_buffer(static_cast<vcl_size_t>(gpu_end - gpu_begin));
1330 fast_copy(gpu_begin, gpu_end, temp_buffer.begin());
1333 std::copy(temp_buffer.begin(), temp_buffer.end(), cpu_begin);
1343 template<
typename NumericT,
unsigned int AlignmentV,
typename CPU_ITERATOR>
1346 CPU_ITERATOR cpu_begin )
1359 template<
typename NumericT,
typename CPUVECTOR>
1367 #ifdef VIENNACL_WITH_EIGEN
1368 template<
typename NumericT,
unsigned int AlignmentV>
1369 void copy(vector<NumericT, AlignmentV>
const & gpu_vec,
1370 Eigen::Matrix<NumericT, Eigen::Dynamic, 1> & eigen_vec)
1375 template<
typename NumericT,
unsigned int AlignmentV,
int EigenMapTypeV,
typename EigenStr
ideT>
1376 void copy(vector<NumericT, AlignmentV>
const & gpu_vec,
1377 Eigen::Map<Eigen::Matrix<NumericT, Eigen::Dynamic, 1>, EigenMapTypeV, EigenStrideT> & eigen_vec)
1399 template<
typename CPU_ITERATOR,
typename NumericT,
unsigned int AlignmentV>
1401 CPU_ITERATOR
const & cpu_end,
1404 if (cpu_end - cpu_begin > 0)
1406 if (gpu_begin.
stride() == 1)
1415 std::vector<NumericT> temp_buffer(gpu_begin.
stride() * cpu_size);
1420 temp_buffer[i * gpu_begin.
stride()] = (&(*cpu_begin))[i];
1433 template<
typename CPUVECTOR,
typename NumericT>
1449 template<
typename CPU_ITERATOR,
typename NumericT,
unsigned int AlignmentV>
1451 CPU_ITERATOR
const & cpu_end,
1454 if (cpu_end - cpu_begin > 0)
1456 if (gpu_begin.
stride() == 1)
1464 fast_copy(cpu_begin, cpu_end, gpu_begin);
1474 template<
typename CPUVECTOR,
typename NumericT>
1487 template<
typename NumericT,
unsigned int AlignmentV,
typename CPU_ITERATOR>
1488 void copy(CPU_ITERATOR
const & cpu_begin,
1489 CPU_ITERATOR
const & cpu_end,
1492 assert(cpu_end - cpu_begin > 0 &&
bool(
"Iterators incompatible"));
1493 if (cpu_begin != cpu_end)
1496 std::vector<NumericT> temp_buffer(static_cast<vcl_size_t>(cpu_end - cpu_begin));
1497 std::copy(cpu_begin, cpu_end, temp_buffer.begin());
1509 template<
typename HostVectorT,
typename T>
1520 template<
typename HostVectorT,
typename T,
unsigned int AlignmentV>
1523 if (gpu_vec.size() == 0)
1524 gpu_vec.resize(static_cast<vcl_size_t>(cpu_vec.end() - cpu_vec.begin()));
1529 #ifdef VIENNACL_WITH_EIGEN
1530 template<
typename NumericT,
unsigned int AlignmentV>
1531 void copy(Eigen::Matrix<NumericT, Eigen::Dynamic, 1>
const & eigen_vec,
1532 vector<NumericT, AlignmentV> & gpu_vec)
1534 viennacl::fast_copy(eigen_vec.data(), eigen_vec.data() + eigen_vec.size(), gpu_vec.begin());
1537 template<
typename NumericT,
int EigenMapTypeV,
typename EigenStr
ideT,
unsigned int AlignmentV>
1538 void copy(Eigen::Map<Eigen::Matrix<NumericT, Eigen::Dynamic, 1>, EigenMapTypeV, EigenStrideT>
const & eigen_vec,
1539 vector<NumericT, AlignmentV> & gpu_vec)
1541 viennacl::fast_copy(eigen_vec.data(), eigen_vec.data() + eigen_vec.size(), gpu_vec.begin());
1556 template<
typename NumericT,
unsigned int AlignmentV_SRC,
unsigned int AlignmentV_DEST>
1561 assert(gpu_src_end - gpu_src_begin >= 0);
1562 assert(gpu_src_begin.stride() == 1 && bool(
"ViennaCL ERROR: copy() for GPU->GPU not implemented for slices! Use operator= instead for the moment."));
1564 if (gpu_src_begin.stride() == 1 && gpu_dest_begin.
stride() == 1)
1566 if (gpu_src_begin != gpu_src_end)
1568 sizeof(
NumericT) * gpu_src_begin.offset(),
1570 sizeof(
NumericT) * (gpu_src_end.offset() - gpu_src_begin.offset()));
1574 assert(
false &&
bool(
"not implemented yet"));
1584 template<
typename NumericT,
unsigned int AlignmentV_SRC,
unsigned int AlignmentV_DEST>
1599 template<
typename NumericT,
unsigned int AlignmentV_SRC,
unsigned int AlignmentV_DEST>
1603 viennacl::copy(gpu_src_vec.begin(), gpu_src_vec.end(), gpu_dest_vec.begin());
1616 template<
typename T>
1617 std::ostream & operator<<(std::ostream & os, vector_base<T>
const & val)
1619 std::vector<T> tmp(val.size());
1621 os <<
"[" << val.size() <<
"](";
1622 for (
typename std::vector<T>::size_type i=0; i<val.size(); ++i)
1632 template<
typename LHS,
typename RHS,
typename OP>
1633 std::ostream & operator<<(std::ostream & os, vector_expression<LHS, RHS, OP>
const & proxy)
1647 template<
typename T>
1658 template<
typename NumericT,
unsigned int AlignmentV>
1662 return v1.fast_swap(v2);
1682 template<
typename T,
typename S1>
1691 v1, gpu_val, 1,
false, flip_sign);
1703 template<
typename T,
typename S1>
1712 v1, gpu_val, 1,
true, flip_sign);
1727 template<
typename LHS1,
typename RHS1,
typename OP1,
1728 typename LHS2,
typename RHS2,
typename OP2>
1729 vector_expression< const vector_expression< LHS1, RHS1, OP1>,
1730 const vector_expression< LHS2, RHS2, OP2>,
1735 assert(proxy1.size() == proxy2.size() && bool(
"Incompatible vector sizes!"));
1746 template<
typename LHS,
typename RHS,
typename OP,
typename T>
1747 vector_expression< const vector_expression<LHS, RHS, OP>,
1748 const vector_base<T>,
1751 vector_base<T>
const & vec)
1753 assert(proxy.size() == vec.
size() && bool(
"Incompatible vector sizes!"));
1755 const vector_base<T>,
1764 template<
typename T,
typename LHS,
typename RHS,
typename OP>
1765 vector_expression< const vector_base<T>,
1766 const vector_expression<LHS, RHS, OP>,
1769 vector_expression<LHS, RHS, OP>
const & proxy)
1771 assert(proxy.size() == vec.
size() && bool(
"Incompatible vector sizes!"));
1773 const vector_expression<LHS, RHS, OP>,
1779 template<
typename T>
1780 vector_expression< const vector_base<T>,
const vector_base<T>, op_add>
1797 template<
typename LHS1,
typename RHS1,
typename OP1,
1798 typename LHS2,
typename RHS2,
typename OP2>
1799 vector_expression< const vector_expression< LHS1, RHS1, OP1>,
1800 const vector_expression< LHS2, RHS2, OP2>,
1805 assert(proxy1.size() == proxy2.size() && bool(
"Incompatible vector sizes!"));
1817 template<
typename LHS,
typename RHS,
typename OP,
typename T>
1818 vector_expression< const vector_expression<LHS, RHS, OP>,
1819 const vector_base<T>,
1822 vector_base<T>
const & vec)
1824 assert(proxy.size() == vec.
size() && bool(
"Incompatible vector sizes!"));
1826 const vector_base<T>,
1835 template<
typename T,
typename LHS,
typename RHS,
typename OP>
1836 vector_expression< const vector_base<T>,
1837 const vector_expression<LHS, RHS, OP>,
1840 vector_expression<LHS, RHS, OP>
const & proxy)
1842 assert(proxy.size() == vec.
size() && bool(
"Incompatible vector sizes!"));
1844 const vector_expression<LHS, RHS, OP>,
1850 template<
typename T>
1851 vector_expression< const vector_base<T>,
const vector_base<T>, op_sub>
1868 template<
typename S1,
typename T>
1870 vector_expression< const vector_base<T>,
const S1, op_mult> >::type
1873 return vector_expression< const vector_base<T>,
const S1,
op_mult>(vec, value);
1881 template<
typename T>
1882 vector_expression< const vector_base<T>,
const T, op_mult>
1885 return vector_expression< const vector_base<T>,
const T,
op_mult>(vec, T(value));
1893 template<
typename T>
1894 vector_expression< const vector_base<T>,
const T, op_mult>
1897 return vector_expression< const vector_base<T>,
const T,
op_mult>(vec, T(value));
1905 template<
typename T>
1906 vector_expression< const vector_base<T>,
const T, op_mult>
1909 return vector_expression< const vector_base<T>,
const T,
op_mult>(vec, T(value));
1917 template<
typename T>
1918 vector_expression< const vector_base<T>,
const T, op_mult>
1921 return vector_expression< const vector_base<T>,
const T,
op_mult>(vec, T(value));
1929 template<
typename T>
1930 vector_expression< const vector_base<T>,
const T, op_mult>
1933 return vector_expression< const vector_base<T>,
const T,
op_mult>(vec, T(value));
1941 template<
typename T>
1942 vector_expression< const vector_base<T>,
const T, op_mult>
1945 return vector_expression< const vector_base<T>,
const T,
op_mult>(vec, T(value));
1955 template<
typename LHS,
typename RHS,
typename OP,
typename T>
1956 vector_expression< const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
1957 operator * (scalar_expression<LHS, RHS, OP>
const & expr, vector_base<T>
const & vec)
1959 return vector_expression< const vector_base<T>,
const scalar_expression<LHS, RHS, OP>,
op_mult>(vec, expr);
1964 template<
typename T,
typename S1>
1966 vector_expression< const vector_base<T>,
const S1, op_mult> >::type
1969 return vector_expression< const vector_base<T>,
const S1,
op_mult>(vec, value);
1972 template<
typename T>
1973 vector_expression< const vector_base<T>,
const T, op_mult>
1976 return vector_expression< const vector_base<T>,
const T,
op_mult>(vec, value);
1984 template<
typename LHS,
typename RHS,
typename OP,
typename S1>
1990 return viennacl::vector_expression<const vector_expression<LHS, RHS, OP>,
const S1,
op_mult>(proxy, val);
1998 template<
typename S1,
typename LHS,
typename RHS,
typename OP>
2000 viennacl::vector_expression<const vector_expression<LHS, RHS, OP>,
const S1, op_mult> >::type
2002 vector_expression<LHS, RHS, OP>
const & proxy)
2004 return viennacl::vector_expression<const vector_expression<LHS, RHS, OP>,
const S1,
op_mult>(proxy, val);
2016 template<
typename S1,
typename LHS,
typename RHS,
typename OP>
2018 viennacl::vector_expression<const vector_expression<LHS, RHS, OP>,
const S1, op_div> >::type
2022 return viennacl::vector_expression<const vector_expression<LHS, RHS, OP>,
const S1,
op_div>(proxy, val);
2028 template<
typename T,
typename S1>
2030 vector_expression< const vector_base<T>,
const S1, op_div> >::type
2049 template<
typename T>
2050 struct op_executor<vector_base<T>,
op_assign, vector_base<T> >
2052 static void apply(vector_base<T> & lhs, vector_base<T>
const & rhs)
2059 template<
typename T>
2060 struct op_executor<vector_base<T>,
op_assign, vector_expression<const vector_base<T>, const vector_tuple<T>, op_inner_prod> >
2062 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_tuple<T>, op_inner_prod>
const & rhs)
2069 template<
typename T>
2070 struct op_executor<vector_base<T>, op_inplace_add, vector_base<T> >
2072 static void apply(vector_base<T> & lhs, vector_base<T>
const & rhs)
2074 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, rhs, T(1), 1,
false,
false);
2079 template<
typename T>
2080 struct op_executor<vector_base<T>, op_inplace_sub, vector_base<T> >
2082 static void apply(vector_base<T> & lhs, vector_base<T>
const & rhs)
2084 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, rhs, T(1), 1,
false,
true);
2092 template<
typename T,
typename ScalarType>
2093 struct op_executor<vector_base<T>,
op_assign, vector_expression<const vector_base<T>, const
ScalarType, op_mult> >
2096 template<
typename LHS,
typename RHS,
typename OP>
2097 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
const & proxy)
2099 T alpha = proxy.rhs();
2103 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar<T>, op_mult>
const & proxy)
2108 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const T, op_mult>
const & proxy)
2115 template<
typename T,
typename ScalarType>
2116 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_base<T>, const
ScalarType, op_mult> >
2119 template<
typename LHS,
typename RHS,
typename OP>
2120 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
const & proxy)
2122 T alpha = proxy.rhs();
2123 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), alpha, 1,
false,
false);
2126 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar<T>, op_mult>
const & proxy)
2128 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
false);
2131 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const T, op_mult>
const & proxy)
2133 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
false);
2138 template<
typename T,
typename ScalarType>
2139 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vector_base<T>, const
ScalarType, op_mult> >
2142 template<
typename LHS,
typename RHS,
typename OP>
2143 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar_expression<LHS, RHS, OP>, op_mult>
const & proxy)
2145 T alpha = proxy.rhs();
2146 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), alpha, 1,
false,
true);
2149 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const scalar<T>, op_mult>
const & proxy)
2151 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
true);
2154 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const T, op_mult>
const & proxy)
2156 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
false,
true);
2164 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2165 struct op_executor<vector_base<T>,
op_assign, vector_expression<const vector_expression<const LHS, const RHS, OP>, const
ScalarType, op_mult> >
2167 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_mult>
const & proxy)
2169 vector<T> temp(proxy.lhs());
2170 lhs = temp * proxy.rhs();
2175 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2176 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_expression<const LHS, const RHS, OP>, const
ScalarType, op_mult> >
2178 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_mult>
const & proxy)
2180 vector<T> temp(proxy.lhs());
2181 lhs += temp * proxy.rhs();
2186 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2187 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vector_expression<const LHS, const RHS, OP>, const
ScalarType, op_mult> >
2189 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_mult>
const & proxy)
2191 vector<T> temp(proxy.lhs());
2192 lhs -= temp * proxy.rhs();
2200 template<
typename T,
typename ScalarType>
2201 struct op_executor<vector_base<T>,
op_assign, vector_expression<const vector_base<T>, const
ScalarType, op_div> >
2203 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const ScalarType, op_div>
const & proxy)
2210 template<
typename T,
typename ScalarType>
2211 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_base<T>, const
ScalarType, op_div> >
2213 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const ScalarType, op_div>
const & proxy)
2215 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
true,
false);
2220 template<
typename T,
typename ScalarType>
2221 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vector_base<T>, const
ScalarType, op_div> >
2223 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const ScalarType, op_div>
const & proxy)
2225 viennacl::linalg::avbv(lhs, lhs, T(1), 1,
false,
false, proxy.lhs(), proxy.rhs(), 1,
true,
true);
2233 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2234 struct op_executor<vector_base<T>,
op_assign, vector_expression<const vector_expression<const LHS, const RHS, OP>, const
ScalarType, op_div> >
2236 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_div>
const & proxy)
2238 vector<T> temp(proxy.lhs());
2239 lhs = temp / proxy.rhs();
2244 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2245 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vector_expression<const LHS, const RHS, OP>, const
ScalarType, op_div> >
2247 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_div>
const & proxy)
2249 vector<T> temp(proxy.lhs());
2250 lhs += temp / proxy.rhs();
2255 template<
typename T,
typename LHS,
typename RHS,
typename OP,
typename ScalarType>
2256 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vector_expression<const LHS, const RHS, OP>, const
ScalarType, op_div> >
2258 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS, const RHS, OP>,
const ScalarType, op_div>
const & proxy)
2260 vector<T> temp(proxy.lhs());
2261 lhs -= temp / proxy.rhs();
2268 template<
typename T,
typename LHS,
typename RHS>
2269 struct op_executor<vector_base<T>,
op_assign, vector_expression<const LHS, const RHS, op_add> >
2272 template<
typename LHS1,
typename RHS1>
2273 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_add>
const & proxy)
2275 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2276 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2278 if (op_aliasing_lhs || op_aliasing_rhs)
2280 vector_base<T> temp(proxy.lhs());
2281 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2286 op_executor<vector_base<T>,
op_assign, LHS>::apply(lhs, proxy.lhs());
2287 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2292 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_add>
const & proxy)
2295 proxy.lhs(), T(1), 1,
false,
false,
2296 proxy.rhs(), T(1), 1,
false,
false);
2300 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_mult>,
2301 const vector_base<T>,
2302 op_add>
const & proxy)
2305 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2306 proxy.rhs(), T(1), 1,
false,
false);
2310 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_div>,
2311 const vector_base<T>,
2312 op_add>
const & proxy)
2315 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2316 proxy.rhs(), T(1), 1,
false,
false);
2320 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2321 const vector_expression<
const vector_base<T>,
const T, op_mult>,
2322 op_add>
const & proxy)
2325 proxy.lhs(), T(1), 1,
false,
false,
2326 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2330 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2331 const vector_expression<
const vector_base<T>,
const T, op_div>,
2332 op_add>
const & proxy)
2335 proxy.lhs(), T(1), 1,
false,
false,
2336 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2340 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_mult>,
2341 const vector_expression<
const vector_base<T>,
const T, op_mult>,
2342 op_add>
const & proxy)
2345 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2346 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2350 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_mult>,
2351 const vector_expression<
const vector_base<T>,
const T, op_div>,
2352 op_add>
const & proxy)
2355 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2356 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2360 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_div>,
2361 const vector_expression<
const vector_base<T>,
const T, op_mult>,
2362 op_add>
const & proxy)
2365 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2366 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2370 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const T, op_div>,
2371 const vector_expression<
const vector_base<T>,
const T, op_div>,
2372 op_add>
const & proxy)
2375 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2376 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2382 template<
typename T,
typename LHS,
typename RHS>
2383 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_add> >
2386 template<
typename LHS1,
typename RHS1>
2387 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_add>
const & proxy)
2389 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2390 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2392 if (op_aliasing_lhs || op_aliasing_rhs)
2394 vector_base<T> temp(proxy.lhs());
2395 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2400 op_executor<vector_base<T>, op_inplace_add, LHS>::apply(lhs, proxy.lhs());
2401 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2406 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_add>
const & proxy)
2409 proxy.lhs(), T(1), 1,
false,
false,
2410 proxy.rhs(), T(1), 1,
false,
false);
2414 template<
typename ScalarType>
2415 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2416 const vector_base<T>,
2417 op_add>
const & proxy)
2420 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2421 proxy.rhs(), T(1), 1,
false,
false);
2425 template<
typename ScalarType>
2426 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2427 const vector_base<T>,
2428 op_add>
const & proxy)
2431 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2432 proxy.rhs(), T(1), 1,
false,
false);
2436 template<
typename ScalarType>
2437 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2438 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2439 op_add>
const & proxy)
2442 proxy.lhs(), T(1), 1,
false,
false,
2443 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2447 template<
typename ScalarType>
2448 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2449 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2450 op_add>
const & proxy)
2453 proxy.lhs(), T(1), 1,
false,
false,
2454 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2458 template<
typename ScalarType1,
typename ScalarType2>
2459 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2460 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2461 op_add>
const & proxy)
2464 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2465 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2469 template<
typename ScalarType1,
typename ScalarType2>
2470 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2471 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2472 op_add>
const & proxy)
2475 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2476 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2480 template<
typename ScalarType1,
typename ScalarType2>
2481 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2482 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2483 op_add>
const & proxy)
2486 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2487 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2491 template<
typename ScalarType1,
typename ScalarType2>
2492 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2493 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2494 op_add>
const & proxy)
2497 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2498 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2505 template<
typename T,
typename LHS,
typename RHS>
2506 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_add> >
2509 template<
typename LHS1,
typename RHS1>
2510 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_add>
const & proxy)
2512 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2513 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2515 if (op_aliasing_lhs || op_aliasing_rhs)
2517 vector_base<T> temp(proxy.lhs());
2518 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(temp, proxy.rhs());
2523 op_executor<vector_base<T>, op_inplace_sub, LHS>::apply(lhs, proxy.lhs());
2524 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2529 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_add>
const & proxy)
2532 proxy.lhs(), T(1), 1,
false,
true,
2533 proxy.rhs(), T(1), 1,
false,
true);
2537 template<
typename ScalarType>
2538 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2539 const vector_base<T>,
2540 op_add>
const & proxy)
2543 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2544 proxy.rhs(), T(1), 1,
false,
true);
2548 template<
typename ScalarType>
2549 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2550 const vector_base<T>,
2551 op_add>
const & proxy)
2554 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2555 proxy.rhs(), T(1), 1,
false,
true);
2559 template<
typename ScalarType>
2560 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2561 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2562 op_add>
const & proxy)
2565 proxy.lhs(), T(1), 1,
false,
true,
2566 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2570 template<
typename ScalarType>
2571 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2572 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2573 op_add>
const & proxy)
2576 proxy.lhs(), T(1), 1,
false,
true,
2577 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2581 template<
typename ScalarType1,
typename ScalarType2>
2582 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2583 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2584 op_add>
const & proxy)
2587 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2588 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2592 template<
typename ScalarType1,
typename ScalarType2>
2593 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2594 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2595 op_add>
const & proxy)
2598 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2599 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2603 template<
typename ScalarType1,
typename ScalarType2>
2604 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2605 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2606 op_add>
const & proxy)
2609 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2610 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2614 template<
typename ScalarType1,
typename ScalarType2>
2615 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2616 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2617 op_add>
const & proxy)
2620 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2621 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2632 template<
typename T,
typename LHS,
typename RHS>
2633 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const RHS, op_sub> >
2636 template<
typename LHS1,
typename RHS1>
2637 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2639 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2640 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2642 if (op_aliasing_lhs || op_aliasing_rhs)
2644 vector_base<T> temp(proxy.lhs());
2645 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2650 op_executor<vector_base<T>, op_assign, LHS>::apply(lhs, proxy.lhs());
2651 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2656 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_sub>
const & proxy)
2659 proxy.lhs(), T(1), 1,
false,
false,
2660 proxy.rhs(), T(1), 1,
false,
true);
2664 template<
typename ScalarType>
2665 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2666 const vector_base<T>,
2667 op_sub>
const & proxy)
2670 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2671 proxy.rhs(), T(1), 1,
false,
true);
2675 template<
typename ScalarType>
2676 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2677 const vector_base<T>,
2678 op_sub>
const & proxy)
2681 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2682 proxy.rhs(), T(1), 1,
false,
true);
2686 template<
typename ScalarType>
2687 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2688 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2689 op_sub>
const & proxy)
2692 proxy.lhs(), T(1), 1,
false,
false,
2693 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2697 template<
typename ScalarType>
2698 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2699 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2700 op_sub>
const & proxy)
2703 proxy.lhs(), T(1), 1,
false,
false,
2704 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2708 template<
typename ScalarType1,
typename ScalarType2>
2709 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2710 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2711 op_sub>
const & proxy)
2714 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2715 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2719 template<
typename ScalarType1,
typename ScalarType2>
2720 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2721 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2722 op_sub>
const & proxy)
2725 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2726 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2730 template<
typename ScalarType1,
typename ScalarType2>
2731 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2732 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2733 op_sub>
const & proxy)
2736 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2737 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2741 template<
typename ScalarType1,
typename ScalarType2>
2742 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2743 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2744 op_sub>
const & proxy)
2747 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2748 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2754 template<
typename T,
typename LHS,
typename RHS>
2755 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_sub> >
2758 template<
typename LHS1,
typename RHS1>
2759 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2761 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2762 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2764 if (op_aliasing_lhs || op_aliasing_rhs)
2766 vector_base<T> temp(proxy.lhs());
2767 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2772 op_executor<vector_base<T>, op_inplace_add, LHS>::apply(lhs, proxy.lhs());
2773 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(lhs, proxy.rhs());
2778 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_sub>
const & proxy)
2781 proxy.lhs(), T(1), 1,
false,
false,
2782 proxy.rhs(), T(1), 1,
false,
true);
2786 template<
typename ScalarType>
2787 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2788 const vector_base<T>,
2789 op_sub>
const & proxy)
2792 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2793 proxy.rhs(), T(1), 1,
false,
true);
2797 template<
typename ScalarType>
2798 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2799 const vector_base<T>,
2800 op_sub>
const & proxy)
2803 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2804 proxy.rhs(), T(1), 1,
false,
true);
2808 template<
typename ScalarType>
2809 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2810 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2811 op_sub>
const & proxy)
2814 proxy.lhs(), T(1), 1,
false,
false,
2815 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2819 template<
typename ScalarType>
2820 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2821 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2822 op_sub>
const & proxy)
2825 proxy.lhs(), T(1), 1,
false,
false,
2826 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2830 template<
typename ScalarType1,
typename ScalarType2>
2831 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2832 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2833 op_sub>
const & proxy)
2836 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2837 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2841 template<
typename ScalarType1,
typename ScalarType2>
2842 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2843 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2844 op_sub>
const & proxy)
2847 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
false,
2848 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2852 template<
typename ScalarType1,
typename ScalarType2>
2853 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2854 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2855 op_sub>
const & proxy)
2858 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2859 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
true);
2863 template<
typename ScalarType1,
typename ScalarType2>
2864 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2865 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2866 op_sub>
const & proxy)
2869 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
false,
2870 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
true);
2877 template<
typename T,
typename LHS,
typename RHS>
2878 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_sub> >
2881 template<
typename LHS1,
typename RHS1>
2882 static void apply(vector_base<T> & lhs, vector_expression<const LHS1, const RHS1, op_sub>
const & proxy)
2884 bool op_aliasing_lhs =
op_aliasing(lhs, proxy.lhs());
2885 bool op_aliasing_rhs =
op_aliasing(lhs, proxy.rhs());
2887 if (op_aliasing_lhs || op_aliasing_rhs)
2889 vector_base<T> temp(proxy.lhs());
2890 op_executor<vector_base<T>, op_inplace_sub, RHS>::apply(temp, proxy.rhs());
2895 op_executor<vector_base<T>, op_inplace_sub, LHS>::apply(lhs, proxy.lhs());
2896 op_executor<vector_base<T>, op_inplace_add, RHS>::apply(lhs, proxy.rhs());
2901 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_sub>
const & proxy)
2904 proxy.lhs(), T(1), 1,
false,
true,
2905 proxy.rhs(), T(1), 1,
false,
false);
2909 template<
typename ScalarType>
2910 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2911 const vector_base<T>,
2912 op_sub>
const & proxy)
2915 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2916 proxy.rhs(), T(1), 1,
false,
false);
2920 template<
typename ScalarType>
2921 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2922 const vector_base<T>,
2923 op_sub>
const & proxy)
2926 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2927 proxy.rhs(), T(1), 1,
false,
false);
2931 template<
typename ScalarType>
2932 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2933 const vector_expression<
const vector_base<T>,
const ScalarType, op_mult>,
2934 op_sub>
const & proxy)
2937 proxy.lhs(), T(1), 1,
false,
true,
2938 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2942 template<
typename ScalarType>
2943 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
2944 const vector_expression<
const vector_base<T>,
const ScalarType, op_div>,
2945 op_sub>
const & proxy)
2948 proxy.lhs(), T(1), 1,
false,
true,
2949 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2953 template<
typename ScalarType1,
typename ScalarType2>
2954 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2955 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2956 op_sub>
const & proxy)
2959 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2960 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2964 template<
typename ScalarType1,
typename ScalarType2>
2965 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_mult>,
2966 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2967 op_sub>
const & proxy)
2970 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
false,
true,
2971 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
2975 template<
typename ScalarType1,
typename ScalarType2>
2976 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2977 const vector_expression<
const vector_base<T>,
const ScalarType2, op_mult>,
2978 op_sub>
const & proxy)
2981 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2982 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
false,
false);
2986 template<
typename ScalarType1,
typename ScalarType2>
2987 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<
const vector_base<T>,
const ScalarType1, op_div>,
2988 const vector_expression<
const vector_base<T>,
const ScalarType2, op_div>,
2989 op_sub>
const & proxy)
2992 proxy.lhs().lhs(), proxy.lhs().rhs(), 1,
true,
true,
2993 proxy.rhs().lhs(), proxy.rhs().rhs(), 1,
true,
false);
3017 template<
typename T,
typename LHS,
typename RHS,
typename OP>
3018 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const RHS, op_element_binary<OP> > >
3021 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3027 template<
typename LHS2,
typename RHS2,
typename OP2>
3028 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)
3030 vector<T> temp(proxy.rhs());
3035 template<
typename LHS1,
typename RHS1,
typename OP1>
3036 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)
3038 vector<T> temp(proxy.lhs());
3043 template<
typename LHS1,
typename RHS1,
typename OP1,
3044 typename LHS2,
typename RHS2,
typename OP2>
3045 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
3046 const vector_expression<const LHS2, const RHS2, OP2>,
3047 op_element_binary<OP> >
const & proxy)
3049 vector<T> temp1(proxy.lhs());
3050 vector<T> temp2(proxy.rhs());
3056 template<
typename T,
typename LHS,
typename RHS,
typename OP>
3057 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_element_binary<OP> > >
3060 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3067 template<
typename LHS2,
typename RHS2,
typename OP2>
3068 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)
3070 vector<T> temp(proxy.rhs());
3071 vector<T> temp2(temp.size());
3077 template<
typename LHS1,
typename RHS1,
typename OP1>
3078 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)
3080 vector<T> temp(proxy.lhs());
3081 vector<T> temp2(temp.size());
3087 template<
typename LHS1,
typename RHS1,
typename OP1,
3088 typename LHS2,
typename RHS2,
typename OP2>
3089 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
3090 const vector_expression<const LHS2, const RHS2, OP2>,
3091 op_element_binary<OP> >
const & proxy)
3093 vector<T> temp1(proxy.lhs());
3094 vector<T> temp2(proxy.rhs());
3095 vector<T> temp3(temp1.size());
3102 template<
typename T,
typename LHS,
typename RHS,
typename OP>
3103 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_element_binary<OP> > >
3107 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_binary<OP> >
const & proxy)
3114 template<
typename LHS2,
typename RHS2,
typename OP2>
3115 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)
3117 vector<T> temp(proxy.rhs());
3118 vector<T> temp2(temp.size());
3124 template<
typename LHS1,
typename RHS1,
typename OP1>
3125 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)
3127 vector<T> temp(proxy.lhs());
3128 vector<T> temp2(temp.size());
3134 template<
typename LHS1,
typename RHS1,
typename OP1,
3135 typename LHS2,
typename RHS2,
typename OP2>
3136 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS1, const RHS1, OP1>,
3137 const vector_expression<const LHS2, const RHS2, OP2>,
3138 op_element_binary<OP> >
const & proxy)
3140 vector<T> temp1(proxy.lhs());
3141 vector<T> temp2(proxy.rhs());
3142 vector<T> temp3(temp1.size());
3150 template<
typename T,
typename LHS,
typename RHS,
typename OP>
3151 struct op_executor<vector_base<T>, op_assign, vector_expression<const LHS, const RHS, op_element_unary<OP> > >
3154 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_unary<OP> >
const & proxy)
3160 template<
typename LHS2,
typename RHS2,
typename OP2>
3161 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS2, const RHS2, OP2>,
3162 const vector_expression<const LHS2, const RHS2, OP2>,
3163 op_element_unary<OP> >
const & proxy)
3165 vector<T> temp(proxy.rhs());
3170 template<
typename T,
typename LHS,
typename RHS,
typename OP>
3171 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, op_element_unary<OP> > >
3174 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_unary<OP> >
const & proxy)
3176 vector<T> temp(proxy);
3181 template<
typename LHS2,
typename RHS2,
typename OP2>
3182 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS2, const RHS2, OP2>,
3183 const vector_expression<const LHS2, const RHS2, OP2>,
3184 op_element_unary<OP> >
const & proxy)
3186 vector<T> temp(proxy.rhs());
3192 template<
typename T,
typename LHS,
typename RHS,
typename OP>
3193 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, op_element_unary<OP> > >
3196 static void apply(vector_base<T> & lhs, vector_expression<
const vector_base<T>,
const vector_base<T>, op_element_unary<OP> >
const & proxy)
3198 vector<T> temp(proxy);
3203 template<
typename LHS2,
typename RHS2,
typename OP2>
3204 static void apply(vector_base<T> & lhs, vector_expression<
const vector_expression<const LHS2, const RHS2, OP2>,
3205 const vector_expression<const LHS2, const RHS2, OP2>,
3206 op_element_unary<OP> >
const & proxy)
3208 vector<T> temp(proxy.rhs());
3218 template<
typename T,
typename UserMatrixT>
3219 struct op_executor<vector_base<T>, op_assign, vector_expression<const UserMatrixT, const vector_base<T>, op_prod> >
3221 static void apply(vector_base<T> & lhs, vector_expression<
const UserMatrixT,
const vector_base<T>, op_prod>
const & rhs)
3223 rhs.lhs().apply(rhs.rhs(), lhs);
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.
void convert(matrix_base< DestNumericT > &dest, matrix_base< SrcNumericT > const &src)
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_iterator(handle_type const &elements, size_type index, size_type start=0, size_type stride=1)
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.
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)