/
LibGraphBLAS.jl
2608 lines (2171 loc) · 120 KB
/
LibGraphBLAS.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module libgb
using Base: Float64
import ..libgraphblas
using ..SuiteSparseGraphBLAS: suffix, towrappertype
using MacroTools
using CEnum
const GxB_FC32_t = ComplexF32
const GxB_FC64_t = ComplexF32
const GrB_Index = UInt64
struct UninitializedObjectError <: Exception end
struct InvalidObjectError <: Exception end
struct NullPointerError <: Exception end
struct InvalidValueError <: Exception end
struct InvalidIndexError <: Exception end
struct OutputNotEmptyError <: Exception end
struct InsufficientSpaceError <: Exception end
struct PANIC <: Exception end
macro wraperror(code)
MacroTools.@q begin
info = $(esc(code))
if info == GrB_SUCCESS
return true
elseif info == GrB_NO_VALUE
return nothing
else
if info == GrB_UNINITIALIZED_OBJECT
throw(UninitializedObjectError)
elseif info == GrB_INVALID_OBJECT
throw(InvalidObjectError)
elseif info == GrB_NULL_POINTER
throw(NullPointerError)
elseif info == GrB_INVALID_VALUE
throw(InvalidValueError)
elseif info == GrB_INVALID_INDEX
throw(InvalidIndexError)
elseif info == GrB_DOMAIN_MISMATCH
throw(DomainError(nothing, "GraphBLAS Domain Mismatch"))
elseif info == GrB_DIMENSION_MISMATCH
throw(DimensionMismatch())
elseif info == GrB_OUTPUT_NOT_EMPTY
throw(OutputNotEmptyError)
elseif info == GrB_OUT_OF_MEMORY
throw(OutOfMemoryError())
elseif info == GrB_INSUFFICIENT_SPACE
throw(InsufficientSpaceError)
elseif info == GrB_INDEX_OUT_OF_BOUNDS
throw(BoundsError())
elseif info == GrB_PANIC
throw(PANIC)
else
throw(ErrorException("I don't know how I got here."))
end
end
end
end
function tozerobased(I)
I isa Vector && (return I .- 1)
I isa Integer && (return I - 1)
return I
end
function toonebased(I)
I isa Vector && (return I .+ 1)
I isa Integer && (return I + 1)
return I
end
const valid_vec = [Bool, Int8, UInt8, Int16, UInt16, Int32, UInt32,
Int64, UInt64, Float32, Float64, ComplexF32, ComplexF64]
@cenum GrB_Info::UInt32 begin
GrB_SUCCESS = 0
GrB_NO_VALUE = 1
GrB_UNINITIALIZED_OBJECT = 2
GrB_INVALID_OBJECT = 3
GrB_NULL_POINTER = 4
GrB_INVALID_VALUE = 5
GrB_INVALID_INDEX = 6
GrB_DOMAIN_MISMATCH = 7
GrB_DIMENSION_MISMATCH = 8
GrB_OUTPUT_NOT_EMPTY = 9
GrB_OUT_OF_MEMORY = 10
GrB_INSUFFICIENT_SPACE = 11
GrB_INDEX_OUT_OF_BOUNDS = 12
GrB_PANIC = 13
end
@cenum GrB_Mode::UInt32 begin
GrB_NONBLOCKING = 0
GrB_BLOCKING = 1
end
function GrB_init(mode)
@wraperror ccall((:GrB_init, libgraphblas), GrB_Info, (GrB_Mode,), mode)
end
function GxB_init(mode, user_malloc_function, user_calloc_function, user_realloc_function, user_free_function, user_malloc_is_thread_safe)
@wraperror ccall((:GxB_init, libgraphblas), GrB_Info, (GrB_Mode, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Bool), mode, user_malloc_function, user_calloc_function, user_realloc_function, user_free_function, user_malloc_is_thread_safe)
end
function GxB_cuda_init(mode)
@wraperror ccall((:GxB_cuda_init, libgraphblas), GrB_Info, (GrB_Mode,), mode)
end
function GrB_finalize()
@wraperror ccall((:GrB_finalize, libgraphblas), GrB_Info, ())
end
function GrB_getVersion(version=Ref{Cuint}(0), subversion=Ref{Cuint}(0))
@wraperror ccall((:GrB_getVersion, libgraphblas), GrB_Info, (Ptr{Cuint}, Ptr{Cuint}), version, subversion)
return version[], subversion[]
end
@cenum GrB_Desc_Field::UInt32 begin
GrB_OUTP = 0
GrB_MASK = 1
GrB_INP0 = 2
GrB_INP1 = 3
GxB_DESCRIPTOR_NTHREADS = 5
GxB_DESCRIPTOR_CHUNK = 7
GxB_DESCRIPTOR_GPU_CONTROL = 21
GxB_DESCRIPTOR_GPU_CHUNK = 22
GxB_AxB_METHOD = 1000
GxB_SORT = 35
end
@cenum GrB_Desc_Value::UInt32 begin
GxB_DEFAULT = 0
GrB_REPLACE = 1
GrB_COMP = 2
# GrB_SCMP = 2
GrB_STRUCTURE = 4
GrB_STRUCT_COMP = 6
GrB_TRAN = 3
GxB_GPU_ALWAYS = 2001
GxB_GPU_NEVER = 2002
GxB_AxB_GUSTAVSON = 1001
GxB_AxB_DOT = 1003
GxB_AxB_HASH = 1004
GxB_AxB_SAXPY = 1005
end
mutable struct GB_Descriptor_opaque end
const GrB_Descriptor = Ptr{GB_Descriptor_opaque}
function GrB_Descriptor_new(descriptor)
@wraperror ccall((:GrB_Descriptor_new, libgraphblas), GrB_Info, (Ptr{GrB_Descriptor},), descriptor)
end
function GrB_Descriptor_new()
desc = Ref{GrB_Descriptor}()
GrB_Descriptor_new(desc)
return desc[]
end
function GrB_Descriptor_set(desc, field, val)
@wraperror ccall((:GrB_Descriptor_set, libgraphblas), GrB_Info, (GrB_Descriptor, GrB_Desc_Field, GrB_Desc_Value), desc, field, val)
end
function GxB_Descriptor_get(val, desc, field)
@wraperror ccall((:GxB_Descriptor_get, libgraphblas), GrB_Info, (Ptr{GrB_Desc_Value}, GrB_Descriptor, GrB_Desc_Field), val, desc, field)
end
function GxB_Descriptor_get(desc, field)
v = Ref{GrB_Desc_Value}()
GxB_Descriptor_get(v, desc, field)
return v[]
end
function GrB_Descriptor_free(descriptor)
@wraperror ccall((:GrB_Descriptor_free, libgraphblas), GrB_Info, (Ptr{GrB_Descriptor},), descriptor)
end
mutable struct GB_Type_opaque end
const GrB_Type = Ptr{GB_Type_opaque}
function GB_Type_new(type, sizeof_ctype, name)
@wraperror ccall((:GB_Type_new, libgraphblas), GrB_Info, (Ptr{GrB_Type}, Csize_t, Ptr{Cchar}), type, sizeof_ctype, name)
end
function GxB_Type_size(size, type)
@wraperror ccall((:GxB_Type_size, libgraphblas), GrB_Info, (Ptr{Csize_t}, GrB_Type), size, type)
end
function GrB_Type_free(type)
@wraperror ccall((:GrB_Type_free, libgraphblas), GrB_Info, (Ptr{GrB_Type},), type)
end
mutable struct GB_UnaryOp_opaque end
const GrB_UnaryOp = Ptr{GB_UnaryOp_opaque}
# typedef void ( * GxB_unary_function ) ( void * , const void * )
const GxB_unary_function = Ptr{Cvoid}
function GB_UnaryOp_new(unaryop, _function, ztype, xtype, name)
@wraperror ccall((:GB_UnaryOp_new, libgraphblas), GrB_Info, (Ptr{GrB_UnaryOp}, GxB_unary_function, GrB_Type, GrB_Type, Ptr{Cchar}), unaryop, _function, ztype, xtype, name)
end
function GxB_UnaryOp_ztype(ztype, unaryop)
@wraperror ccall((:GxB_UnaryOp_ztype, libgraphblas), GrB_Info, (Ptr{GrB_Type}, GrB_UnaryOp), ztype, unaryop)
end
function GxB_UnaryOp_ztype(unaryop)
z = Ref{GrB_Type}()
GxB_UnaryOp_ztype(z, unaryop)
return z[]
end
function GxB_UnaryOp_xtype(xtype, unaryop)
@wraperror ccall((:GxB_UnaryOp_xtype, libgraphblas), GrB_Info, (Ptr{GrB_Type}, GrB_UnaryOp), xtype, unaryop)
end
function GxB_UnaryOp_xtype(unaryop)
x = Ref{GrB_Type}()
GxB_UnaryOp_ztype(x, unaryop)
return x[]
end
function GrB_UnaryOp_free(unaryop)
@wraperror ccall((:GrB_UnaryOp_free, libgraphblas), GrB_Info, (Ptr{GrB_UnaryOp},), unaryop)
end
mutable struct GB_BinaryOp_opaque end
const GrB_BinaryOp = Ptr{GB_BinaryOp_opaque}
# typedef void ( * GxB_binary_function ) ( void * , const void * , const void * )
const GxB_binary_function = Ptr{Cvoid}
function GB_BinaryOp_new(binaryop, _function, ztype, xtype, ytype, name)
@wraperror ccall((:GB_BinaryOp_new, libgraphblas), GrB_Info, (Ptr{GrB_BinaryOp}, GxB_binary_function, GrB_Type, GrB_Type, GrB_Type, Ptr{Cchar}), binaryop, _function, ztype, xtype, ytype, name)
end
function GxB_BinaryOp_ztype(ztype, binaryop)
@wraperror ccall((:GxB_BinaryOp_ztype, libgraphblas), GrB_Info, (Ptr{GrB_Type}, GrB_BinaryOp), ztype, binaryop)
end
function GxB_BinaryOp_ztype(binaryop)
z = Ref{GrB_Type}()
GxB_BinaryOp_ztype(z, binaryop)
return z[]
end
function GxB_BinaryOp_xtype(xtype, binaryop)
@wraperror ccall((:GxB_BinaryOp_xtype, libgraphblas), GrB_Info, (Ptr{GrB_Type}, GrB_BinaryOp), xtype, binaryop)
end
function GxB_BinaryOp_xtype(binaryop)
x = Ref{GrB_Type}()
GxB_BinaryOp_xtype(x, binaryop)
return x[]
end
function GxB_BinaryOp_ytype(ytype, binaryop)
@wraperror ccall((:GxB_BinaryOp_ytype, libgraphblas), GrB_Info, (Ptr{GrB_Type}, GrB_BinaryOp), ytype, binaryop)
end
function GxB_BinaryOp_ytype(binaryop)
y= Ref{GrB_Type}()
GxB_BinaryOp_ztype(y, binaryop)
return y[]
end
function GrB_BinaryOp_free(binaryop)
@wraperror ccall((:GrB_BinaryOp_free, libgraphblas), GrB_Info, (Ptr{GrB_BinaryOp},), binaryop)
end
mutable struct GB_SelectOp_opaque end
const GxB_SelectOp = Ptr{GB_SelectOp_opaque}
# typedef bool ( * GxB_select_function ) // return true if A(i,j) is kept ( GrB_Index i , // row index of A(i,j) GrB_Index j , // column index of A(i,j) const void * x , // value of A(i,j) const void * thunk // optional input for select function )
const GxB_select_function = Ptr{Cvoid}
function GB_SelectOp_new(selectop, _function, xtype, ttype, name)
@wraperror ccall((:GB_SelectOp_new, libgraphblas), GrB_Info, (Ptr{GxB_SelectOp}, GxB_select_function, GrB_Type, GrB_Type, Ptr{Cchar}), selectop, _function, xtype, ttype, name)
end
function GxB_SelectOp_xtype(xtype, selectop)
@wraperror ccall((:GxB_SelectOp_xtype, libgraphblas), GrB_Info, (Ptr{GrB_Type}, GxB_SelectOp), xtype, selectop)
end
function GxB_SelectOp_ttype(ttype, selectop)
@wraperror ccall((:GxB_SelectOp_ttype, libgraphblas), GrB_Info, (Ptr{GrB_Type}, GxB_SelectOp), ttype, selectop)
end
function GxB_SelectOp_free(selectop)
@wraperror ccall((:GxB_SelectOp_free, libgraphblas), GrB_Info, (Ptr{GxB_SelectOp},), selectop)
end
mutable struct GB_Monoid_opaque end
const GrB_Monoid = Ptr{GB_Monoid_opaque}
const monoididnew = Dict{DataType, Function}()
function GrB_Monoid_new_BOOL(monoid, op, identity)
@wraperror ccall((:GrB_Monoid_new_BOOL, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Bool), monoid, op, identity)
end
monoididnew[Bool] = GrB_Monoid_new_BOOL
function GrB_Monoid_new_INT8(monoid, op, identity)
@wraperror ccall((:GrB_Monoid_new_INT8, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Int8), monoid, op, identity)
end
monoididnew[Int8] = GrB_Monoid_new_INT8
function GrB_Monoid_new_UINT8(monoid, op, identity)
@wraperror ccall((:GrB_Monoid_new_UINT8, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, UInt8), monoid, op, identity)
end
monoididnew[UInt8] = GrB_Monoid_new_UINT8
function GrB_Monoid_new_INT16(monoid, op, identity)
@wraperror ccall((:GrB_Monoid_new_INT16, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Int16), monoid, op, identity)
end
monoididnew[Int16] = GrB_Monoid_new_INT16
function GrB_Monoid_new_UINT16(monoid, op, identity)
@wraperror ccall((:GrB_Monoid_new_UINT16, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, UInt16), monoid, op, identity)
end
monoididnew[UInt16] = GrB_Monoid_new_UINT16
function GrB_Monoid_new_INT32(monoid, op, identity)
@wraperror ccall((:GrB_Monoid_new_INT32, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Int32), monoid, op, identity)
end
monoididnew[Int32] = GrB_Monoid_new_INT32
function GrB_Monoid_new_UINT32(monoid, op, identity)
@wraperror ccall((:GrB_Monoid_new_UINT32, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, UInt32), monoid, op, identity)
end
monoididnew[UInt32] = GrB_Monoid_new_UINT32
function GrB_Monoid_new_INT64(monoid, op, identity)
@wraperror ccall((:GrB_Monoid_new_INT64, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Int64), monoid, op, identity)
end
monoididnew[Int64] = GrB_Monoid_new_INT64
function GrB_Monoid_new_UINT64(monoid, op, identity)
@wraperror ccall((:GrB_Monoid_new_UINT64, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, UInt64), monoid, op, identity)
end
monoididnew[UInt64] = GrB_Monoid_new_UINT64
function GrB_Monoid_new_FP32(monoid, op, identity)
@wraperror ccall((:GrB_Monoid_new_FP32, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Cfloat), monoid, op, identity)
end
monoididnew[Float32] = GrB_Monoid_new_FP32
function GrB_Monoid_new_FP64(monoid, op, identity)
@wraperror ccall((:GrB_Monoid_new_FP64, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Cdouble), monoid, op, identity)
end
monoididnew[Float64] = GrB_Monoid_new_FP64
function GxB_Monoid_new_FC32(monoid, op, identity)
@wraperror ccall((:GxB_Monoid_new_FC32, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, GxB_FC32_t), monoid, op, identity)
end
monoididnew[ComplexF32] = GxB_Monoid_new_FC32
function GxB_Monoid_new_FC64(monoid, op, identity)
@wraperror ccall((:GxB_Monoid_new_FC64, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, GxB_FC64_t), monoid, op, identity)
end
monoididnew[ComplexF64] = GxB_Monoid_new_FC64
function GrB_Monoid_new_UDT(monoid, op, identity)
@wraperror ccall((:GrB_Monoid_new_UDT, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Ptr{Cvoid}), monoid, op, identity)
end
monoididnew[Any] = GrB_Monoid_new_UDT
const monoidtermnew = Dict{DataType, Function}()
function GxB_Monoid_terminal_new_BOOL(monoid, op, identity, terminal)
@wraperror ccall((:GxB_Monoid_terminal_new_BOOL, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Bool, Bool), monoid, op, identity, terminal)
end
monoidtermnew[Bool] = GxB_Monoid_terminal_new_BOOL
function GxB_Monoid_terminal_new_INT8(monoid, op, identity, terminal)
@wraperror ccall((:GxB_Monoid_terminal_new_INT8, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Int8, Int8), monoid, op, identity, terminal)
end
monoidtermnew[Int8] = GxB_Monoid_terminal_new_INT8
function GxB_Monoid_terminal_new_UINT8(monoid, op, identity, terminal)
@wraperror ccall((:GxB_Monoid_terminal_new_UINT8, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, UInt8, UInt8), monoid, op, identity, terminal)
end
monoidtermnew[UInt8] = GxB_Monoid_terminal_new_UINT8
function GxB_Monoid_terminal_new_INT16(monoid, op, identity, terminal)
@wraperror ccall((:GxB_Monoid_terminal_new_INT16, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Int16, Int16), monoid, op, identity, terminal)
end
monoidtermnew[Int16] = GxB_Monoid_terminal_new_INT16
function GxB_Monoid_terminal_new_UINT16(monoid, op, identity, terminal)
@wraperror ccall((:GxB_Monoid_terminal_new_UINT16, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, UInt16, UInt16), monoid, op, identity, terminal)
end
monoidtermnew[UInt16] = GxB_Monoid_terminal_new_UINT16
function GxB_Monoid_terminal_new_INT32(monoid, op, identity, terminal)
@wraperror ccall((:GxB_Monoid_terminal_new_INT32, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Int32, Int32), monoid, op, identity, terminal)
end
monoidtermnew[Int32] = GxB_Monoid_terminal_new_INT32
function GxB_Monoid_terminal_new_UINT32(monoid, op, identity, terminal)
@wraperror ccall((:GxB_Monoid_terminal_new_UINT32, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, UInt32, UInt32), monoid, op, identity, terminal)
end
monoidtermnew[UInt32] = GxB_Monoid_terminal_new_UINT32
function GxB_Monoid_terminal_new_INT64(monoid, op, identity, terminal)
println(monoid)
println(op)
println(terminal)
println(identity)
@wraperror ccall((:GxB_Monoid_terminal_new_INT64, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Int64, Int64), monoid, op, identity, terminal)
end
monoidtermnew[Int64] = GxB_Monoid_terminal_new_INT64
function GxB_Monoid_terminal_new_UINT64(monoid, op, identity, terminal)
@wraperror ccall((:GxB_Monoid_terminal_new_UINT64, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, UInt64, UInt64), monoid, op, identity, terminal)
end
monoidtermnew[UInt64] = GxB_Monoid_terminal_new_UINT64
function GxB_Monoid_terminal_new_FP32(monoid, op, identity, terminal)
@wraperror ccall((:GxB_Monoid_terminal_new_FP32, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Cfloat, Cfloat), monoid, op, identity, terminal)
end
monoidtermnew[Float32] = GxB_Monoid_terminal_new_FP32
function GxB_Monoid_terminal_new_FP64(monoid, op, identity, terminal)
@wraperror ccall((:GxB_Monoid_terminal_new_FP64, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Cdouble, Cdouble), monoid, op, identity, terminal)
end
monoidtermnew[Float64] = GxB_Monoid_terminal_new_FP64
function GxB_Monoid_terminal_new_FC32(monoid, op, identity, terminal)
@wraperror ccall((:GxB_Monoid_terminal_new_FC32, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, GxB_FC32_t, GxB_FC32_t), monoid, op, identity, terminal)
end
monoidtermnew[ComplexF32] = GxB_Monoid_terminal_new_FC32
function GxB_Monoid_terminal_new_FC64(monoid, op, identity, terminal)
@wraperror ccall((:GxB_Monoid_terminal_new_FC64, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, GxB_FC64_t, GxB_FC64_t), monoid, op, identity, terminal)
end
monoidtermnew[ComplexF64] = GxB_Monoid_terminal_new_FC64
function GxB_Monoid_terminal_new_UDT(monoid, op, identity, terminal)
@wraperror ccall((:GxB_Monoid_terminal_new_UDT, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_BinaryOp, Ptr{Cvoid}, Ptr{Cvoid}), monoid, op, identity, terminal)
end
monoidtermnew[Any] = GxB_Monoid_terminal_new_UDT
function GxB_Monoid_operator(op, monoid)
@wraperror ccall((:GxB_Monoid_operator, libgraphblas), GrB_Info, (Ptr{GrB_BinaryOp}, GrB_Monoid), op, monoid)
end
function GxB_Monoid_operator(monoid)
op = Ref{GrB_BinaryOp}()
GxB_Monoid_operator(op, monoid)
return op[]
end
function GxB_Monoid_identity(identity, monoid)
@wraperror ccall((:GxB_Monoid_identity, libgraphblas), GrB_Info, (Ptr{Cvoid}, GrB_Monoid), identity, monoid)
end
function GxB_Monoid_terminal(T, monoid)
has_terminal = Ref{Bool}()
terminal = Ref{T}()
ccall((:GxB_Monoid_terminal, libgraphblas), GrB_Info, (Ptr{Bool}, Ptr{Cvoid}, GrB_Monoid), has_terminal, terminal, monoid)
has_terminal = has_terminal[]
println(has_terminal)
if has_terminal
return terminal[]
else
return nothing
end
end
function GrB_Monoid_free(monoid)
@wraperror ccall((:GrB_Monoid_free, libgraphblas), GrB_Info, (Ptr{GrB_Monoid},), monoid)
end
mutable struct GB_Semiring_opaque end
const GrB_Semiring = Ptr{GB_Semiring_opaque}
function GrB_Semiring_new(semiring, add, multiply)
@wraperror ccall((:GrB_Semiring_new, libgraphblas), GrB_Info, (Ptr{GrB_Semiring}, GrB_Monoid, GrB_BinaryOp), semiring, add, multiply)
end
function GxB_Semiring_add(add, semiring)
@wraperror ccall((:GxB_Semiring_add, libgraphblas), GrB_Info, (Ptr{GrB_Monoid}, GrB_Semiring), add, semiring)
end
function GxB_Semiring_add(semiring)
m = Ref{GrB_Monoid}()
GxB_Semiring_add(m, semiring)
return m[]
end
function GxB_Semiring_multiply(multiply, semiring)
@wraperror ccall((:GxB_Semiring_multiply, libgraphblas), GrB_Info, (Ptr{GrB_BinaryOp}, GrB_Semiring), multiply, semiring)
end
function GxB_Semiring_multiply(semiring)
m = Ref{GrB_BinaryOp}()
GxB_Semiring_multiply(m, semiring)
return m[]
end
function GrB_Semiring_free(semiring)
@wraperror ccall((:GrB_Semiring_free, libgraphblas), GrB_Info, (Ptr{GrB_Semiring},), semiring)
end
mutable struct GB_Scalar_opaque end
const GxB_Scalar = Ptr{GB_Scalar_opaque}
function GxB_Scalar_new(s, type)
@wraperror ccall((:GxB_Scalar_new, libgraphblas), GrB_Info, (Ptr{GxB_Scalar}, GrB_Type), s, type)
end
function GxB_Scalar_new(type)
s = Ref{GxB_Scalar}()
GxB_Scalar_new(s, type)
return s[]
end
function GxB_Scalar_dup(s, t)
@wraperror ccall((:GxB_Scalar_dup, libgraphblas), GrB_Info, (Ptr{GxB_Scalar}, GxB_Scalar), s, t)
end
function GxB_Scalar_dup(t)
s = Ref{GxB_Scalar}()
GxB_Scalar_dup(s, t)
return s[]
end
function GxB_Scalar_clear(s)
@wraperror ccall((:GxB_Scalar_clear, libgraphblas), GrB_Info, (GxB_Scalar,), s)
return nothing
end
function GxB_Scalar_nvals(nvals, s)
@wraperror ccall((:GxB_Scalar_nvals, libgraphblas), GrB_Info, (Ptr{GrB_Index}, GxB_Scalar), nvals, s)
end
function GxB_Scalar_nvals(s)
nvals = Ref{GrB_Index}()
GxB_Scalar_nvals(nvals, s)
return nvals[]
end
function GxB_Scalar_type(type, s)
@wraperror ccall((:GxB_Scalar_type, libgraphblas), GrB_Info, (Ptr{GrB_Type}, GxB_Scalar), type, s)
end
function GxB_Scalar_type(s)
type = Ref{GrB_Type}()
GxB_Scalar_type(type, s)
return type[]
end
function GxB_Scalar_free(s)
@wraperror ccall((:GxB_Scalar_free, libgraphblas), GrB_Info, (Ptr{GxB_Scalar},), s)
end
function GxB_Scalar_setElement_BOOL(s, x)
@wraperror ccall((:GxB_Scalar_setElement_BOOL, libgraphblas), GrB_Info, (GxB_Scalar, Bool), s, x)
end
function GxB_Scalar_setElement_INT8(s, x)
@wraperror ccall((:GxB_Scalar_setElement_INT8, libgraphblas), GrB_Info, (GxB_Scalar, Int8), s, x)
end
function GxB_Scalar_setElement_UINT8(s, x)
@wraperror ccall((:GxB_Scalar_setElement_UINT8, libgraphblas), GrB_Info, (GxB_Scalar, UInt8), s, x)
end
function GxB_Scalar_setElement_INT16(s, x)
@wraperror ccall((:GxB_Scalar_setElement_INT16, libgraphblas), GrB_Info, (GxB_Scalar, Int16), s, x)
end
function GxB_Scalar_setElement_UINT16(s, x)
@wraperror ccall((:GxB_Scalar_setElement_UINT16, libgraphblas), GrB_Info, (GxB_Scalar, UInt16), s, x)
end
function GxB_Scalar_setElement_INT32(s, x)
@wraperror ccall((:GxB_Scalar_setElement_INT32, libgraphblas), GrB_Info, (GxB_Scalar, Int32), s, x)
end
function GxB_Scalar_setElement_UINT32(s, x)
@wraperror ccall((:GxB_Scalar_setElement_UINT32, libgraphblas), GrB_Info, (GxB_Scalar, UInt32), s, x)
end
function GxB_Scalar_setElement_INT64(s, x)
@wraperror ccall((:GxB_Scalar_setElement_INT64, libgraphblas), GrB_Info, (GxB_Scalar, Int64), s, x)
end
function GxB_Scalar_setElement_UINT64(s, x)
@wraperror ccall((:GxB_Scalar_setElement_UINT64, libgraphblas), GrB_Info, (GxB_Scalar, UInt64), s, x)
end
function GxB_Scalar_setElement_FP32(s, x)
@wraperror ccall((:GxB_Scalar_setElement_FP32, libgraphblas), GrB_Info, (GxB_Scalar, Cfloat), s, x)
end
function GxB_Scalar_setElement_FP64(s, x)
@wraperror ccall((:GxB_Scalar_setElement_FP64, libgraphblas), GrB_Info, (GxB_Scalar, Cdouble), s, x)
end
function GxB_Scalar_setElement_FC32(s, x)
@wraperror ccall((:GxB_Scalar_setElement_FC32, libgraphblas), GrB_Info, (GxB_Scalar, GxB_FC32_t), s, x)
end
function GxB_Scalar_setElement_FC64(s, x)
@wraperror ccall((:GxB_Scalar_setElement_FC64, libgraphblas), GrB_Info, (GxB_Scalar, GxB_FC64_t), s, x)
end
function GxB_Scalar_setElement_UDT(s, x)
@wraperror ccall((:GxB_Scalar_setElement_UDT, libgraphblas), GrB_Info, (GxB_Scalar, Ptr{Cvoid}), s, x)
end
function GxB_Scalar_extractElement_BOOL(x, s)
ccall((:GxB_Scalar_extractElement_BOOL, libgraphblas), GrB_Info, (Ptr{Bool}, GxB_Scalar), x, s)
end
function GxB_Scalar_extractElement_BOOL(s)
x = Ref{Bool}()
GxB_Scalar_extractElement_BOOL(x, s)
return x[]
end
function GxB_Scalar_extractElement_INT8(x, s)
ccall((:GxB_Scalar_extractElement_INT8, libgraphblas), GrB_Info, (Ptr{Int8}, GxB_Scalar), x, s)
end
function GxB_Scalar_extractElement_INT8(s)
x = Ref{Int8}()
GxB_Scalar_extractElement_INT8(x, s)
return x[]
end
function GxB_Scalar_extractElement_UINT8(x, s)
ccall((:GxB_Scalar_extractElement_UINT8, libgraphblas), GrB_Info, (Ptr{UInt8}, GxB_Scalar), x, s)
end
function GxB_Scalar_extractElement_UINT8(s)
x = Ref{UInt8}()
GxB_Scalar_extractElement_UINT8(x, s)
return x[]
end
function GxB_Scalar_extractElement_INT16(x, s)
ccall((:GxB_Scalar_extractElement_INT16, libgraphblas), GrB_Info, (Ptr{Int16}, GxB_Scalar), x, s)
end
function GxB_Scalar_extractElement_INT16(s)
x = Ref{Int16}()
GxB_Scalar_extractElement_INT16(x, s)
return x[]
end
function GxB_Scalar_extractElement_UINT16(x, s)
ccall((:GxB_Scalar_extractElement_UINT16, libgraphblas), GrB_Info, (Ptr{UInt16}, GxB_Scalar), x, s)
end
function GxB_Scalar_extractElement_UINT16(s)
x = Ref{UInt16}()
GxB_Scalar_extractElement_UINT16(x, s)
return x[]
end
function GxB_Scalar_extractElement_INT32(x, s)
ccall((:GxB_Scalar_extractElement_INT32, libgraphblas), GrB_Info, (Ptr{Int32}, GxB_Scalar), x, s)
end
function GxB_Scalar_extractElement_INT32(s)
x = Ref{Int32}()
GxB_Scalar_extractElement_INT32(x, s)
return x[]
end
function GxB_Scalar_extractElement_UINT32(x, s)
ccall((:GxB_Scalar_extractElement_UINT32, libgraphblas), GrB_Info, (Ptr{UInt32}, GxB_Scalar), x, s)
end
function GxB_Scalar_extractElement_UINT32(s)
x = Ref{UInt32}()
GxB_Scalar_extractElement_UINT32(x, s)
return x[]
end
function GxB_Scalar_extractElement_INT64(x, s)
ccall((:GxB_Scalar_extractElement_INT64, libgraphblas), GrB_Info, (Ptr{Int64}, GxB_Scalar), x, s)
end
function GxB_Scalar_extractElement_INT64(s)
x = Ref{Int64}()
GxB_Scalar_extractElement_INT64(x, s)
return x[]
end
function GxB_Scalar_extractElement_UINT64(x, s)
ccall((:GxB_Scalar_extractElement_UINT64, libgraphblas), GrB_Info, (Ptr{UInt64}, GxB_Scalar), x, s)
end
function GxB_Scalar_extractElement_UINT64(s)
x = Ref{UInt64}()
GxB_Scalar_extractElement_UINT64(x, s)
return x[]
end
function GxB_Scalar_extractElement_FP32(x, s)
ccall((:GxB_Scalar_extractElement_FP32, libgraphblas), GrB_Info, (Ptr{Cfloat}, GxB_Scalar), x, s)
end
function GxB_Scalar_extractElement_FP32(s)
x = Ref{Float32}()
GxB_Scalar_extractElement_FP32(x, s)
return x[]
end
function GxB_Scalar_extractElement_FP64(x, s)
ccall((:GxB_Scalar_extractElement_FP64, libgraphblas), GrB_Info, (Ptr{Cdouble}, GxB_Scalar), x, s)
end
function GxB_Scalar_extractElement_FP64(s)
x = Ref{Float64}()
GxB_Scalar_extractElement_FP64(x, s)
return x[]
end
function GxB_Scalar_extractElement_FC32(x, s)
ccall((:GxB_Scalar_extractElement_FC32, libgraphblas), GrB_Info, (Ptr{GxB_FC32_t}, GxB_Scalar), x, s)
end
function GxB_Scalar_extractElement_FC32(s)
x = Ref{ComplexF32}()
GxB_Scalar_extractElement_FC32(x, s)
return x[]
end
function GxB_Scalar_extractElement_FC64(x, s)
ccall((:GxB_Scalar_extractElement_FC64, libgraphblas), GrB_Info, (Ptr{GxB_FC64_t}, GxB_Scalar), x, s)
end
function GxB_Scalar_extractElement_FC64(s)
x = Ref{ComplexF64}()
GxB_Scalar_extractElement_FC64(x, s)
return x[]
end
function GxB_Scalar_extractElement_UDT(x, s)
ccall((:GxB_Scalar_extractElement_UDT, libgraphblas), GrB_Info, (Ptr{Cvoid}, GxB_Scalar), x, s)
end
mutable struct GB_Vector_opaque end
const GrB_Vector = Ptr{GB_Vector_opaque}
function GrB_Vector_new(v, type, n)
@wraperror ccall((:GrB_Vector_new, libgraphblas), GrB_Info, (Ptr{GrB_Vector}, GrB_Type, GrB_Index), v, type, n)
end
function GrB_Vector_new(type, n)
v = Ref{GrB_Vector}()
GrB_Vector_new(v, type, n)
return v[]
end
function GrB_Vector_dup(w, u)
@wraperror ccall((:GrB_Vector_dup, libgraphblas), GrB_Info, (Ptr{GrB_Vector}, GrB_Vector), w, u)
end
function GrB_Vector_dup(u)
w = Ref{GrB_Vector}()
GrB_Vector_new(w, GxB_Vector_type(u), GrB_Vector_size(u))
GrB_Vector_dup(w, u)
return w[]
end
function GrB_Vector_clear(v)
@wraperror ccall((:GrB_Vector_clear, libgraphblas), GrB_Info, (GrB_Vector,), v)
return nothing
end
function GrB_Vector_size(n, v)
@wraperror ccall((:GrB_Vector_size, libgraphblas), GrB_Info, (Ptr{GrB_Index}, GrB_Vector), n, v)
end
function GrB_Vector_size(v)
n = Ref{GrB_Index}()
GrB_Vector_size(n, v)
return n[]
end
function GrB_Vector_nvals(nvals, v)
@wraperror ccall((:GrB_Vector_nvals, libgraphblas), GrB_Info, (Ptr{GrB_Index}, GrB_Vector), nvals, v)
end
function GrB_Vector_nvals(v)
nvals = Ref{GrB_Index}()
GrB_Vector_nvals(nvals, v)
return nvals[]
end
function GxB_Vector_type(type, v)
@wraperror ccall((:GxB_Vector_type, libgraphblas), GrB_Info, (Ptr{GrB_Type}, GrB_Vector), type, v)
end
function GxB_Vector_type(v)
type = Ref{GrB_Type}()
GxB_Vector_type(type, v)
return type[]
end
function GrB_Vector_free(v)
@wraperror ccall((:GrB_Vector_free, libgraphblas), GrB_Info, (Ptr{GrB_Vector},), v)
end
function GrB_Vector_build_UDT(w, I, X, nvals, dup)
@wraperror ccall((:GrB_Vector_build_UDT, libgraphblas), GrB_Info, (GrB_Vector, Ptr{GrB_Index}, Ptr{Cvoid}, GrB_Index, GrB_BinaryOp), w, I, X, nvals, dup)
end
function GxB_Vector_build_Scalar(w, I, scalar, nvals)
I = tozerobased(I)
@wraperror ccall((:GxB_Vector_build_Scalar, libgraphblas), GrB_Info, (GrB_Vector, Ptr{GrB_Index}, GxB_Scalar, GrB_Index), w, I, scalar, nvals)
end
function GrB_Vector_setElement_UDT(w, x, i)
@wraperror ccall((:GrB_Vector_setElement_UDT, libgraphblas), GrB_Info, (GrB_Vector, Ptr{Cvoid}, GrB_Index), w, x, i)
end
function GrB_Vector_extractElement_UDT(x, v, i)
ccall((:GrB_Vector_extractElement_UDT, libgraphblas), GrB_Info, (Ptr{Cvoid}, GrB_Vector, GrB_Index), x, v, i)
end
function GrB_Vector_removeElement(v, i)
i = tozerobased(i)
@wraperror ccall((:GrB_Vector_removeElement, libgraphblas), GrB_Info, (GrB_Vector, GrB_Index), v, i)
end
#Generate functions for Vector_extractElement and Vector_extractTuples.
#Both have multiple forms, the second creates its own output( vectors) and returns them.
for T ∈ valid_vec
if T ∈ [ComplexF32, ComplexF64]
prefix = :GxB
else
prefix = :GrB
end
type = towrappertype(T)
# GrB_Vector_build_* Functions:
func = Symbol(prefix, :_Vector_build_, suffix(T))
funcstr = string(func)
@eval begin
function $func(w, I, X, nvals, dup)
I = tozerobased(I) #Switch to 0-based indexing at ccall barrier
@wraperror ccall(($funcstr, libgraphblas), GrB_Info, (GrB_Vector, Ptr{GrB_Index}, Ptr{$type}, GrB_Index, GrB_BinaryOp), w, I, X, nvals, dup)
end
end
# GrB_Vector_setElement* Functions:
func = Symbol(prefix, :_Vector_setElement_, suffix(T))
funcstr = string(func)
@eval begin
function $func(w, x, i)
i = tozerobased(i) #Switch to 0-based indexing at ccall barrier
@wraperror ccall(($funcstr, libgraphblas), GrB_Info, (GrB_Vector, $type, GrB_Index), w, x, i)
end
end
# GrB_Vector_extractElement Functions:
func = Symbol(prefix, :_Vector_extractElement_, suffix(T))
funcstr = string(func)
@eval begin
function $func(x, v, i)
i = tozerobased(i) #Switch to 0-based indexing at ccall barrier
ccall(($funcstr, libgraphblas), GrB_Info, (Ptr{$type}, GrB_Vector, GrB_Index), x, v, i)
end
function $func(v, i)
x = Ref{$T}()
result = $func(x, v, i)
if result == GrB_SUCCESS
return x[]
elseif result == GrB_NO_VALUE
return nothing
else
throw(ErrorException("Invalid extractElement return value."))
end
end
end
# GrB_Vector_extractTuples functions:
func = Symbol(prefix, :_Vector_extractTuples_, suffix(T))
funcstr = string(func)
@eval begin
function $func(I, X, nvals, v)
#I, X, and nvals are outputs
@wraperror ccall(($funcstr, libgraphblas), GrB_Info, (Ptr{GrB_Index}, Ptr{$T}, Ptr{GrB_Index}, GrB_Vector), I, X, nvals, v)
#I .+= 1 #Back to 1-based indexing after ccall
end
function $func(v)
nvals = GrB_Vector_nvals(v)
I = Vector{GrB_Index}(undef, nvals)
X = Vector{$type}(undef, nvals)
nvals = Ref{GrB_Index}(nvals)
$func(I, X, nvals, v)
nvals[] == length(I) == length(X) || throw(DimensionMismatch())
return I .+ 1, X
end
end
end
function GrB_Vector_extractTuples_UDT(I, X, nvals, v)
@wraperror ccall((:GrB_Vector_extractTuples_UDT, libgraphblas), GrB_Info, (Ptr{GrB_Index}, Ptr{Cvoid}, Ptr{GrB_Index}, GrB_Vector), I, X, nvals, v)
end
mutable struct GB_Matrix_opaque end
const GrB_Matrix = Ptr{GB_Matrix_opaque}
function GrB_Matrix_new(A, type, nrows, ncols)
@wraperror ccall((:GrB_Matrix_new, libgraphblas), GrB_Info, (Ptr{GrB_Matrix}, GrB_Type, GrB_Index, GrB_Index), A, type, nrows, ncols)
end
function GrB_Matrix_new(type, nrows, ncols)
m = Ref{GrB_Matrix}()
GrB_Matrix_new(m, type, nrows, ncols)
return m[]
end
function GrB_Matrix_dup(C, A)
@wraperror ccall((:GrB_Matrix_dup, libgraphblas), GrB_Info, (Ptr{GrB_Matrix}, GrB_Matrix), C, A)
end
function GrB_Matrix_dup(A)
C = Ref{GrB_Matrix}()
GrB_Matrix_new(C, GxB_Matrix_type(A), GrB_Matrix_nrows(A), GrB_Matrix_ncols(A))
GrB_Matrix_dup(C, A)
return C[]
end
function GrB_Matrix_clear(A)
@wraperror ccall((:GrB_Matrix_clear, libgraphblas), GrB_Info, (GrB_Matrix,), A)
return nothing
end
function GrB_Matrix_nrows(nrows, A)
@wraperror ccall((:GrB_Matrix_nrows, libgraphblas), GrB_Info, (Ptr{GrB_Index}, GrB_Matrix), nrows, A)
end
function GrB_Matrix_nrows(A)
nrows = Ref{GrB_Index}()
GrB_Matrix_nrows(nrows, A)
return nrows[]
end
function GrB_Matrix_ncols(ncols, A)
@wraperror ccall((:GrB_Matrix_ncols, libgraphblas), GrB_Info, (Ptr{GrB_Index}, GrB_Matrix), ncols, A)
end
function GrB_Matrix_ncols(A)
ncols = Ref{GrB_Index}()
GrB_Matrix_ncols(ncols, A)
return ncols[]
end
function GrB_Matrix_nvals(nvals, A)
@wraperror ccall((:GrB_Matrix_nvals, libgraphblas), GrB_Info, (Ptr{GrB_Index}, GrB_Matrix), nvals, A)
end
function GrB_Matrix_nvals(A)
nvals = Ref{GrB_Index}()
GrB_Matrix_nvals(nvals, A)
return nvals[]
end
function GxB_Matrix_type(type, A)
@wraperror ccall((:GxB_Matrix_type, libgraphblas), GrB_Info, (Ptr{GrB_Type}, GrB_Matrix), type, A)
end
function GxB_Matrix_type(A)
type = Ref{GrB_Type}()
GxB_Matrix_type(type, A)
return type[]
end
function GrB_Matrix_free(A)
@wraperror ccall((:GrB_Matrix_free, libgraphblas), GrB_Info, (Ptr{GrB_Matrix},), A)
end
for T ∈ valid_vec
if T ∈ [ComplexF32, ComplexF64]
prefix = :GxB
else
prefix = :GrB
end
type = towrappertype(T)
# GrB_Matrix_build_* Functions:
func = Symbol(prefix, :_Matrix_build_, suffix(T))
funcstr = string(func)
@eval begin
function $func(C, I, J, X, nvals, dup)
I = tozerobased(I) #Switch to 0-based indexing at ccall barrier
J = tozerobased(J)
@wraperror ccall(($funcstr, libgraphblas), GrB_Info, (GrB_Matrix, Ptr{GrB_Index}, Ptr{GrB_Index}, Ptr{$type}, GrB_Index, GrB_BinaryOp), C, I, J, X, nvals, dup)
end
end
# GrB_Matrix_setElement* Functions:
func = Symbol(prefix, :_Matrix_setElement_, suffix(T))
funcstr = string(func)
@eval begin
function $func(C, x, i, j)
i = tozerobased(i) #Switch to 0-based indexing at ccall barrier
j = tozerobased(j)
@wraperror ccall(($funcstr, libgraphblas), GrB_Info, (GrB_Matrix, $type, GrB_Index, GrB_Index), C, x, i, j)
end
end
# GrB_Matrix_extractElement Functions:
func = Symbol(prefix, :_Matrix_extractElement_, suffix(T))
funcstr = string(func)
@eval begin
function $func(x, A, i, j)
i = tozerobased(i) #Switch to 0-based indexing at ccall barrier
j = tozerobased(j)
return ccall(($funcstr, libgraphblas), GrB_Info, (Ptr{$type}, GrB_Matrix, GrB_Index, GrB_Index), x, A, i, j)
end
function $func(A, i, j)
x = Ref{$T}()
result = $func(x, A, i, j)
if result == GrB_SUCCESS
return x[]
elseif result == GrB_NO_VALUE
nothing
else
throw(ErrorException("Invalid return from Matrix_extractElement"))
end
end
end
# GrB_Matrix_extractTuples functions:
func = Symbol(prefix, :_Matrix_extractTuples_, suffix(T))
funcstr = string(func)
@eval begin
function $func(I, J, X, nvals, A)
#I, X, and nvals are output
@wraperror ccall(
($funcstr, libgraphblas),
GrB_Info,
(Ptr{GrB_Index}, Ptr{GrB_Index}, Ptr{$type}, Ptr{GrB_Index}, GrB_Matrix),
I, J, X, nvals, A
)
end
function $func(A)
nvals = GrB_Matrix_nvals(A)
I = Vector{GrB_Index}(undef, nvals)
J = Vector{GrB_Index}(undef, nvals)
X = Vector{$type}(undef, nvals)
nvals = Ref{GrB_Index}(nvals)
$func(I, J, X, nvals, A)