| 15 | #include "GB.h" |
| 16 | |
| 17 | GrB_Info GB_Matrix_new // create a new matrix with no entries |
| 18 | ( |
| 19 | GrB_Matrix *A, // handle of matrix to create |
| 20 | GrB_Type type, // type of matrix to create |
| 21 | GrB_Index nrows, // matrix dimension is nrows-by-ncols |
| 22 | GrB_Index ncols, |
| 23 | GB_Context Context |
| 24 | ) |
| 25 | { |
| 26 | |
| 27 | //-------------------------------------------------------------------------- |
| 28 | // check inputs |
| 29 | //-------------------------------------------------------------------------- |
| 30 | |
| 31 | GB_RETURN_IF_NULL (A) ; |
| 32 | (*A) = NULL ; |
| 33 | GB_RETURN_IF_NULL_OR_FAULTY (type) ; |
| 34 | |
| 35 | if (nrows > GB_NMAX || ncols > GB_NMAX) |
| 36 | { |
| 37 | // problem too large |
| 38 | return (GrB_INVALID_VALUE) ; |
| 39 | } |
| 40 | |
| 41 | //-------------------------------------------------------------------------- |
| 42 | // create the matrix |
| 43 | //-------------------------------------------------------------------------- |
| 44 | |
| 45 | int64_t vlen, vdim ; |
| 46 | bool A_is_csc ; |
| 47 | if (ncols == 1) |
| 48 | { |
| 49 | // n-by-1 matrices are always held by column, including 1-by-1 |
| 50 | A_is_csc = true ; |
| 51 | } |
| 52 | else if (nrows == 1) |
| 53 | { |
| 54 | // 1-by-n matrices (except 1-by-1) are always held by row |
| 55 | A_is_csc = false ; |
| 56 | } |
| 57 | else |
| 58 | { |
| 59 | // m-by-n (including 0-by-0) with m != and n != use the global setting |
| 60 | A_is_csc = GB_Global_is_csc_get ( ) ; |
| 61 | } |
| 62 | |
| 63 | if (A_is_csc) |
| 64 | { |
| 65 | vlen = (int64_t) nrows ; |
| 66 | vdim = (int64_t) ncols ; |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | vlen = (int64_t) ncols ; |
| 71 | vdim = (int64_t) nrows ; |
| 72 | } |
| 73 | |
| 74 | return (GB_new (A, // auto sparsity, new header |
no test coverage detected