Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions include/alp/reference/blas1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3779,17 +3779,18 @@ namespace alp {
typename InputType2, typename InputStructure2, typename InputView2, typename InputImfR2, typename InputImfC2,
class AddMonoid, class AnyOp
>
RC dot( Scalar< OutputType, OutputStructure, reference > &z,
RC dot(
Scalar< OutputType, OutputStructure, reference > &z,
const Vector< InputType1, InputStructure1, Density::Dense, InputView1, InputImfR1, InputImfC1, reference > &x,
const Vector< InputType2, InputStructure2, Density::Dense, InputView2, InputImfR2, InputImfC2, reference > &y,
const AddMonoid &addMonoid = AddMonoid(),
const AnyOp &anyOp = AnyOp(),
const typename std::enable_if< !alp::is_object< OutputType >::value &&
const typename std::enable_if_t< !alp::is_object< OutputType >::value &&
!alp::is_object< InputType1 >::value &&
!alp::is_object< InputType2 >::value &&
alp::is_monoid< AddMonoid >::value &&
alp::is_operator< AnyOp >::value,
void >::type * const = NULL
alp::is_operator< AnyOp >::value
> * const = nullptr
) {
// static sanity checks
NO_CAST_ASSERT( ( !( descr & descriptors::no_casting ) || std::is_same< InputType1, typename AnyOp::D1 >::value ), "alp::dot",
Expand All @@ -3811,12 +3812,42 @@ namespace alp {
"called with an output vector value type that does not match the third "
"domain of the given additive operator" );
(void)z;
(void)x;
(void)y;
(void)addMonoid;
(void)anyOp;
throw std::runtime_error( "Needs an implementation." );
return SUCCESS;
if( size( x ) != size( y ) ) {
return MISMATCH;
}

if( !( internal::getInitialized( z ) && internal::getInitialized( x ) && internal::getInitialized( y ) ) ) {
#ifdef _DEBUG
std::cout << "dot(): one of input vectors or scalar are not initialized: do noting!\n";
#endif
return SUCCESS;
}

std::function< void( typename AddMonoid::D3 &, const size_t, const size_t ) > data_lambda =
[ &x, &y, &anyOp ]( typename AddMonoid::D3 &result, const size_t i, const size_t j ) {
(void) j;
internal::apply( result, x[ i ], y[ i ], anyOp );
};

std::function< bool() > init_lambda =
[ &x ]() -> bool {
return internal::getInitialized( x );
};

Vector<
typename AddMonoid::D3,
structures::General,
Density::Dense,
view::Functor< std::function< void( typename AddMonoid::D3 &, const size_t, const size_t ) > >,
imf::Id, imf::Id,
reference
> temp(
init_lambda,
getLength( x ),
data_lambda
);
RC rc = foldl( z, temp, addMonoid );
return rc;
}

/** C++ scalar specialization */
Expand Down
19 changes: 14 additions & 5 deletions include/alp/reference/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ namespace alp {

/** Returns the length of the vector */
size_t _length() const {
return this->amf.getLogicalDimensions().first;
return nrows( static_cast< const base_type & >( *this ) );
}


Expand All @@ -400,7 +400,16 @@ namespace alp {
typedef structures::General structure;

/** @see Vector::lambda_reference */
typedef T& lambda_reference;
typedef typename std::conditional<
internal::is_storage_based< self_type >::value,
T&,
T
>::type lambda_reference;
typedef typename std::conditional<
internal::is_storage_based< self_type >::value,
const T&,
const T
>::type const_lambda_reference;

template < view::Views view_tag, bool d=false >
struct view_type;
Expand Down Expand Up @@ -553,15 +562,15 @@ namespace alp {
assert( i < _length() );
//assert( getInitialized( *v ) );
/** \internal \todo revise the third and fourth parameter for parallel backends */
return this->access( this->amf.getStorageIndex( i, 0, 0, 1 ) );
return this->access( this->getStorageIndex( i, 0, 0, 1 ) );
}

/** \internal No implementation notes. */
const lambda_reference operator[]( const size_t i ) const noexcept {
const_lambda_reference operator[]( const size_t i ) const noexcept {
assert( i < _length() );
//assert( getInitialized( *v ) );
/** \internal \todo revise the third and fourth parameter for parallel backends */
return this->access( this->amf.getStorageIndex( i, 0, 0, 1 ) );
return this->access( this->getStorageIndex( i, 0, 0, 1 ) );
}

}; // class Vector with physical container
Expand Down
Loading