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
32 changes: 16 additions & 16 deletions include/graphblas/reference/blas1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3306,7 +3306,7 @@ namespace grb {
#endif
for( ; k < loop_coors.nonzeroes(); ++k ) {
const size_t index = loop_coors.index( k );
if( masked && mask_coors->template mask< descr >( index, mask_p ) ) {
if( masked && !mask_coors->template mask< descr >( index, mask_p ) ) {
continue;
}
RC rc = SUCCESS;
Expand Down Expand Up @@ -3518,7 +3518,7 @@ namespace grb {
if( loop_coors.assigned( index ) ) {
continue;
}
if( masked && mask_coors->template mask< descr >( index, mask_p ) ) {
if( masked && !mask_coors->template mask< descr >( index, mask_p ) ) {
continue;
}
#ifndef _H_GRB_REFERENCE_OMP_BLAS1
Expand Down Expand Up @@ -6132,25 +6132,25 @@ namespace grb {
#ifdef _H_GRB_REFERENCE_OMP_BLAS1
if( z_coors.asyncAssign( index, localUpdate ) ) {
#else
if( z_coors.assign( index ) ) {
if( z_coors.assign( index ) ) {
#endif
typename Ring::D4 b = static_cast< typename Ring::D4 >( z[ index ] );
(void) foldr( t, b, ring.getAdditiveOperator() );
z[ index ] = static_cast< OutputType >( b );
} else {
z[ index ] = static_cast< OutputType >(
static_cast< typename Ring::D4 >( t )
);
typename Ring::D4 b = static_cast< typename Ring::D4 >( z[ index ] );
(void) foldr( t, b, ring.getAdditiveOperator() );
z[ index ] = static_cast< OutputType >( b );
} else {
z[ index ] = static_cast< OutputType >(
static_cast< typename Ring::D4 >( t )
);
#ifdef _H_GRB_REFERENCE_OMP_BLAS1
(void) ++asyncAssigns;
if( asyncAssigns == maxAsyncAssigns ) {
(void) z_coors.joinUpdate( localUpdate );
asyncAssigns = 0;
}
#endif
(void) ++asyncAssigns;
if( asyncAssigns == maxAsyncAssigns ) {
(void) z_coors.joinUpdate( localUpdate );
asyncAssigns = 0;
}
#endif
}
}
}
#ifdef _H_GRB_REFERENCE_OMP_BLAS1
while( !z_coors.joinUpdate( localUpdate ) ) {}
}
Expand Down
91 changes: 86 additions & 5 deletions tests/unit/ewiseapply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <graphblas.hpp>


using namespace grb;

void grb_program( const size_t &n, grb::RC &rc ) {
Expand Down Expand Up @@ -659,28 +660,108 @@ void grb_program( const size_t &n, grb::RC &rc ) {

rc = grb::eWiseApply( out, mask, right, right, plusM );
assert( rc == SUCCESS );
const bool halfIsOdd = ((n / 2) % 2) == 1;
if( rc == SUCCESS ) {
if( nnz( out ) != nnz( right ) / 2 ) {
const size_t expected = nnz( right ) / 2 + (halfIsOdd ? 1 : 0);
if( nnz( out ) != expected ) {
std::cerr << "\tunexpected number of nonzeroes ( " << nnz( out ) << ", "
<< "expected " << nnz( right ) / 2 << " ) at subtest 22\n";
<< "expected " << expected << " ) at subtest 22\n";
rc = FAILED;
}
for( const auto &pair : out ) {
if( pair.first < n / 2 ) {
if( pair.first % 2 == 0 ) {
if( pair.second != static_cast< double >( .5 ) ) {
std::cerr << "\tunexpected entry ( " << pair.first << ", " << pair.second
<< "; expected ( " << pair.first << ", 0.5 ) at subtest 22\n";
<< " ), expected ( " << pair.first << ", 0.5 ) at subtest 22\n";
rc = FAILED;
}
} else {
std::cerr << "\tunexpected entry ( " << pair.first << ", " << pair.second
<< "; expected nothing at this entry) at subtest 22\n";
<< " ), expected nothing at this entry at subtest 22\n";
rc = FAILED;
}
} else {
std::cerr << "\tunexpected entry ( " << pair.first << ", " << pair.second
<< " ), expected nothing at this index at subtest 22\n";
rc = FAILED;
}
}
if( rc == FAILED ) {
return;
}
} else {
return;
}

rc = clear( right );
rc = rc ? rc : clear( left );
rc = rc ? rc : setElement( right, 2.17, 0 );
rc = rc ? rc : setElement( right, 2.0, n/2 );
rc = rc ? rc : setElement( right, 3.14, n-1 );
rc = rc ? rc : setElement( left, 1.0, n-1 );
rc = rc ? rc : setElement( left, -1.0, 0 );
rc = eWiseApply( out, mask, left, right, plusM );
assert( n % 2 == 0 );
assert( rc == SUCCESS );
if( rc == SUCCESS ) {
const size_t expect = 1;
if( nnz( out ) != expect ) {
std::cerr << "\tunexpected number of nonzeroes ( " << nnz( out ) << ", "
<< "), expected " << expect << " ) at subtest 23\n";
rc = FAILED;
}
for( const auto &pair : out ) {
if( pair.first == 0 ) {
if( pair.second != 1.17 ) {
std::cerr << "\tunexpected entry ( " << pair.first << ", " << pair.second
<< " ), expected ( " << pair.first << ", 1.17 ) at subtest 23\n";
rc = FAILED;
}
} else {
std::cerr << "\tunexpected entry ( " << pair.first << ", " << pair.second
<< " ), expected ( " << pair.first << ", " << (n/2) << " ) "
<< "at subtest 23\n";
rc = FAILED;
}
}
if( rc == FAILED ) {
return;
}
} else {
return;
}

rc = grb::eWiseApply( out, left, right, plusM );
assert( rc == SUCCESS );
if( rc == SUCCESS ) {
if( nnz( out ) != 3 ) {
std::cerr << "\tunexpected number of nonzeroes ( " << nnz( out ) << ", "
<< "expected " << 3 << " ) at subtest 24\n";
rc = FAILED;
}
for( const auto &pair : out ) {
if( pair.first == 0 ) {
if( pair.second != 1.17 ) {
std::cerr << "\tunexpected entry ( " << pair.first << ", " << pair.second
<< " ), expected ( " << pair.first << ", 1.17 ) at subtest 24\n";
rc = FAILED;
}
} else if( pair.first == n / 2 ) {
if( pair.second != 2.0 ) {
std::cerr << "\tunexpected entry ( " << pair.first << ", " << pair.second
<< " ), expected ( " << pair.first << ", 2.0 ) at subtest 24\n";
rc = FAILED;
}
} else if( pair.first == n - 1 ) {
if( !utils::equals( pair.second, 4.14, 1 ) ) {
std::cerr << "\tunexpected entry ( " << pair.first << ", " << pair.second
<< " ), expected ( " << pair.first << ", 4.14 ) at subtest 24\n";
rc = FAILED;
}
} else {
std::cerr << "\tunexpected entry ( " << pair.first << ", " << pair.second
<< "; expected nothing at this index) at subtest 22\n";
<< ", expected nothing at this index at subtest 24\n";
rc = FAILED;
}
}
Expand Down
19 changes: 13 additions & 6 deletions tests/unit/unittests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,26 +194,33 @@ for MODE in debug ndebug; do
grep 'Test OK' ${TEST_OUT_DIR}/pinnedVector_${MODE}_${BACKEND}_${P}_${T}.log || echo "Test FAILED"
echo " "

echo ">>> [x] [ ] Testing grb::eWiseApply using (+,0) on vectors"
echo " of doubles of size 14."
$runner ${TEST_BIN_DIR}/ewiseapply_${MODE}_${BACKEND} 14 &> ${TEST_OUT_DIR}/ewiseapply_small_${MODE}_${BACKEND}_${P}_${T}
head -1 ${TEST_OUT_DIR}/ewiseapply_small_${MODE}_${BACKEND}_${P}_${T}
grep 'Test OK' ${TEST_OUT_DIR}/ewiseapply_small_${MODE}_${BACKEND}_${P}_${T} || echo "Test FAILED"
echo " "

echo ">>> [x] [ ] Testing grb::eWiseApply using (+,0) on vectors"
echo " of doubles of size 100."
$runner ${TEST_BIN_DIR}/ewiseapply_${MODE}_${BACKEND} 100 &> ${TEST_OUT_DIR}/ewiseapply_${MODE}_${BACKEND}_${P}_${T}
head -1 ${TEST_OUT_DIR}/ewiseapply_${MODE}_${BACKEND}_${P}_${T}
grep 'Test OK' ${TEST_OUT_DIR}/ewiseapply_${MODE}_${BACKEND}_${P}_${T} || echo "Test FAILED"
echo " "

echo ">>> [x] [ ] Testing grb::eWiseApply using + on matrices"
$runner ${TEST_BIN_DIR}/eWiseApply_matrix_${MODE}_${BACKEND} &> ${TEST_OUT_DIR}/eWiseApply_matrix_${MODE}_${BACKEND}_${P}_${T}
head -1 ${TEST_OUT_DIR}/eWiseApply_matrix_${MODE}_${BACKEND}_${P}_${T}
grep 'Test OK' ${TEST_OUT_DIR}/eWiseApply_matrix_${MODE}_${BACKEND}_${P}_${T} || echo "Test FAILED"
echo " "

echo ">>> [x] [ ] Testing grb::eWiseApply using (+,0) on vectors"
echo " of doubles of size 10 000 000."
$runner ${TEST_BIN_DIR}/ewiseapply_${MODE}_${BACKEND} 10000000 &> ${TEST_OUT_DIR}/ewiseapply_large_${MODE}_${BACKEND}_${P}_${T}
head -1 ${TEST_OUT_DIR}/ewiseapply_large_${MODE}_${BACKEND}_${P}_${T}
grep 'Test OK' ${TEST_OUT_DIR}/ewiseapply_large_${MODE}_${BACKEND}_${P}_${T} || echo "Test FAILED"
echo " "

echo ">>> [x] [ ] Testing grb::eWiseApply using + on matrices"
$runner ${TEST_BIN_DIR}/eWiseApply_matrix_${MODE}_${BACKEND} &> ${TEST_OUT_DIR}/eWiseApply_matrix_${MODE}_${BACKEND}_${P}_${T}
head -1 ${TEST_OUT_DIR}/eWiseApply_matrix_${MODE}_${BACKEND}_${P}_${T}
grep 'Test OK' ${TEST_OUT_DIR}/eWiseApply_matrix_${MODE}_${BACKEND}_${P}_${T} || echo "Test FAILED"
echo " "

echo ">>> [x] [ ] Testing grb::zip on two vectors of doubles and"
echo " ints of size 10 000 000."
$runner ${TEST_BIN_DIR}/zip_${MODE}_${BACKEND} 10000000 &> ${TEST_OUT_DIR}/zip_large_${MODE}_${BACKEND}_${P}_${T}
Expand Down