| 28 | //------------------------------------------------------------------------------ |
| 29 | |
| 30 | GB_PUBLIC |
| 31 | GrB_Info random_matrix // create a random double-precision matrix |
| 32 | ( |
| 33 | GrB_Matrix *A_output, // handle of matrix to create |
| 34 | bool make_symmetric, // if true, return A as symmetric |
| 35 | bool no_self_edges, // if true, then do not create self edges |
| 36 | int64_t nrows, // number of rows |
| 37 | int64_t ncols, // number of columns |
| 38 | int64_t nedges, // number of edges |
| 39 | int method, // method to use: 0:setElement, 1:build, |
| 40 | bool A_complex // if true, create a Complex matrix |
| 41 | ) |
| 42 | { |
| 43 | GrB_Matrix Areal = NULL, Aimag = NULL, A = NULL ; |
| 44 | *A_output = NULL ; |
| 45 | GrB_Index *I = NULL, *J = NULL ; |
| 46 | double *X = NULL ; |
| 47 | GrB_Info info ; |
| 48 | |
| 49 | if (make_symmetric) |
| 50 | { |
| 51 | nrows = MAX (nrows, ncols) ; |
| 52 | ncols = MAX (nrows, ncols) ; |
| 53 | } |
| 54 | |
| 55 | //-------------------------------------------------------------------------- |
| 56 | // create a Complex matrix |
| 57 | //-------------------------------------------------------------------------- |
| 58 | |
| 59 | if (A_complex) |
| 60 | { |
| 61 | // Areal = real random matrix |
| 62 | OK (random_matrix (&Areal, make_symmetric, no_self_edges, nrows, |
| 63 | ncols, nedges, method, false)) ; |
| 64 | OK (GxB_Matrix_fprint (Areal, "random real part", GxB_SHORT, stderr)) ; |
| 65 | // Aimag = real random matrix |
| 66 | OK (random_matrix (&Aimag, make_symmetric, no_self_edges, nrows, |
| 67 | ncols, nedges, method, false)) ; |
| 68 | OK (GxB_Matrix_fprint (Aimag, "random imag part", GxB_SHORT, stderr)) ; |
| 69 | // A = Areal + imag(Aimag) |
| 70 | OK (GrB_Matrix_new (&A, Complex, nrows, ncols)) ; |
| 71 | OK (GrB_Matrix_apply (A, NULL, NULL, Complex_complex_real, |
| 72 | Areal, NULL)) ; |
| 73 | OK (GrB_Matrix_apply (A, NULL, Complex_plus, Complex_complex_imag, |
| 74 | Aimag, NULL)) ; |
| 75 | *A_output = A ; |
| 76 | A = NULL ; |
| 77 | FREE_ALL ; |
| 78 | return (GrB_SUCCESS) ; |
| 79 | } |
| 80 | |
| 81 | //-------------------------------------------------------------------------- |
| 82 | // create a real double matrix (GrB_FP64) |
| 83 | //-------------------------------------------------------------------------- |
| 84 | |
| 85 | OK (GrB_Matrix_new (&A, GrB_FP64, nrows, ncols)) ; |
| 86 | |
| 87 | if (method == 0) |
no test coverage detected