1 //------------------------------------------------------------------------------
2 // GB_mex_subassign_alias: C<C>(:,:) = accum(C(:,:),C)
3 //------------------------------------------------------------------------------
4
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7
8 //------------------------------------------------------------------------------
9
10 #include "GB_mex.h"
11
12 #define USAGE "C = GB_mex_subassign_alias (C, accum, desc)"
13
14 #define FREE_ALL \
15 { \
16 GrB_Matrix_free_(&C) ; \
17 GrB_Descriptor_free_(&desc) ; \
18 GB_mx_put_global (true) ; \
19 }
20
mexFunction(int nargout,mxArray * pargout[],int nargin,const mxArray * pargin[])21 void mexFunction
22 (
23 int nargout,
24 mxArray *pargout [ ],
25 int nargin,
26 const mxArray *pargin [ ]
27 )
28 {
29
30 bool malloc_debug = GB_mx_get_global (true) ;
31 GrB_Matrix C = NULL ;
32 GrB_Descriptor desc = NULL ;
33
34 // check inputs
35 if (nargout > 1 || nargin < 2 || nargin > 3)
36 {
37 mexErrMsgTxt ("Usage: " USAGE) ;
38 }
39
40 // get C (make a deep copy)
41 #define GET_DEEP_COPY \
42 C = GB_mx_mxArray_to_Matrix (pargin [0], "C input", true, true) ;
43 #define FREE_DEEP_COPY GrB_Matrix_free_(&C) ;
44 GET_DEEP_COPY ;
45 if (C == NULL)
46 {
47 FREE_ALL ;
48 mexErrMsgTxt ("C failed") ;
49 }
50
51 // get accum, if present
52 bool user_complex = (Complex != GxB_FC64) && (C->type == Complex) ;
53 GrB_BinaryOp accum ;
54 if (!GB_mx_mxArray_to_BinaryOp (&accum, pargin [1], "accum",
55 C->type, user_complex))
56 {
57 FREE_ALL ;
58 mexErrMsgTxt ("accum failed") ;
59 }
60
61 // get desc
62 if (!GB_mx_mxArray_to_Descriptor (&desc, PARGIN (2), "desc"))
63 {
64 FREE_ALL ;
65 mexErrMsgTxt ("desc failed") ;
66 }
67
68 GrB_Index nrows, ncols ;
69 GrB_Matrix_nrows (&nrows, C) ;
70 GrB_Matrix_ncols (&ncols, C) ;
71
72 // C<C>(:,:) = accum (C(:,:),C)
73 METHOD (GxB_Matrix_subassign_(C, C, accum, C,
74 GrB_ALL, nrows, GrB_ALL, ncols, desc)) ;
75
76 // return C to MATLAB as a struct and free the GraphBLAS C
77 pargout [0] = GB_mx_Matrix_to_mxArray (&C, "C output", true) ;
78
79 FREE_ALL ;
80 }
81
82