예제 #1
0
void vector_assign_functor(
	vector_expression<V, cpu_tag>& v,
	vector_expression<E, cpu_tag> const& e,
	F f,
	dense_tag, packed_tag
) {
	typedef typename E::const_iterator EIterator;
	typedef typename V::const_iterator VIterator;
	typedef typename V::value_type value_type;
	EIterator eiter = e().begin();
	EIterator eend = e().end();
	VIterator viter = v().begin();
	VIterator 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){
			*viter = f(*viter,value_type/*zero*/());
		}
		//copy contents of right-hand side
		for(;eiter != eend; ++eiter,++viter){
			*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= value_type/*zero*/();
	}
}
예제 #2
0
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::const_iterator VIterator;
    typedef typename V::scalar_type scalar_type;
    EIterator eiter = e().begin();
    EIterator eend = e().end();
    VIterator viter = v().begin();
    VIterator 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*/();
    }
}
예제 #3
0
void vector_assign_functor(
	vector_expression<V, cpu_tag>& v,
	vector_expression<E, cpu_tag> const& e,
	F f,
	packed_tag, packed_tag
) {
	typedef typename E::const_iterator EIterator;
	typedef typename V::const_iterator VIterator;
	typedef typename V::value_type value_type;
	EIterator eiter = e().begin();
	EIterator eend = e().end();
	VIterator viter = v().begin();
	VIterator vend = v().end();
	
	//right hand side has nonzero elements
	if(eiter != eend){
		
		//check for compatible layout
		REMORA_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
		REMORA_SIZE_CHECK(viter.index() <= eiter.index());
		REMORA_SIZE_CHECK(viter.index()+(vend-viter) >= eiter.index()+(eend-eiter));
		
		//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){
			*viter = f(*viter,value_type/*zero*/());
		}
		//copy contents of right-hand side
		for(;eiter != eend; ++eiter,++viter){
			*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= f(*viter,value_type/*zero*/());
	}
}