1function w = GB_spec_vxm (w, mask, accum, semiring, u, A, descriptor)
2%GB_SPEC_VXM a MATLAB mimic of GrB_vxm
3%
4% Usage:
5% w = GB_spec_vxm (w, mask, accum, semiring, u, A, descriptor)
6%
7% w, mask, and u are column vectors.  Computes w'=u'*A or w'=u'*A'
8
9% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
10% SPDX-License-Identifier: Apache-2.0
11
12if (nargout > 1 || nargin ~= 7)
13    error ('usage: w = GB_spec_vxm (w, mask, accum, semiring, u, A, descriptor)') ;
14end
15
16% In the C implementation of GraphBLAS itself, the column vectors u and w are
17% not transposed since it is costly to transpose column vectors.  w=A*u or
18% w=A'*u is computed instead, but with the multiply operator fmult(x,y) used as
19% fmult(y,x) instead.  This also requires the descriptor to be revised for A.
20%
21% The transformation of the problem in the C implementation is the same as
22% simply doing the transpose of u and w and leaving the descriptor unchanged.
23% Then the inputs to the multiply operator are used as-is and not flipped.
24% This simpler method is used in this MATLAB mimic.
25
26% make sure u is a column vector on input, then transpose it
27if (isstruct (u))
28    n = size (u.matrix, 2) ;
29    u.matrix = u.matrix.' ;
30    u.pattern = u.pattern' ;
31else
32    n = size (u, 2);
33    u = u' ;
34end
35if (n ~= 1)
36    error ('u must be a vector') ;
37end
38
39% make sure w is a column vector on input, then transpose it
40if (isstruct (w))
41    n = size (w.matrix, 2) ;
42    w.matrix = w.matrix.' ;
43    w.pattern = w.pattern' ;
44else
45    n = size (w, 2);
46    w = w' ;
47end
48if (n ~= 1)
49    error ('w must be a vector') ;
50end
51
52% mask is a column vector on input, so transpose it
53mask = mask' ;
54
55% GraphBLAS does not allow u to be transposed via the descriptor
56if (isfield (descriptor, 'inp0'))
57    descriptor = rmfield (descriptor, 'inp0') ;
58end
59
60w = GB_spec_mxm (w, mask, accum, semiring, u, A, descriptor) ;
61
62% transpose w back into a column vector
63w.matrix = w.matrix.' ;
64w.pattern = w.pattern' ;
65
66