Skip to content

Descriptor resolutions on compile time #371

@djelovina

Description

@djelovina

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


...

// 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 working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions