Exemple #1
0
void vector_assign_functor(
	vector_expression<V, cpu_tag>& v,
	vector_expression<E, cpu_tag> const& e,
	F f,
	sparse_tag tag, dense_tag
){	
	typedef typename V::value_type value_type;
	typedef typename V::size_type size_type;
	value_type zero = value_type();
	size_type size = e().size();
	
	typename V::iterator it = v().begin();
	for(size_type i = 0; i != size; ++i,++it){
		if(it == v().end() || it.index() != i){//insert missing elements
			it = v().set_element(it,i,zero); 
		}
		*it = f(*it, e()(i));
	}
}
Exemple #2
0
void assign(
    vector_expression<V>& v,
    vector_expression<E> const& e,
    F f,
    sparse_bidirectional_iterator_tag tag, dense_random_access_iterator_tag
) {
    typedef typename V::value_type value_type;
    typedef typename V::size_type size_type;
    value_type zero = value_type();
    size_type size = e().size();

    typename V::iterator it = v().begin();
    for(size_type i = 0; i != size; ++i,++it) {
        if(it == v().end() || it.index() != i) { //insert missing elements
            it = v().set_element(it,i,zero);
        }
        f(*it, e()(i));
    }
}
Exemple #3
0
void assign_sparse(
    vector_expression<V>& v,
    vector_expression<E> const& e,
    F f
) {
    typedef typename V::value_type value_type;
    typedef typename V::size_type size_type;
    value_type zero = value_type();
    size_type size = v().size();

    typename V::iterator it = v().begin();
    typename E::const_iterator ite = e().begin();
    typename E::const_iterator ite_end = e().end();
    while(it != v().end() && ite != ite_end) {
        size_type it_index = it.index();
        size_type ite_index = ite.index();
        if (it_index == ite_index) {
            f(*it, *ite);
            ++ ite;
        } else if (it_index < ite_index) {
            f(*it, zero);
        } else { //it_index > ite_index so insert new element in v()
            it = v().set_element(it,ite_index,zero);
            f(*it, *ite);
            ++ite;
        }
        ++it;
    }
    //apply zero transformation on elements which are not transformed yet
    for(; it != v().end(); ++it) {
        f(*it, zero);
    }
    //add missing elements
    for(; ite != ite_end; ++it,++ite) {
        it = v().set_element(it,ite.index(),zero);
        f(*it, *ite);
    }
}
Exemple #4
0
  static
 typename V::size_type index (const typename V::iterator &i) {
     return i.index ();
 }
 BOOST_UBLAS_INLINE static
 typename V::size_type index (const typename V::iterator &i) {
     return i.index ();
 }