File: GrB_Matrix_exportHint.c

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, 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 (68 lines) | stat: -rw-r--r-- 2,516 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
//------------------------------------------------------------------------------
// GrB_Matrix_exportHint: determine sizes of arrays for GrB_Matrix_export
//------------------------------------------------------------------------------

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

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

#include "transpose/GB_transpose.h"
#define GB_FREE_ALL ;

GrB_Info GrB_Matrix_exportHint  // suggest the best export format
(
    int *format,            // export format
    GrB_Matrix A            // matrix to export
)
{ 

    //--------------------------------------------------------------------------
    // check inputs
    //--------------------------------------------------------------------------

    GB_RETURN_IF_NULL (format) ;
    GB_RETURN_IF_NULL (A) ;
    GB_WHERE_1 (A, "GrB_Matrix_exportHint (&format, A)") ;

    // finish any pending work since this can change the sparsity of A
    GB_MATRIX_WAIT (A) ;

    int sparsity = GB_sparsity (A) ;
    bool is_csc = A->is_csc ;

    //--------------------------------------------------------------------------
    // determine format that requires the least amount of modification
    //--------------------------------------------------------------------------

    switch (sparsity)
    {
        default:
        case GxB_SPARSE : 
            // CSR and CSC formats are supported by GraphBLAS, so if the matrix
            // is sparse by-row or sparse by-column, then suggest CSR or CSC.
            // The matrix can be exported with no change at all.
        case GxB_BITMAP : 
            // Bitmap is not supported as a GrB_Format.  It cannot be exported
            // as full, in general, so select CSR or CSC.
            (*format) = is_csc ? GrB_CSC_FORMAT : GrB_CSR_FORMAT ;
            break ;

        case GxB_HYPERSPARSE : 
            // Hypersparse is not supported as a GrB_Format.  Expanding a huge
            // hypersparse matrix to sparse can be costly, so suggest COO.
            (*format) = GrB_COO_FORMAT ;
            break ;

        case GxB_FULL : 
            // Full is not supported by GraphBLAS
            (*format) = is_csc ? GrB_CSC_FORMAT : GrB_CSR_FORMAT ;
            // if full was supported by GraphBLAS;
//          (*format) = is_csc ?  GrB_DENSE_COL_FORMAT : GrB_DENSE_ROW_FORMAT ; 
            break ;
    }

    #pragma omp flush
    return (GrB_SUCCESS) ;
}