File: gb_new.c

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (53 lines) | stat: -rw-r--r-- 1,594 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
//------------------------------------------------------------------------------
// gb_new: create a GraphBLAS matrix with desired format and sparsity control
//------------------------------------------------------------------------------

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

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

#include "gb_interface.h"

GrB_Matrix gb_new               // create and empty matrix C
(
    GrB_Type type,              // type of C
    GrB_Index nrows,            // # of rows
    GrB_Index ncols,            // # of rows
    GxB_Format_Value fmt,       // requested format, if < 0 use default
    int sparsity                // sparsity control for C, 0 for default
)
{

    // create the matrix
    GrB_Matrix C = NULL ;
    OK (GrB_Matrix_new (&C, type, nrows, ncols)) ;

    // get the default format, if needed
    if (fmt < 0)
    { 
        fmt = gb_default_format (nrows, ncols) ;
    }

    // set the desired format
    GxB_Format_Value fmt_current ;
    OK (GxB_Matrix_Option_get (C, GxB_FORMAT, &fmt_current)) ;
    if (fmt != fmt_current)
    { 
        OK (GxB_Matrix_Option_set (C, GxB_FORMAT, fmt)) ;
    }

    // set the desired sparsity structure
    if (sparsity != 0)
    { 
        int current ;
        OK (GxB_Matrix_Option_get (C, GxB_SPARSITY_CONTROL, &current)) ;
        if (current != sparsity)
        {
            OK (GxB_Matrix_Option_set (C, GxB_SPARSITY_CONTROL, sparsity)) ;
        }
    }

    return (C) ;
}