Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

316 invert mask descriptor inverts return value to true for unassigned elements #317

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions include/graphblas/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ namespace grb {
ret = assigned;
} else {
// if based on value, if there is a value, cast it to bool
if( assigned ) {
if( !assigned ) {
return false;
}
else {
ret = static_cast< bool >( val[ offset ] );
}
// otherwise there is no value and false is assumed
Expand All @@ -350,7 +353,10 @@ namespace grb {
ret = assigned;
} else {
// if based on value, if there is a value, cast it to bool
if( assigned ) {
if( !assigned ) {
return false;
}
else {
ret = static_cast< bool >( real( val [ offset ] ) ) ||
static_cast< bool >( imag( val [ offset ] ) );
}
Expand All @@ -371,10 +377,8 @@ namespace grb {
const void * const,
const size_t
) {
// set default mask to false
bool ret = assigned;
// check whether we should return the inverted value
if( descriptor & descriptors::invert_mask ) {
if( ( descriptor & descriptors::structural_complement ) == descriptors::structural_complement ) {
return !ret;
} else {
return ret;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/eWiseMul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void grb_program( const size_t &n, RC &rc ) {
}, temp );
rc = rc ? rc : set( even_mask, temp, true );
rc = rc ? rc : set< descriptors::invert_mask >(
odd_mask, even_mask, true );
odd_mask, temp, true );
rc = rc ? rc : wait();
if( rc != SUCCESS ) {
std::cerr << "\t initialisation of masks FAILED\n";
Expand Down
14 changes: 9 additions & 5 deletions tests/unit/launcher/reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,12 @@ void grbProgram( const size_t &P, int &exit_status ) {
grb::Vector< bool > even_mask( n );
check = 0.0;
for( size_t i = 0; i < n; i += 2 ) {
check += xr[ i ];
const grb::RC setrc = grb::setElement( even_mask, true, i );
bool set_to = false;
if( i%4 == 0 ) {
check += xr[ i ];
set_to = true;
}
const grb::RC setrc = grb::setElement( even_mask, set_to, i );
#ifndef NDEBUG
assert( setrc == grb::SUCCESS );
#else
Expand All @@ -484,7 +488,7 @@ void grbProgram( const size_t &P, int &exit_status ) {
}

check = 0.0;
for( size_t i = 1; i < n; i += 2 ) {
for( size_t i = 2; i < n; i += 4 ) {
check += xr[ i ];
}

Expand Down Expand Up @@ -555,7 +559,7 @@ void grbProgram( const size_t &P, int &exit_status ) {
}

exit_status = expect_sparse_success< grb::descriptors::invert_mask >(
sparse, realm, grb::nnz(sparse), empty_mask );
sparse, realm, 0.0, empty_mask, grb::nnz(sparse) );
if( exit_status != 0 ) {
exit_status += 500;
return;
Expand Down Expand Up @@ -606,7 +610,7 @@ void grbProgram( const size_t &P, int &exit_status ) {
}

exit_status = expect_sparse_success< grb::descriptors::invert_mask >(
sparse, realm, grb::nnz(sparse), odd_mask );
sparse, realm, 0.0, odd_mask, grb::nnz(sparse) );
if( exit_status != 0 ) {
exit_status += 1100;
return;
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/pinnedVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ void grbProgram( const struct input< T > &in, struct output< T > &out ) {
case LEAST_SPARSE_CLEARED:
{
Vector< bool > mask( n );
rc = grb::setElement( mask, true, n/2 );
rc = grb::set( mask, false );
rc = rc ? rc : grb::setElement( mask, true, n/2 );
rc = rc ? rc : grb::set<
grb::descriptors::invert_mask
>( nonempty, mask, in.element );
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,8 @@ void grb_program( const size_t &n, grb::RC &rc ) {

// test sparse inverted mask set
grb::Vector< bool > mask( n );
rc = grb::setElement( mask, true, n / 2 );
rc = grb::set( mask, false );
rc = rc ? rc : grb::setElement( mask, true, n / 2 );
if( rc == SUCCESS ) {
rc = grb::set( src, 1.5 );
rc = rc ? rc : grb::wait( src );
Expand Down
Loading