1 //------------------------------------------------------------------------------
2 // GB_mex_Vector_eWiseMult: w<mask> = accum(w,u.*v)
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 "w = GB_mex_Vector_eWiseMult (w, mask, accum, mult, u, v, desc)"
13
14 #define FREE_ALL \
15 { \
16 GrB_Vector_free_(&w) ; \
17 GrB_Vector_free_(&u) ; \
18 GrB_Vector_free_(&v) ; \
19 GrB_Descriptor_free_(&desc) ; \
20 GrB_Vector_free_(&mask) ; \
21 GB_mx_put_global (true) ; \
22 }
23
mexFunction(int nargout,mxArray * pargout[],int nargin,const mxArray * pargin[])24 void mexFunction
25 (
26 int nargout,
27 mxArray *pargout [ ],
28 int nargin,
29 const mxArray *pargin [ ]
30 )
31 {
32
33 bool malloc_debug = GB_mx_get_global (true) ;
34 GrB_Vector w = NULL ;
35 GrB_Vector u = NULL ;
36 GrB_Vector v = NULL ;
37 GrB_Vector mask = NULL ;
38 GrB_Descriptor desc = NULL ;
39
40 // check inputs
41 if (nargout > 1 || nargin < 6 || nargin > 7)
42 {
43 mexErrMsgTxt ("Usage: " USAGE) ;
44 }
45
46 // get w (make a deep copy)
47 #define GET_DEEP_COPY \
48 w = GB_mx_mxArray_to_Vector (pargin [0], "w input", true, true) ;
49 #define FREE_DEEP_COPY GrB_Vector_free_(&w) ;
50 GET_DEEP_COPY ;
51 if (w == NULL)
52 {
53 FREE_ALL ;
54 mexErrMsgTxt ("w failed") ;
55 }
56
57 // get mask (shallow copy)
58 mask = GB_mx_mxArray_to_Vector (pargin [1], "mask", false, false) ;
59 if (mask == NULL && !mxIsEmpty (pargin [1]))
60 {
61 FREE_ALL ;
62 mexErrMsgTxt ("mask failed") ;
63 }
64
65 // get u (shallow copy)
66 u = GB_mx_mxArray_to_Vector (pargin [4], "u input", false, true) ;
67 if (u == NULL)
68 {
69 FREE_ALL ;
70 mexErrMsgTxt ("u failed") ;
71 }
72
73 // get v (shallow copy)
74 v = GB_mx_mxArray_to_Vector (pargin [5], "v input", false, true) ;
75 if (v == NULL)
76 {
77 FREE_ALL ;
78 mexErrMsgTxt ("v failed") ;
79 }
80
81 // get mult operator
82 bool user_complex = (Complex != GxB_FC64)
83 && (u->type == Complex || v->type == Complex) ;
84 GrB_BinaryOp mult ;
85 if (!GB_mx_mxArray_to_BinaryOp (&mult, pargin [3], "mult",
86 w->type, user_complex) || mult == NULL)
87 {
88 FREE_ALL ;
89 mexErrMsgTxt ("mult failed") ;
90 }
91
92 // get accum, if present
93 GrB_BinaryOp accum ;
94 user_complex = (Complex != GxB_FC64) && (w->type == Complex) ;
95 if (!GB_mx_mxArray_to_BinaryOp (&accum, pargin [2], "accum",
96 w->type, user_complex))
97 {
98 FREE_ALL ;
99 mexErrMsgTxt ("accum failed") ;
100 }
101
102 // get desc
103 if (!GB_mx_mxArray_to_Descriptor (&desc, PARGIN (6), "desc"))
104 {
105 FREE_ALL ;
106 mexErrMsgTxt ("desc failed") ;
107 }
108
109 // w<mask> = accum(w,u.*v)
110 METHOD (GrB_Vector_eWiseMult_BinaryOp_(w, mask, accum, mult, u, v, desc)) ;
111
112 // return w to MATLAB as a struct and free the GraphBLAS w
113 pargout [0] = GB_mx_Vector_to_mxArray (&w, "w output", true) ;
114
115 FREE_ALL ;
116 }
117
118