Repository navigation
Closed
Description
Code like this one
rc = rc ? rc : grb::eWiseApply< (descr_dense) >(
y_comp, static_cast<IOType>(0),
mask,
grb::operators::left_assign_if<IOType, bool, IOType>()
);will fail to compile due to the static assertions in inactive part of the code
static_assert( !internal::maybe_noop< OP >::value, "Warning: you may be "in this example from
ALP/include/graphblas/reference/blas1.hpp
Line 5000 in 136ac70
| RC eWiseApply( |
...
ALP/include/graphblas/reference/blas1.hpp
Lines 5054 to 5075 in 136ac70
| // check for dense variant | |
| if( (descr & descriptors::dense) || | |
| internal::getCoordinates( y ).nonzeroes() == n | |
| ) { | |
| internal::getCoordinates( z ).assignAll(); | |
| const internal::Coordinates< reference > * const no_coordinates = nullptr; | |
| return internal::dense_apply_generic< true, false, false, false, descr >( | |
| internal::getRaw( z ), &alpha, no_coordinates, | |
| internal::getRaw( y ), no_coordinates, op, n | |
| ); | |
| } | |
| // we are in the sparse variant | |
| internal::getCoordinates( z ).clear(); | |
| const bool * const null_mask = nullptr; | |
| const Coords * const null_coors = nullptr; | |
| return internal::sparse_apply_generic< false, false, true, false, descr >( | |
| internal::getRaw( z ), internal::getCoordinates( z ), null_mask, null_coors, | |
| &alpha, null_coors, | |
| internal::getRaw( y ), &( internal::getCoordinates( y ) ), | |
| op, n | |
| ); |
// check for dense variant
if( (descr & descriptors::dense) ||
internal::getCoordinates( y ).nonzeroes() == n
) {
internal::getCoordinates( z ).assignAll();
const internal::Coordinates< reference > * const no_coordinates = nullptr;
// **<<------ active code**
return internal::dense_apply_generic< true, false, false, false, descr >(
internal::getRaw( z ), &alpha, no_coordinates,
internal::getRaw( y ), no_coordinates, op, n
);
}
// **<<------ inactive code**
// we are in the sparse variant
internal::getCoordinates( z ).clear();
const bool * const null_mask = nullptr;
const Coords * const null_coors = nullptr;
//**<<------ static assert inside**
return internal::sparse_apply_generic< false, false, true, false, descr >(
internal::getRaw( z ), internal::getCoordinates( z ), null_mask, null_coors,
&alpha, null_coors,
internal::getRaw( y ), &( internal::getCoordinates( y ) ),
op, n
);In order to avoid these problems the blocks of the code should be properly guarded by static checks.
related to #370 where some statements could be better implemented with this examples
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
[-]descriprot resultions on compile time[/-][+]descriptor resolutions on compile time[/+][-]descriptor resolutions on compile time[/-][+]Descriptor resolutions on compile time[/+]anyzelman commentedon Jul 25, 2025
I see the bug that you're indicating -- that static_assert would not trigger if the if-statement on the dense descriptor was a constexpr if. I also see what you're trying to do in the initial code snippet, starting there first:
Another way of writing this would be
Note that now, for every entry
iwheremask_ievaluatestrue, the original value of{y\_comp}_iis overwritten with zero. All other values ofy_compare left unmodified. I believe that's what you intend (by assumingy_compis dense, as per the descriptor name:).Now to the use of
eWiseApplyinstead. The issue the static_assert warns about, is that when usingleft_assign_ifin an out-of-place operation (likeeWiseApplybut alsogrb::set), then for entries where the right argument evaluatesfalse, the output is unmodified. If that output element was never set to begin with, however, which could be possible because this operation is out-of-place, this would result in an undefined value at that entry -- which usually is a bug (which is why I wrote it as a hard static assert failure). In this case, however, assumingy_compwas already set to something valid (which it should be, if given thedensedescriptor), you are correct that this assertion error should not trigger. Therefore this is indeed a bug -- will flag it as such and resolve it momentarily.Fixes the reported issue #371
djelovina commentedon Jul 25, 2025
Tanks! I fact I already wrote it like this but with explicit templates for
right_assignsincemaskis different type (bool)anyzelman commentedon Jul 25, 2025
I'm actually not sure if that's correct -- the mask does not enter the domains of the operator to be applied. Suppose
y_comphas some element typeT, then the right-assign OP should have domains T (since the left operand isy_comp) -> IOType (since that's the type of the scalar given as right operand) -> T (since it's folding the output back into the left operand).The reason it gets accepted is because ALP will internally cast
y_compfromTtobool(since that's now the OP's first domain). The reason that this casting behaviour doesn't lead to a bug is because either the original value ofy_compis retained, or it is overwritten by 0 (which is never cast away fromIOType).If you want ALP to nit-pick about domains (enforce that they always match), you can add the
grb::descriptors::no_castingtodescr_dense. In that case though, the element type ofmaskmust bebool-- which is the native element type of a mask container.djelovina commentedon Jul 28, 2025
Thanks. I fixed the operator domain. Perhaps we should add a section in tutorial in order to clarify these details.
Fixes static-assert failure from unused code path #371 (#372)