File: GrB_Matrix_setElement.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 (90 lines) | stat: -rw-r--r-- 3,836 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
//------------------------------------------------------------------------------
// GrB_Matrix_setElement: set an entry in a matrix, C(row,col) = x
//------------------------------------------------------------------------------

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

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

// Set a single entry in a matrix, C(row,col) = x,
// typecasting from the type of x to the type of C, as needed.

#define GB_FREE_ALL ;
#include "GB.h"

#define GB_SET(prefix,type,T,ampersand)                                     \
GrB_Info GB_EVAL3 (prefix, _Matrix_setElement_, T) /* C (row,col) = x */    \
(                                                                           \
    GrB_Matrix C,                       /* matrix to modify               */\
    type x,                             /* scalar to assign to C(row,col) */\
    GrB_Index row,                      /* row index                      */\
    GrB_Index col                       /* column index                   */\
)                                                                           \
{                                                                           \
    GB_WHERE (C, GB_STR(prefix) "_Matrix_setElement_" GB_STR(T)             \
        " (C, row, col, x)") ;                                              \
    GB_RETURN_IF_NULL_OR_FAULTY (C) ;                                       \
    return (GB_setElement (C, NULL, ampersand x, row, col,                  \
        GB_ ## T ## _code, Context)) ;                                      \
}

GB_SET (GrB, bool      , BOOL   , &)
GB_SET (GrB, int8_t    , INT8   , &)
GB_SET (GrB, int16_t   , INT16  , &)
GB_SET (GrB, int32_t   , INT32  , &)
GB_SET (GrB, int64_t   , INT64  , &)
GB_SET (GrB, uint8_t   , UINT8  , &)
GB_SET (GrB, uint16_t  , UINT16 , &)
GB_SET (GrB, uint32_t  , UINT32 , &)
GB_SET (GrB, uint64_t  , UINT64 , &)
GB_SET (GrB, float     , FP32   , &)
GB_SET (GrB, double    , FP64   , &)
GB_SET (GxB, GxB_FC32_t, FC32   , &)
GB_SET (GxB, GxB_FC64_t, FC64   , &)
GB_SET (GrB, void *    , UDT    ,  )

//------------------------------------------------------------------------------
// GrB_Matrix_setElement_Scalar: set an entry in a matrix from a GrB_Scalar
//------------------------------------------------------------------------------

// When the GrB_Scalar has a single entry, this method is just like the
// setElement methods defined above.  If the GrB_Scalar has no entry, then it
// acts like GrB_Matrix_removeElement.

GrB_Info GrB_Matrix_setElement_Scalar
(
    GrB_Matrix C,                       // matrix to modify
    GrB_Scalar scalar,                  // scalar to assign to C(row,col)
    GrB_Index row,                      // row index
    GrB_Index col                       // column index
)
{

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

    GB_WHERE (C, "GrB_Matrix_setElement_Scalar (C, x, row, col)") ;
    GB_RETURN_IF_NULL_OR_FAULTY (C) ;
    GB_RETURN_IF_NULL_OR_FAULTY (scalar) ;

    //--------------------------------------------------------------------------
    // set or remove the element
    //--------------------------------------------------------------------------

    GrB_Info info ;
    GB_MATRIX_WAIT (scalar) ;
    if (GB_nnz ((GrB_Matrix) scalar) > 0)
    { 
        // set the element: C(row,col) = scalar
        return (GB_setElement (C, NULL, scalar->x, row, col,
            scalar->type->code, Context)) ;
    }
    else
    { 
        // delete the C(row,col) element
        return (GB_Matrix_removeElement (C, row, col, Context)) ;
    }
}