File: GB_emult_08bcd.c

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: 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 (153 lines) | stat: -rw-r--r-- 4,924 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//------------------------------------------------------------------------------
// GB_emult_08bcd: C=A.*B; C, A, and B are all sparse/hyper
//------------------------------------------------------------------------------

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

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

{

    //--------------------------------------------------------------
    // Method8(b,c,d): C = A.*B, no mask
    //--------------------------------------------------------------

    //      ------------------------------------------
    //      C       =           A       .*      B
    //      ------------------------------------------
    //      sparse  .           sparse          sparse  (method: 8)
    //      sparse  sparse      sparse          sparse  (8, M later)

    // both A and B are sparse/hyper
    ASSERT (A_is_sparse || A_is_hyper) ;
    ASSERT (B_is_sparse || B_is_hyper) ;

    if (ajnz > 32 * bjnz)
    {

        //----------------------------------------------------------
        // Method8(b): A(:,j) is much denser than B(:,j)
        //----------------------------------------------------------

        for ( ; pB < pB_end ; pB++)
        {
            int64_t i = GB_IGET (Bi, pB) ;
            // find i in A(:,j)
            int64_t pright = pA_end - 1 ;
            bool found ;
            found = GB_binary_search (i, Ai, GB_Ai_IS_32, &pA, &pright) ;
            if (found)
            { 
                // C (i,j) = A (i,j) .* B (i,j)
                #if ( GB_EMULT_08_PHASE == 1 )
                cjnz++ ;
                #else
                ASSERT (pC < pC_end) ;
                GB_ISET (Ci, pC, i) ;   // Ci [pC] = i ;
                #ifndef GB_ISO_EMULT
                GB_DECLAREA (aij) ;
                GB_GETA (aij, Ax, pA, A_iso) ;
                GB_DECLAREB (bij) ;
                GB_GETB (bij, Bx, pB, B_iso) ;
                GB_EWISEOP (Cx, pC, aij, bij, i, j) ;
                #endif
                pC++ ;
                #endif
            }
        }
        #if ( GB_EMULT_08_PHASE == 2 )
        ASSERT (pC == pC_end) ;
        #endif

    }
    else if (bjnz > 32 * ajnz)
    {

        //----------------------------------------------------------
        // Method8(c): B(:,j) is much denser than A(:,j)
        //----------------------------------------------------------

        for ( ; pA < pA_end ; pA++)
        {
            int64_t i = GB_IGET (Ai, pA) ;
            // find i in B(:,j)
            int64_t pright = pB_end - 1 ;
            bool found ;
            found = GB_binary_search (i, Bi, GB_Bi_IS_32, &pB, &pright) ;
            if (found)
            { 
                // C (i,j) = A (i,j) .* B (i,j)
                #if ( GB_EMULT_08_PHASE == 1 )
                cjnz++ ;
                #else
                ASSERT (pC < pC_end) ;
                GB_ISET (Ci, pC, i) ;   // Ci [pC] = i ;
                #ifndef GB_ISO_EMULT
                GB_DECLAREA (aij) ;
                GB_GETA (aij, Ax, pA, A_iso) ;
                GB_DECLAREB (bij) ;
                GB_GETB (bij, Bx, pB, B_iso) ;
                GB_EWISEOP (Cx, pC, aij, bij, i, j) ;
                #endif
                pC++ ;
                #endif
            }
        }
        #if ( GB_EMULT_08_PHASE == 2 )
        ASSERT (pC == pC_end) ;
        #endif

    }
    else
    {

        //----------------------------------------------------------
        // Method8(d): A(:,j) and B(:,j) about the sparsity
        //----------------------------------------------------------

        // linear-time scan of A(:,j) and B(:,j)

        while (pA < pA_end && pB < pB_end)
        {
            int64_t iA = GB_IGET (Ai, pA) ;
            int64_t iB = GB_IGET (Bi, pB) ;
            if (iA < iB)
            { 
                // A(i,j) exists but not B(i,j)
                pA++ ;
            }
            else if (iB < iA)
            { 
                // B(i,j) exists but not A(i,j)
                pB++ ;
            }
            else
            { 
                // both A(i,j) and B(i,j) exist
                // C (i,j) = A (i,j) .* B (i,j)
                #if ( GB_EMULT_08_PHASE == 1 )
                cjnz++ ;
                #else
                ASSERT (pC < pC_end) ;
                GB_ISET (Ci, pC, iB) ;  // Ci [pC] = iB ;
                #ifndef GB_ISO_EMULT
                GB_DECLAREA (aij) ;
                GB_GETA (aij, Ax, pA, A_iso) ;
                GB_DECLAREB (bij) ;
                GB_GETB (bij, Bx, pB, B_iso) ;
                GB_EWISEOP (Cx, pC, aij, bij, iB, j) ;
                #endif
                pC++ ;
                #endif
                pA++ ;
                pB++ ;
            }
        }

        #if ( GB_EMULT_08_PHASE == 2 )
        ASSERT (pC == pC_end) ;
        #endif
    }
}