File: GB_enumify_mask.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 (115 lines) | stat: -rw-r--r-- 3,473 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
//------------------------------------------------------------------------------
// GB_enumify_mask: return mask_ecode to define mask macros
//------------------------------------------------------------------------------

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

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

// User-defined types cannot be used as a valued mask.  They can be used
// as structural masks.

#include "GB.h"
#include "jitifyer/GB_stringify.h"

void GB_enumify_mask       // return enum to define mask macros
(
    // output:
    int *mask_ecode,            // enumified mask
    // input
    const GB_Type_code mcode,   // typecode of the mask matrix M,
                                // or 0 if M is not present
    bool Mask_struct,           // true if M structural, false if valued
    bool Mask_comp              // true if M complemented
)
{

    // Mask_comp becomes the least significant bit, so that
    // Mask_comp = (mask_ecode & 0x1) can be computed later.
    // Mask_struct = (mask_ecode == 2 || mask_ecode == 3)

    int e = -1 ;

    if (mcode == 0)
    { 

        //----------------------------------------------------------------------
        // no mask is present
        //----------------------------------------------------------------------

        // Mask_struct is ignored, but the mask may be complemented or not

        // user-defined types are OK.  The values of M are not accessed.
        e = (!Mask_comp) ? 0 : 1 ;

    }
    else if (Mask_struct)
    { 

        //----------------------------------------------------------------------
        // M is present, and structural (not valued).
        //----------------------------------------------------------------------

        // user-defined types are OK.  The values of M are not accessed.
        e = (!Mask_comp) ? 2 : 3 ;

    }
    else
    { 

        //----------------------------------------------------------------------
        // M is present, and valued
        //----------------------------------------------------------------------

        switch (mcode)
        {

            case GB_BOOL_code  : 
            case GB_INT8_code  : 
            case GB_UINT8_code : 

                // valued mask, values are 1 byte in size
                e = (!Mask_comp) ? 4 : 5 ;
                break ;

            case GB_INT16_code  : 
            case GB_UINT16_code : 

                // valued mask, values are 2 bytes in size
                e = (!Mask_comp) ? 6 : 7 ;
                break ;

            case GB_INT32_code  : 
            case GB_UINT32_code : 
            case GB_FP32_code   : 

                // valued mask, values are 4 bytes in size
                e = (!Mask_comp) ? 8 : 9 ;
                break ;

            case GB_INT64_code  : 
            case GB_UINT64_code : 
            case GB_FC32_code   : 
            case GB_FP64_code   : 

                // valued mask, values are 8 bytes in size
                e = (!Mask_comp) ? 10 : 11 ;
                break ;

            case GB_FC64_code   : 

                // valued mask, values are 16 bytes in size
                e = (!Mask_comp) ? 12 : 13 ;
                break ;

            default: ;
                // user-defined types are not allowed
                e = -1 ;
                break ;
        }
    }

    (*mask_ecode) = e ;
}