Skip to content

Commit 80ec4b2

Browse files
committed
Implementation in hyperdags
1 parent 000777a commit 80ec4b2

File tree

3 files changed

+195
-3
lines changed

3 files changed

+195
-3
lines changed

include/graphblas/hyperdags/blas3.hpp

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,174 @@ namespace grb {
332332
return ret;
333333
}
334334

335+
template<
336+
Descriptor descr = descriptors::no_operation,
337+
class Operator,
338+
typename IOType, typename MaskType, typename InputType,
339+
typename RIT_A, typename CIT_A, typename NIT_A,
340+
typename RIT_M, typename CIT_M, typename NIT_M
341+
>
342+
RC foldl(
343+
Matrix< IOType, hyperdags, RIT_A, CIT_A, NIT_A > &A,
344+
const Matrix< MaskType, hyperdags, RIT_M, CIT_M, NIT_M > &mask,
345+
const InputType &x,
346+
const Operator &op = Operator(),
347+
const typename std::enable_if<
348+
!grb::is_object< IOType >::value &&
349+
!grb::is_object< InputType >::value &&
350+
!grb::is_object< MaskType >::value &&
351+
grb::is_operator< Operator >::value, void
352+
>::type * const = nullptr
353+
) {
354+
const RC ret = foldl< descr >(
355+
internal::getMatrix( A ),
356+
internal::getMatrix( mask ),
357+
x,
358+
op
359+
);
360+
if( ret != SUCCESS ) { return ret; }
361+
if( nrows( A ) == 0 || ncols( A ) == 0 ) { return ret; }
362+
if( nrows( mask ) == 0 || ncols( mask ) == 0 ) { return ret; }
363+
std::array< const void *, 0 > sourcesP{};
364+
std::array< uintptr_t, 2 > sourcesC{
365+
getID( internal::getMatrix(A) ),
366+
getID( internal::getMatrix(mask) )
367+
};
368+
std::array< uintptr_t, 1 > destinations{
369+
getID( internal::getMatrix(A) )
370+
};
371+
internal::hyperdags::generator.addOperation(
372+
internal::hyperdags::FOLDL_MATRIX_MATRIX_BETA_OP,
373+
sourcesP.begin(), sourcesP.end(),
374+
sourcesC.begin(), sourcesC.end(),
375+
destinations.begin(), destinations.end()
376+
);
377+
return ret;
378+
}
379+
380+
template<
381+
Descriptor descr = descriptors::no_operation,
382+
class Operator,
383+
typename IOType, typename InputType,
384+
typename RIT, typename CIT, typename NIT
385+
>
386+
RC foldl(
387+
Matrix< IOType, hyperdags, RIT, CIT, NIT > &A,
388+
const InputType &x,
389+
const Operator &op = Operator(),
390+
const typename std::enable_if<
391+
!grb::is_object< IOType >::value &&
392+
!grb::is_object< InputType >::value &&
393+
grb::is_operator< Operator >::value, void
394+
>::type * const = nullptr
395+
) {
396+
const RC ret = foldl< descr >(
397+
internal::getMatrix( A ),
398+
x,
399+
op
400+
);
401+
if( ret != SUCCESS ) { return ret; }
402+
if( nrows( A ) == 0 || ncols( A ) == 0 ) { return ret; }
403+
std::array< const void *, 0 > sourcesP{};
404+
std::array< uintptr_t, 1 > sourcesC{
405+
getID( internal::getMatrix(A) )
406+
};
407+
std::array< uintptr_t, 1 > destinations{
408+
getID( internal::getMatrix(A) )
409+
};
410+
internal::hyperdags::generator.addOperation(
411+
internal::hyperdags::FOLDL_MATRIX_BETA_OP,
412+
sourcesP.begin(), sourcesP.end(),
413+
sourcesC.begin(), sourcesC.end(),
414+
destinations.begin(), destinations.end()
415+
);
416+
return ret;
417+
}
418+
419+
template<
420+
Descriptor descr = descriptors::no_operation,
421+
class Operator,
422+
typename IOType, typename MaskType, typename InputType,
423+
typename RIT_A, typename CIT_A, typename NIT_A,
424+
typename RIT_M, typename CIT_M, typename NIT_M
425+
>
426+
RC foldr(
427+
Matrix< IOType, hyperdags, RIT_A, CIT_A, NIT_A > &A,
428+
const Matrix< MaskType, hyperdags, RIT_M, CIT_M, NIT_M > &mask,
429+
const InputType &x,
430+
const Operator &op = Operator(),
431+
const typename std::enable_if<
432+
!grb::is_object< IOType >::value &&
433+
!grb::is_object< InputType >::value &&
434+
!grb::is_object< MaskType >::value &&
435+
grb::is_operator< Operator >::value, void
436+
>::type * const = nullptr
437+
) {
438+
const RC ret = foldr< descr >(
439+
internal::getMatrix( A ),
440+
internal::getMatrix( mask ),
441+
x,
442+
op
443+
);
444+
if( ret != SUCCESS ) { return ret; }
445+
if( nrows( A ) == 0 || ncols( A ) == 0 ) { return ret; }
446+
if( nrows( mask ) == 0 || ncols( mask ) == 0 ) { return ret; }
447+
std::array< const void *, 0 > sourcesP{};
448+
std::array< uintptr_t, 2 > sourcesC{
449+
getID( internal::getMatrix(A) ),
450+
getID( internal::getMatrix(mask) )
451+
};
452+
std::array< uintptr_t, 1 > destinations{
453+
getID( internal::getMatrix(A) )
454+
};
455+
internal::hyperdags::generator.addOperation(
456+
internal::hyperdags::FOLDR_MATRIX_MATRIX_BETA_OP,
457+
sourcesP.begin(), sourcesP.end(),
458+
sourcesC.begin(), sourcesC.end(),
459+
destinations.begin(), destinations.end()
460+
);
461+
return ret;
462+
}
463+
464+
template<
465+
Descriptor descr = descriptors::no_operation,
466+
class Operator,
467+
typename IOType, typename InputType,
468+
typename RIT, typename CIT, typename NIT
469+
>
470+
RC foldr(
471+
Matrix< IOType, hyperdags, RIT, CIT, NIT > &A,
472+
const InputType &x,
473+
const Operator &op = Operator(),
474+
const typename std::enable_if<
475+
!grb::is_object< IOType >::value &&
476+
!grb::is_object< InputType >::value &&
477+
grb::is_operator< Operator >::value, void
478+
>::type * const = nullptr
479+
) {
480+
const RC ret = foldr< descr >(
481+
internal::getMatrix( A ),
482+
x,
483+
op
484+
);
485+
if( ret != SUCCESS ) { return ret; }
486+
if( nrows( A ) == 0 || ncols( A ) == 0 ) { return ret; }
487+
std::array< const void *, 0 > sourcesP{};
488+
std::array< uintptr_t, 1 > sourcesC{
489+
getID( internal::getMatrix(A) )
490+
};
491+
std::array< uintptr_t, 1 > destinations{
492+
getID( internal::getMatrix(A) )
493+
};
494+
internal::hyperdags::generator.addOperation(
495+
internal::hyperdags::FOLDR_MATRIX_BETA_OP,
496+
sourcesP.begin(), sourcesP.end(),
497+
sourcesC.begin(), sourcesC.end(),
498+
destinations.begin(), destinations.end()
499+
);
500+
return ret;
501+
}
502+
335503
} // end namespace grb
336504

337505
#endif

include/graphblas/hyperdags/hyperdags.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,20 @@ namespace grb {
488488

489489
EWISEMUL_VECTOR_VECTOR_ALPHA_BETA_RING,
490490

491-
EWISELAMBDA_FUNC_VECTOR
491+
EWISELAMBDA_FUNC_VECTOR,
492+
493+
FOLDL_MATRIX_MATRIX_BETA_OP,
494+
495+
FOLDL_MATRIX_BETA_OP,
496+
497+
FOLDR_MATRIX_MATRIX_BETA_OP,
498+
499+
FOLDR_MATRIX_BETA_OP
492500

493501
};
494502

495503
/** \internal How many operation vertex types exist. */
496-
const constexpr size_t numOperationVertexTypes = 106;
504+
const constexpr size_t numOperationVertexTypes = 110;
497505

498506
/** \internal An array of all operation vertex types. */
499507
const constexpr enum OperationVertexType
@@ -604,7 +612,11 @@ namespace grb {
604612
EWISEMUL_VECTOR_VECTOR_ALPHA_VECTOR_RING,
605613
EWISEMUL_VECTOR_VECTOR_VECTOR_BETA_RING,
606614
EWISEMUL_VECTOR_VECTOR_ALPHA_BETA_RING,
607-
EWISELAMBDA_FUNC_VECTOR
615+
EWISELAMBDA_FUNC_VECTOR,
616+
FOLDL_MATRIX_MATRIX_BETA_OP,
617+
FOLDL_MATRIX_BETA_OP,
618+
FOLDR_MATRIX_MATRIX_BETA_OP,
619+
FOLDR_MATRIX_BETA_OP
608620
};
609621

610622
/** \internal @returns The operation vertex type as a string. */

src/graphblas/hyperdags/hyperdags.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,18 @@ std::string grb::internal::hyperdags::toString(
379379

380380
case GETID_MATRIX:
381381
return "getID( matrix )";
382+
383+
case FOLDL_MATRIX_MATRIX_BETA_OP:
384+
return "foldl( matrix, matrix, scalar )";
385+
386+
case FOLDL_MATRIX_BETA_OP:
387+
return "foldl( matrix, scalar )";
388+
389+
case FOLDR_MATRIX_MATRIX_BETA_OP:
390+
return "foldr( matrix, matrix, scalar )";
391+
392+
case FOLDR_MATRIX_BETA_OP:
393+
return "foldr( matrix, scalar )";
382394

383395
}
384396
assert( false );

0 commit comments

Comments
 (0)