File: GB_bitmap_assign.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 (233 lines) | stat: -rw-r--r-- 9,020 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
//------------------------------------------------------------------------------
// GB_bitmap_assign: assign to C bitmap
//------------------------------------------------------------------------------

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

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

// Implements GrB_Row_assign, GrB_Col_assign, GrB_assign, GxB_subassign when C
// is in bitmap form, or when C is converted into bitmap form.

// C is returned as bitmap in all cases except for C = A or C = scalar (the
// whole_C_matrix case with GB_bitmap_assign_noM_noaccum_whole).  For that
// method, C can be returned with any sparsity structure.

#include "GB_bitmap_assign_methods.h"
#include "GB_dense.h"

#define GB_FREE_ALL GB_phybix_free (C) ;

GrB_Info GB_bitmap_assign
(
    // input/output:
    GrB_Matrix C,               // input/output matrix
    // inputs:
    const bool C_replace,       // descriptor for C
    const GrB_Index *I,         // I index list
    const int64_t nI,
    const int Ikind,
    const int64_t Icolon [3],
    const GrB_Index *J,         // J index list
    const int64_t nJ,
    const int Jkind,
    const int64_t Jcolon [3],
    const GrB_Matrix M,         // mask matrix, NULL if not present
    const bool Mask_comp,       // true for !M, false for M
    const bool Mask_struct,     // true if M is structural, false if valued
    const GrB_BinaryOp accum,   // NULL if not present
    const GrB_Matrix A,         // input matrix, NULL for scalar assignment
    const void *scalar,         // input scalar, if A == NULL
    const GrB_Type scalar_type, // type of input scalar
    const int assign_kind,      // row assign, col assign, assign, or subassign
    GB_Context Context
)
{

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

    GrB_Info info ;
    ASSERT_MATRIX_OK (C, "C for bitmap assign", GB0) ;

    //--------------------------------------------------------------------------
    // ensure C is in bitmap form
    //--------------------------------------------------------------------------

    GB_OK (GB_convert_any_to_bitmap (C, Context)) ;
    ASSERT (GB_IS_BITMAP (C)) ;

    bool whole_C_matrix = (Ikind == GB_ALL && Jkind == GB_ALL) ;

    //--------------------------------------------------------------------------
    // do the assignment
    //--------------------------------------------------------------------------

    if (M == NULL)
    {
        if (accum == NULL)
        {
            if (whole_C_matrix)
            { 
                // C = A or scalar, no mask.  C may become sparse, hyper, or
                // full, or it may remain bitmap.
                GB_OK (GB_bitmap_assign_noM_noaccum_whole (C, C_replace,
                    /* no M, */ Mask_comp, Mask_struct, /* no accum, */
                    A, scalar, scalar_type, Context)) ;
            }
            else
            { 
                // C(I,J) = A or scalar, no mask
                GB_OK (GB_bitmap_assign_noM_noaccum (C, C_replace,
                    I, nI, Ikind, Icolon, J, nJ, Jkind, Jcolon,
                    /* no M, */ Mask_comp, Mask_struct, /* no accum, */
                    A, scalar, scalar_type, assign_kind, Context)) ;
            }
        }
        else
        {
            if (whole_C_matrix)
            { 
                // C += A or scalar, no mask.
                GB_OK (GB_bitmap_assign_noM_accum_whole (C, C_replace,
                    /* no M, */ Mask_comp, Mask_struct, accum,
                    A, scalar, scalar_type, Context)) ;
            }
            else
            { 
                // C(I,J) += A or scalar, no mask.
                GB_OK (GB_bitmap_assign_noM_accum (C, C_replace,
                    I, nI, Ikind, Icolon, J, nJ, Jkind, Jcolon,
                    /* no M, */ Mask_comp, Mask_struct, accum,
                    A, scalar, scalar_type, assign_kind, Context)) ;
            }
        }
    }
    else if (GB_IS_BITMAP (M) || GB_IS_FULL (M))
    {
        if (accum == NULL)
        {
            if (whole_C_matrix)
            { 
                // C<M or !M, where M is full> = A or scalar
                GB_OK (GB_bitmap_assign_fullM_noaccum_whole (C, C_replace,
                    M, Mask_comp, Mask_struct, /* no accum, */
                    A, scalar, scalar_type, Context)) ;
            }
            else
            { 
                // C<M or !M, where M is full>(I,J) = A or scalar
                GB_OK (GB_bitmap_assign_fullM_noaccum (C, C_replace,
                    I, nI, Ikind, Icolon, J, nJ, Jkind, Jcolon,
                    M, Mask_comp, Mask_struct, /* no accum, */
                    A, scalar, scalar_type, assign_kind, Context)) ;
            }
        }
        else
        {
            if (whole_C_matrix)
            { 
                // C<M or !M, where M is full> = A or scalar
                GB_OK (GB_bitmap_assign_fullM_accum_whole (C, C_replace,
                    M, Mask_comp, Mask_struct, accum,
                    A, scalar, scalar_type, Context)) ;
            }
            else
            { 
                // C<M or !M, where M is full>(I,J) = A or scalar
                GB_OK (GB_bitmap_assign_fullM_accum (C, C_replace,
                    I, nI, Ikind, Icolon, J, nJ, Jkind, Jcolon,
                    M, Mask_comp, Mask_struct, accum,
                    A, scalar, scalar_type, assign_kind, Context)) ;
            }
        }
    }
    else if (!Mask_comp)
    {
        if (accum == NULL)
        {
            if (whole_C_matrix)
            { 
                // C<M> = A or scalar, M is sparse or hypersparse
                GB_OK (GB_bitmap_assign_M_noaccum_whole (C, C_replace,
                    M, /* Mask_comp false, */ Mask_struct, /* no accum, */
                    A, scalar, scalar_type, Context)) ;
            }
            else
            { 
                // C<M>(I,J) = A or scalar, M is sparse or hypersparse
                GB_OK (GB_bitmap_assign_M_noaccum (C, C_replace,
                    I, nI, Ikind, Icolon, J, nJ, Jkind, Jcolon,
                    M, /* Mask_comp false, */ Mask_struct, /* no accum, */
                    A, scalar, scalar_type, assign_kind, Context)) ;
            }
        }
        else
        {
            if (whole_C_matrix)
            { 
                // C<M> += A or scalar, M is sparse or hypersparse
                GB_OK (GB_bitmap_assign_M_accum_whole (C, C_replace,
                    M, /* Mask_comp false, */ Mask_struct, accum,
                    A, scalar, scalar_type, Context)) ;
            }
            else
            { 
                // C<M>(I,J) += A or scalar, M is sparse or hypersparse
                GB_OK (GB_bitmap_assign_M_accum (C, C_replace,
                    I, nI, Ikind, Icolon, J, nJ, Jkind, Jcolon,
                    M, /* Mask_comp false, */ Mask_struct, accum,
                    A, scalar, scalar_type, assign_kind, Context)) ;
            }
        }
    }
    else // Mask_comp is true
    {
        if (accum == NULL)
        {
            if (whole_C_matrix)
            { 
                // C<!M> = A or scalar, M is sparse or hypersparse
                GB_OK (GB_bitmap_assign_notM_noaccum_whole (C, C_replace,
                    M, /* Mask_comp true, */ Mask_struct, /* no accum, */
                    A, scalar, scalar_type, Context)) ;
            }
            else
            { 
                // C<!M>(I,J) = A or scalar, M is sparse or hypersparse
                GB_OK (GB_bitmap_assign_notM_noaccum (C, C_replace,
                    I, nI, Ikind, Icolon, J, nJ, Jkind, Jcolon,
                    M, /* Mask_comp true, */ Mask_struct, /* no accum, */
                    A, scalar, scalar_type, assign_kind, Context)) ;
            }
        }
        else
        {
            if (whole_C_matrix)
            { 
                // C<!M> += A or scalar, M is sparse or hypersparse
                GB_OK (GB_bitmap_assign_notM_accum_whole (C, C_replace,
                    M, /* Mask_comp true, */ Mask_struct, accum,
                    A, scalar, scalar_type, Context)) ;
            }
            else
            { 
                // C<!M>(I,J) += A or scalar, M is sparse or hypersparse
                GB_OK (GB_bitmap_assign_notM_accum (C, C_replace,
                    I, nI, Ikind, Icolon, J, nJ, Jkind, Jcolon,
                    M, /* Mask_comp true, */ Mask_struct, accum,
                    A, scalar, scalar_type, assign_kind, Context)) ;
            }
        }
    }

    //--------------------------------------------------------------------------
    // return result
    //--------------------------------------------------------------------------

    ASSERT_MATRIX_OK (C, "final C for bitmap assign", GB0) ;
    return (GrB_SUCCESS) ;
}