1 //------------------------------------------------------------------------------
2 // GrB_Monoid_new: create a new monoid
3 //------------------------------------------------------------------------------
4
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7
8 //------------------------------------------------------------------------------
9
10 // Create a new monoid with binary operator, z=op(x.y). The three types of x,
11 // y, and z must all be the same, and the identity value must also have the
12 // same type. No typecasting is done for the identity value.
13
14 #include "GB.h"
15
16 #define GB_MONOID_NEW(prefix,type,T) \
17 GrB_Info GB_EVAL3 (prefix, _Monoid_new_, T) /* create a new monoid */ \
18 ( \
19 GrB_Monoid *monoid, /* handle of monoid to create */ \
20 GrB_BinaryOp op, /* binary operator of the monoid */ \
21 type identity /* identity value of the monoid */ \
22 ) \
23 { \
24 GB_WHERE1 ("GrB_Monoid_new_" GB_STR(T) " (&monoid, op, identity)") ; \
25 type id = identity ; \
26 return (GB_Monoid_new (monoid, op, &id, NULL, GB_ ## T ## _code, \
27 Context)) ; \
28 }
29
GB_MONOID_NEW(GrB,bool,BOOL)30 GB_MONOID_NEW (GrB, bool , BOOL )
31 GB_MONOID_NEW (GrB, int8_t , INT8 )
32 GB_MONOID_NEW (GrB, uint8_t , UINT8 )
33 GB_MONOID_NEW (GrB, int16_t , INT16 )
34 GB_MONOID_NEW (GrB, uint16_t , UINT16 )
35 GB_MONOID_NEW (GrB, int32_t , INT32 )
36 GB_MONOID_NEW (GrB, uint32_t , UINT32 )
37 GB_MONOID_NEW (GrB, int64_t , INT64 )
38 GB_MONOID_NEW (GrB, uint64_t , UINT64 )
39 GB_MONOID_NEW (GrB, float , FP32 )
40 GB_MONOID_NEW (GrB, double , FP64 )
41 GB_MONOID_NEW (GxB, GxB_FC32_t, FC32 )
42 GB_MONOID_NEW (GxB, GxB_FC64_t, FC64 )
43
44 GrB_Info GrB_Monoid_new_UDT // create a monoid with a user-defined type
45 (
46 GrB_Monoid *monoid, // handle of monoid to create
47 GrB_BinaryOp op, // binary operator of the monoid
48 void *identity // identity value of monoid
49 )
50 {
51 GB_WHERE1 ("GrB_Monoid_new_UDT (&monoid, op, identity)") ;
52 return (GB_Monoid_new (monoid, op, identity, NULL, GB_UDT_code, Context)) ;
53 }
54
55