void assign( vector_expression<V>& v, vector_expression<E> const& e, dense_random_access_iterator_tag, packed_random_access_iterator_tag ) { SIZE_CHECK(v().size() == e().size()); typedef typename E::const_iterator EIterator; typedef typename V::scalar_type scalar_type; EIterator eiter = e.begin(); EIterator eend = e.end(); //special case: //right hand side is completely 0 if(eiter == eend) { v().clear(); return; } EIterator viter = v.begin(); EIterator vend = v.end(); //set the first elements to zero for(; viter.index() != eiter.index(); ++viter) { *viter= scalar_type/*zero*/(); } //copy contents of right-hand side for(; eiter != eend; ++eiter,++viter) { *viter= *eiter; } for(; viter!= vend; ++viter) { *viter= scalar_type/*zero*/(); } }
void assign( vector_expression<V>& v, vector_expression<E> const& e, packed_random_access_iterator_tag, packed_random_access_iterator_tag ) { SIZE_CHECK(v().size() == e().size()); typedef typename E::const_iterator EIterator; EIterator eiter = e.begin(); EIterator eend = e.end(); //special case: //right hand side is completely 0 if(eiter == eend){ v().clear(); return; } EIterator viter = v.begin(); EIterator vend = v.end(); //check for compatible layout SIZE_CHECK(vend-viter);//empty ranges can't be compatible //check whether the right hand side range is included in the left hand side range SIZE_CHECK(viter.index() <= eiter.index()); SIZE_CHECK(viter.index()+(vend-viter) >= eiter.index()+(eend-eiter)); //copy contents of right-hand side viter += eiter.index()-viter.index(); for(;eiter != eend; ++eiter,++viter){ *viter= *eiter; } }
void assign( vector_expression<V>& v, vector_expression<E> const& e, F f, dense_random_access_iterator_tag, packed_random_access_iterator_tag ) { SIZE_CHECK(v().size() == e().size()); typedef typename E::const_iterator EIterator; typedef typename V::scalar_type scalar_type; EIterator eiter = e.begin(); EIterator eend = e.end(); EIterator viter = v.begin(); EIterator vend = v.end(); //right hand side hasnonzero elements if(eiter != eend){ //apply f to the first elements for which the right hand side is 0, unless f is the identity for(;viter.index() != eiter.index() &&!F::right_zero_identity; ++viter){ f(*viter,scalar_type/*zero*/()); } //copy contents of right-hand side for(;eiter != eend; ++eiter,++viter){ f(*viter,*eiter); } } //apply f to the last elements for which the right hand side is 0, unless f is the identity for(;viter!= vend &&!F::right_zero_identity; ++viter){ *viter= scalar_type/*zero*/(); } }
viennacl::vector<SCALARTYPE, ALIGNMENT> viennacl::vector<SCALARTYPE, ALIGNMENT>::operator-(const vector_expression< const hankel_matrix<SCALARTYPE, MAT_ALIGNMENT>, const vector<SCALARTYPE, ALIGNMENT>, op_prod> & proxy) { assert(proxy.get_lhs().size1() == size()); vector<SCALARTYPE, ALIGNMENT> result(size()); viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result); result = *this - result; return result; }
vcl_size_t size(vector_expression<LHS, const int, op_matrix_diag> const & proxy) { int k = proxy.rhs(); int A_size1 = static_cast<int>(size1(proxy.lhs())); int A_size2 = static_cast<int>(size2(proxy.lhs())); int row_depth = std::min(A_size1, A_size1 + k); int col_depth = std::min(A_size2, A_size2 - k); return std::min(row_depth, col_depth); }
static void apply(vector_base<T> & lhs, vector_expression<const vandermonde_matrix<T, A>, const vector_base<T>, op_prod> const & rhs) { // check for the special case x = A * x if (viennacl::traits::handle(lhs) == viennacl::traits::handle(rhs.rhs())) { viennacl::vector<T> temp(lhs); viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), temp); lhs = temp; } else viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), lhs); }
typename viennacl::enable_if< viennacl::is_any_matrix<LHS>::value && viennacl::is_any_dense_nonstructured_vector<RHS>::value, vcl_size_t >::type size(vector_expression<const LHS, const RHS, op_prod> const & proxy) //matrix-vector product { return proxy.lhs().size1(); }
typename viennacl::enable_if< viennacl::is_any_dense_nonstructured_vector<RHS>::value, vcl_size_t >::type size(vector_expression<const matrix_expression<M1, M1, op_trans>, const RHS, op_prod> const & proxy) //transposed matrix-vector product { return proxy.lhs().lhs().size2(); }
void element_op(vector_base<T> & vec1, vector_expression<const vector_base<T>, const vector_base<T>, op_element_binary<OP> > const & proxy) { typedef T value_type; typedef viennacl::linalg::detail::op_applier<op_element_binary<OP> > OpFunctor; value_type * data_vec1 = detail::extract_raw_pointer<value_type>(vec1); value_type const * data_vec2 = detail::extract_raw_pointer<value_type>(proxy.lhs()); value_type const * data_vec3 = detail::extract_raw_pointer<value_type>(proxy.rhs()); std::size_t start1 = viennacl::traits::start(vec1); std::size_t inc1 = viennacl::traits::stride(vec1); std::size_t size1 = viennacl::traits::size(vec1); std::size_t start2 = viennacl::traits::start(proxy.lhs()); std::size_t inc2 = viennacl::traits::stride(proxy.lhs()); std::size_t start3 = viennacl::traits::start(proxy.rhs()); std::size_t inc3 = viennacl::traits::stride(proxy.rhs()); #ifdef VIENNACL_WITH_OPENMP #pragma omp parallel for if (size1 > VIENNACL_OPENMP_VECTOR_MIN_SIZE) #endif for (std::size_t i = 0; i < size1; ++i) OpFunctor::apply(data_vec1[i*inc1+start1], data_vec2[i*inc2+start2], data_vec3[i*inc3+start3]); }
void element_op(vector_base<NumericT> & vec1, vector_expression<const vector_base<NumericT>, const vector_base<NumericT>, op_element_unary<OpT> > const & proxy) { typedef NumericT value_type; typedef viennacl::linalg::detail::op_applier<op_element_unary<OpT> > OpFunctor; value_type * data_vec1 = detail::extract_raw_pointer<value_type>(vec1); value_type const * data_vec2 = detail::extract_raw_pointer<value_type>(proxy.lhs()); vcl_size_t start1 = viennacl::traits::start(vec1); vcl_size_t inc1 = viennacl::traits::stride(vec1); vcl_size_t size1 = viennacl::traits::size(vec1); vcl_size_t start2 = viennacl::traits::start(proxy.lhs()); vcl_size_t inc2 = viennacl::traits::stride(proxy.lhs()); #ifdef VIENNACL_WITH_OPENMP #pragma omp parallel for if (size1 > VIENNACL_OPENMP_VECTOR_MIN_SIZE) #endif for (long i = 0; i < static_cast<long>(size1); ++i) OpFunctor::apply(data_vec1[static_cast<vcl_size_t>(i)*inc1+start1], data_vec2[static_cast<vcl_size_t>(i)*inc2+start2]); }
vcl_size_t size(vector_expression<LHS, const unsigned int, op_column> const & proxy) { return size1(proxy.lhs()); }
vcl_size_t size(vector_expression<LHS, const vector_tuple<RHS>, op_inner_prod> const & proxy) { return proxy.rhs().const_size(); }
vcl_size_t size(vector_expression<const matrix_expression<const LhsT, const RhsT, OpT>, const vector_base<NumericT>, op_prod> const & proxy) { return size1(proxy.lhs()); }
bool op_aliasing(vector_base<NumericT> const & lhs, vector_expression<const LhsT, const RhsT, OpT> const & rhs) { return op_aliasing(lhs, rhs.lhs()) || op_aliasing(lhs, rhs.rhs()); }
static void apply(vector_base<T> & lhs, vector_expression<const vandermonde_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> const & rhs) { viennacl::vector<T> temp(rhs.rhs()); viennacl::linalg::prod_impl(rhs.lhs(), temp, lhs); }
vcl_size_t size(vector_expression<const matrix_base<NumericT>, const vector_expression<LhsT, RhsT, OpT>, op_prod> const & proxy) //matrix-vector product { return proxy.lhs().size1(); }
vcl_size_t size(vector_expression<const matrix_expression<const LhsT, const RhsT, OpT>, const matrix_expression<const LhsT, const RhsT, OpT>, op_col_sum> const & proxy) { return size2(proxy.lhs()); }
vcl_size_t size(vector_expression<const matrix_base<NumericT>, const matrix_base<NumericT>, op_col_sum> const & proxy) { return size2(proxy.lhs()); }
vcl_size_t size(vector_expression<const matrix_expression<const LhsT1, const RhsT1, OpT1>, const vector_expression<const LhsT2, const RhsT2, OpT2>, op_prod> const & proxy) { return size1(proxy.lhs()); }
vcl_size_t size(vector_expression<LHS, RHS, OP> const & proxy) { return size(proxy.lhs()); }
vcl_size_t size(vector_expression<const SparseMatrixType, const VectorType, op_prod> const & proxy) { return size1(proxy.lhs()); }
vcl_size_t size(vector_expression<const vandermonde_matrix<T, A>, const VectorType, op_prod> const & proxy) { return proxy.lhs().size1(); }
vcl_size_t size(vector_expression<const matrix_expression<const matrix_base<NumericT, F>, const matrix_base<NumericT, F>, op_trans>, const vector_base<NumericT>, op_prod> const & proxy) //transposed matrix-vector product { return proxy.lhs().lhs().size2(); }
typename viennacl::enable_if< viennacl::is_any_sparse_matrix<SparseMatrixType>::value, vcl_size_t >::type size(vector_expression<const SparseMatrixType, const VectorType, op_prod> const & proxy) { return proxy.lhs().size1(); }
vcl_size_t size(vector_expression<const matrix_expression<const LhsT, const RhsT, OpT>, VectorT, op_prod> const & proxy) { return size1(proxy.lhs()); }