38#define NO_CAST_ASSERT( x, y, z ) \
41 "************************************************************************" \
42 "************************************************************************" \
43 "**********************\n" \
44 "* ERROR | " y " " z ".\n" \
45 "************************************************************************" \
46 "************************************************************************" \
47 "**********************\n" \
48 "* Possible fix 1 | Remove no_casting from the template parameters in " \
49 "this call to " y ".\n" \
50 "* Possible fix 2 | Provide a left-hand side input value of the same " \
51 "type as the first domain of the given operator.\n" \
52 "* Possible fix 3 | Provide a right-hand side input value of the same " \
53 "type as the second domain of the given operator.\n" \
54 "* Possible fix 4 | Provide an output value of the same type as the " \
55 "third domain of the given operator.\n" \
56 "* Note that in case of in-place operators the left-hand side input or " \
57 "right-hand side input also play the role of the output value.\n" \
58 "************************************************************************" \
59 "************************************************************************" \
60 "**********************\n" );
177 typename InputType1,
typename InputType2,
typename OutputType
184 const typename std::enable_if<
189 void >::type * =
nullptr
193 std::is_same< InputType1, typename OP::D1 >::value &&
194 std::is_same< InputType2, typename OP::D2 >::value &&
195 std::is_same< OutputType, typename OP::D3 >::value
197 "grb::apply (BLAS level 0)",
198 "Argument value types do not match operator domains while no_casting "
203 const typename OP::D1 left =
static_cast< typename OP::D1
>( x );
204 const typename OP::D2 right =
static_cast< typename OP::D2
>( y );
205 typename OP::D3 output =
static_cast< typename OP::D3
>( out );
206 op.apply( left, right, output );
207 out =
static_cast< OutputType
>( output );
285 class OP,
typename InputType,
typename IOType
291 const typename std::enable_if<
299 std::is_same< InputType, typename OP::D1 >::value &&
300 std::is_same< IOType, typename OP::D2 >::value &&
301 std::is_same< IOType, typename OP::D3 >::value
302 ) ),
"grb::foldr (BLAS level 0)",
303 "Argument value types do not match operator domains while no_casting "
304 "descriptor was set" );
307 const typename OP::D1 left =
static_cast< typename OP::D1
>( x );
308 typename OP::D3 right =
static_cast< typename OP::D3
>( y );
309 op.foldr( left, right );
310 y =
static_cast< IOType
>( right );
389 typename InputType,
typename IOType
402 std::is_same< IOType, typename OP::D1 >::value &&
403 std::is_same< InputType, typename OP::D2 >::value &&
404 std::is_same< IOType, typename OP::D3 >::value
405 ) ),
"grb::foldl (BLAS level 0)",
406 "Argument value types do not match operator domains while no_casting "
407 "descriptor was set" );
410 typename OP::D1 left =
static_cast< typename OP::D1
>( x );
411 const typename OP::D3 right =
static_cast< typename OP::D3
>( y );
412 op.foldl( left, right );
413 x =
static_cast< IOType
>( left );
439 typename OutputType,
typename D,
440 typename Enabled =
void
445 template< grb::Descriptor descr,
typename OutputType,
typename D >
449 typename std::enable_if<
450 std::is_arithmetic< OutputType >::value &&
451 !std::is_same< D, void >::value
459 static_assert( use_index || std::is_convertible< D, OutputType >::value,
460 "Cannot convert to the requested output type" );
465 static OutputType getFromArray(
466 const D * __restrict__
const x,
467 const std::function<
size_t(
size_t ) > &src_local_to_global,
471 return static_cast< OutputType
>( src_local_to_global( index ) );
473 return static_cast< OutputType
>( x[ index ] );
477 static OutputType getFromScalar(
const D &x,
const size_t index )
noexcept {
479 return static_cast< OutputType
>( index );
481 return static_cast< OutputType
>( x );
488 template< grb::Descriptor descr,
typename OutputType,
typename D >
492 typename std::enable_if<
493 !std::is_arithmetic< OutputType >::value &&
494 !std::is_same< OutputType, void >::value
499 "use_index descriptor given while output type is not numeric" );
501 static_assert( std::is_convertible< D, OutputType >::value,
502 "Cannot convert input to the given output type" );
506 static OutputType getFromArray(
507 const D * __restrict__
const x,
508 const std::function<
size_t(
size_t ) > &,
511 return static_cast< OutputType
>( x[ index ] );
514 static OutputType getFromScalar(
515 const D &x,
const size_t
517 return static_cast< OutputType
>( x );
544 typename OutputType,
typename InputType,
545 template<
typename >
class Identity,
546 typename Enabled =
void
548 class CopyOrApplyWithIdentity;
553 typename OutputType,
typename InputType,
554 template<
typename >
class Identity
556 class CopyOrApplyWithIdentity<
558 OutputType, InputType,
560 typename std::enable_if<
561 std::is_convertible< InputType, OutputType >::value
567 template<
typename Operator >
568 static void set( OutputType &out,
const InputType &in,
const Operator & ) {
569 out =
static_cast< OutputType
>( in );
577 typename OutputType,
typename InputType,
578 template<
typename >
class Identity
580 class CopyOrApplyWithIdentity<
582 OutputType, InputType,
584 typename std::enable_if<
585 !std::is_convertible< InputType, OutputType >::value
591 template<
typename Operator >
593 OutputType &out,
const InputType &in,
const Operator &op
595 const auto identity = identity_left ?
596 Identity< typename Operator::D1 >::value() :
597 Identity< typename Operator::D2 >::value();
598 if( identity_left ) {
Defines all ALP/GraphBLAS descriptors.
static enum RC apply(OutputType &out, const InputType1 &x, const InputType2 &y, const OP &op=OP(), const typename std::enable_if< grb::is_operator< OP >::value &&!grb::is_object< InputType1 >::value &&!grb::is_object< InputType2 >::value &&!grb::is_object< OutputType >::value, void >::type *=nullptr)
Out-of-place application of the operator OP on two data elements.
Definition: blas0.hpp:179
RC foldl(IOType &x, const Vector< InputType, backend, Coords > &y, const Vector< MaskType, backend, Coords > &mask, const Monoid &monoid=Monoid(), const typename std::enable_if< !grb::is_object< IOType >::value &&!grb::is_object< InputType >::value &&!grb::is_object< MaskType >::value &&grb::is_monoid< Monoid >::value, void >::type *const =nullptr)
Reduces, or folds, a vector into a scalar.
Definition: blas1.hpp:3618
RC foldr(const Vector< InputType, backend, Coords > &x, const Vector< MaskType, backend, Coords > &mask, IOType &y, const Monoid &monoid=Monoid(), const typename std::enable_if< !grb::is_object< IOType >::value &&!grb::is_object< InputType >::value &&!grb::is_object< MaskType >::value &&grb::is_monoid< Monoid >::value, void >::type *const =nullptr)
Folds a vector into a scalar, right-to-left.
Definition: blas1.hpp:3721
RC set(Vector< DataType, backend, Coords > &x, const T val, const Phase &phase=EXECUTE, const typename std::enable_if< !grb::is_object< DataType >::value &&!grb::is_object< T >::value, void >::type *const =nullptr) noexcept
Sets all elements of a vector to the given value.
Definition: io.hpp:857
static constexpr Descriptor no_casting
Disallows the standard casting of input parameters to a compatible domain in case they did not match ...
Definition: descriptors.hpp:196
static constexpr Descriptor use_index
Instead of using input vector elements, use the index of those elements.
Definition: descriptors.hpp:167
static constexpr Descriptor no_operation
Indicates no additional pre- or post-processing on any of the GraphBLAS function arguments.
Definition: descriptors.hpp:63
The ALP/GraphBLAS namespace.
Definition: graphblas.hpp:450
RC
Return codes of ALP primitives.
Definition: rc.hpp:47
@ SUCCESS
Indicates the primitive has executed successfully.
Definition: rc.hpp:54
unsigned int Descriptor
Descriptors indicate pre- or post-processing for some or all of the arguments to an ALP/GraphBLAS cal...
Definition: descriptors.hpp:54
Defines the ALP error codes.
Used to inspect whether a given type is an ALP/GraphBLAS object.
Definition: type_traits.hpp:130
Used to inspect whether a given type is an ALP operator.
Definition: type_traits.hpp:104
Specifies the ALP algebraic type traits.