File: GB_mex_test15.c

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (220 lines) | stat: -rw-r--r-- 7,403 bytes parent folder | download | duplicates (2)
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
//------------------------------------------------------------------------------
// GB_mex_test15: JIT error handling
//------------------------------------------------------------------------------

// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//------------------------------------------------------------------------------

#include "GB_mex.h"
#include "GB_mex_errors.h"

#define FREE_ALL ;
#define GET_DEEP_COPY ;
#define FREE_DEEP_COPY ;

void mexFunction
(
    int nargout,
    mxArray *pargout [ ],
    int nargin,
    const mxArray *pargin [ ]
)
{

    //--------------------------------------------------------------------------
    // startup GraphBLAS
    //--------------------------------------------------------------------------

    GrB_Info info ;
    bool malloc_debug = GB_mx_get_global (true) ;

    //--------------------------------------------------------------------------
    // create some valid matrices
    //--------------------------------------------------------------------------

    uint64_t n = 4 ;
    GrB_Matrix A = NULL, B = NULL, F = NULL, C = NULL, D = NULL, G = NULL,
        S = NULL, H = NULL, F2 = NULL, F3 = NULL ;
    OK (GrB_Matrix_new (&A, GrB_FP32, n, n)) ;
    OK (GrB_Matrix_new (&C, GrB_FP32, n, n)) ;
    OK (GrB_Matrix_new (&B, GrB_FP32, n, n)) ;
    OK (GrB_Matrix_new (&D, GrB_FP32, n, n)) ;
    OK (GrB_Matrix_new (&F, GrB_FP32, n, n)) ;
    OK (GrB_Matrix_new (&F2, GrB_FP32, n, n)) ;
    OK (GrB_Matrix_new (&G, GrB_FP32, 2*n, 2*n)) ;
    OK (GrB_Matrix_new (&S, GrB_FP32, 200, 200)) ;
    OK (GrB_Matrix_new (&H, GrB_FP32, 400, 400)) ;
    OK (GxB_set (A, GxB_SPARSITY_CONTROL, GxB_SPARSE)) ;
    OK (GxB_set (B, GxB_SPARSITY_CONTROL, GxB_BITMAP)) ;
    OK (GxB_set (D, GxB_SPARSITY_CONTROL, GxB_SPARSE)) ;
    OK (GxB_set (H, GxB_SPARSITY_CONTROL, GxB_SPARSE)) ;
    OK (GxB_set (F, GxB_SPARSITY_CONTROL, GxB_FULL)) ;
    OK (GxB_set (F2, GxB_SPARSITY_CONTROL, GxB_FULL)) ;
    OK (GrB_assign (A, NULL, NULL, 1, GrB_ALL, n, GrB_ALL, n, NULL)) ;
    OK (GrB_assign (B, NULL, NULL, 1, GrB_ALL, n, GrB_ALL, n, NULL)) ;
    OK (GrB_assign (F, NULL, NULL, 1, GrB_ALL, n, GrB_ALL, n, NULL)) ;
    OK (GrB_assign (F2, NULL, NULL, 1, GrB_ALL, n, GrB_ALL, n, NULL)) ;
    OK (GrB_Matrix_setElement (A, 0, 0, 0)) ;
    OK (GrB_Matrix_setElement (B, 0, 0, 0)) ;
    OK (GrB_Matrix_setElement (F, 0, 0, 0)) ;
    OK (GrB_Matrix_setElement (F2, 0, 0, 0)) ;
    OK (GrB_Matrix_setElement (S, 2, 10, 4)) ;
    for (int i = 0 ; i < 200 ; i++)
    {
        OK (GrB_Matrix_setElement (S, 3, i, i)) ;
    }
    OK (GrB_select (D, NULL, NULL, GrB_DIAG, A, 0, NULL)) ;
    OK (GrB_Matrix_dup (&F3, F2)) ;
    OK (GrB_Matrix_wait (A, GrB_MATERIALIZE)) ;
    OK (GrB_Matrix_wait (B, GrB_MATERIALIZE)) ;
    OK (GrB_Matrix_wait (C, GrB_MATERIALIZE)) ;
    OK (GrB_Matrix_wait (F, GrB_MATERIALIZE)) ;
    OK (GrB_Matrix_wait (F2, GrB_MATERIALIZE)) ;
    OK (GrB_Matrix_wait (F3, GrB_MATERIALIZE)) ;
    OK (GrB_Matrix_wait (D, GrB_MATERIALIZE)) ;
    OK (GrB_Matrix_wait (G, GrB_MATERIALIZE)) ;
    OK (GrB_Matrix_wait (H, GrB_MATERIALIZE)) ;
    OK (GrB_Matrix_wait (S, GrB_MATERIALIZE)) ;

    //--------------------------------------------------------------------------
    // set the JIT to ON, and the Factory Kernels off, then disable the JIT
    //--------------------------------------------------------------------------

    int save_control ;
    bool save_factory = GB_factory_kernels_enabled ;
    GB_factory_kernels_enabled = false ;
    OK (GxB_Global_Option_get_INT32 (GxB_JIT_C_CONTROL, &save_control)) ;
    OK (GxB_Global_Option_set_INT32 (GxB_JIT_C_CONTROL, GxB_JIT_ON)) ;
    GB_Global_hack_set (3, 1) ;     // JIT will return GrB_NOT_IMPLEMENTED

    //--------------------------------------------------------------------------
    // try some methods that require the JIT
    //--------------------------------------------------------------------------

    OK (GxB_set (GxB_BURBLE, true)) ;
    GrB_Semiring s = GrB_PLUS_TIMES_SEMIRING_FP32 ;
    GrB_BinaryOp add = GrB_PLUS_FP32 ;
    GrB_Monoid mon = GrB_PLUS_MONOID_FP32 ;

    GrB_Info expected = GrB_NOT_IMPLEMENTED ;

    // dot2
    ERR (GrB_mxm (C, NULL, NULL, s, A, A, GrB_DESC_T0)) ;

    // dot3
    ERR (GrB_mxm (C, A, NULL, s, A, A, GrB_DESC_T0)) ;

    // saxpy3
    ERR (GrB_mxm (C, NULL, NULL, s, A, A, NULL)) ;

    // saxpy4
    ERR (GrB_mxm (F2, NULL, add, s, A, F, NULL)) ;

    // saxpy5
    ERR (GrB_mxm (F3, NULL, add, s, F, A, NULL)) ;

    // row scale
    ERR (GrB_mxm (C, NULL, NULL, s, D, A, NULL)) ;

    // col scale
    ERR (GrB_mxm (C, NULL, NULL, s, A, D, NULL)) ;

    // saxbit
    ERR (GrB_mxm (C, NULL, NULL, s, B, B, NULL)) ;

    // add
    ERR (GrB_eWiseAdd (C, NULL, NULL, add, A, A, NULL)) ;

    // emult 08
    ERR (GrB_eWiseMult (C, NULL, NULL, add, A, A, NULL)) ;

    // emult 02
    ERR (GrB_eWiseMult (C, NULL, NULL, add, A, F, NULL)) ;

    // emult 03
    ERR (GrB_eWiseMult (C, NULL, NULL, GrB_DIV_FP32, F, A, NULL)) ;

    // emult 04
    ERR (GrB_eWiseMult (C, D, NULL, add, F, B, NULL)) ;

    // emult bitmap
    ERR (GrB_eWiseMult (C, NULL, NULL, add, B, B, NULL)) ;

    // reduce
    float x = 0 ;
    ERR (GrB_reduce (&x, NULL, mon, A, NULL)) ;

    // select (convert sparse to bitmap)
    ERR (GrB_select (C, NULL, NULL, GrB_DIAG, A, 0, NULL)) ;

    // select sparse
    ERR (GrB_select (C, NULL, NULL, GrB_VALUENE_FP32, D, 0, NULL)) ;

    // select bitmap
    ERR (GrB_select (C, NULL, NULL, GrB_VALUENE_FP32, B, 0, NULL)) ;

    // concat full
    GrB_Matrix Tiles [4] ;
    Tiles [0] = F ;
    Tiles [1] = F ;
    Tiles [2] = F ;
    Tiles [3] = F ;
    ERR (GxB_Matrix_concat (G, Tiles, 2, 2, NULL)) ;

    // concat sparse
    Tiles [0] = S ;
    Tiles [1] = S ;
    Tiles [2] = S ;
    Tiles [3] = S ;
    ERR (GxB_Matrix_concat (H, Tiles, 2, 2, NULL)) ;

    // concat bitmap
    Tiles [0] = B ;
    Tiles [1] = B ;
    Tiles [2] = B ;
    Tiles [3] = B ;
    GrB_free (&G) ;
    OK (GrB_Matrix_new (&G, GrB_FP32, 2*n, 2*n)) ;
    ERR (GxB_Matrix_concat (G, Tiles, 2, 2, NULL)) ;

    // split full
    uint64_t Tile_rows [2] = {2, 2} ;
    uint64_t Tile_cols [2] = {2, 2} ;
    ERR (GxB_Matrix_split (Tiles, 2, 2, Tile_rows, Tile_cols, F, NULL)) ;

    // split sparse
    ERR (GxB_Matrix_split (Tiles, 2, 2, Tile_rows, Tile_cols, A, NULL)) ;

    // split bitmap
    ERR (GxB_Matrix_split (Tiles, 2, 2, Tile_rows, Tile_cols, B, NULL)) ;

    //--------------------------------------------------------------------------
    // restore the JIT control, Factory Kernels, and renable the JIT
    //--------------------------------------------------------------------------

    OK (GxB_set (GxB_BURBLE, false)) ;
    OK (GxB_Global_Option_set_INT32 (GxB_JIT_C_CONTROL, save_control)) ;
    GB_factory_kernels_enabled = save_factory ;
    GB_Global_hack_set (3, 0) ;

    //--------------------------------------------------------------------------
    // finalize GraphBLAS
    //--------------------------------------------------------------------------

    GrB_free (&A) ;
    GrB_free (&B) ;
    GrB_free (&C) ;
    GrB_free (&D) ;
    GrB_free (&F) ;
    GrB_free (&G) ;
    GrB_free (&H) ;
    GrB_free (&S) ;
    GrB_free (&F2) ;
    GrB_free (&F3) ;

    GB_mx_put_global (true) ;
    printf ("\nGB_mex_test15:  all tests passed\n\n") ;
}