1 /* ========================================================================== */
2 /* === CHOLMOD/MATLAB/sdmult mexFunction ==================================== */
3 /* ========================================================================== */
4 
5 /* -----------------------------------------------------------------------------
6  * CHOLMOD/MATLAB Module.  Copyright (C) 2005-2006, Timothy A. Davis
7  * http://www.suitesparse.com
8  * MATLAB(tm) is a Trademark of The MathWorks, Inc.
9  * -------------------------------------------------------------------------- */
10 
11 /* Compute C = S*F or S'*F where S is sparse and F is full (C is also sparse).
12  * S and F must both be real or both be complex.
13  *
14  * Usage:
15  *
16  *	C = sdmult (S,F) ;		C = S*F
17  *	C = sdmult (S,F,0) ;		C = S*F
18  *	C = sdmult (S,F,1) ;		C = S'*F
19  */
20 
21 #include "cholmod_matlab.h"
22 
mexFunction(int nargout,mxArray * pargout[],int nargin,const mxArray * pargin[])23 void mexFunction
24 (
25     int nargout,
26     mxArray *pargout [ ],
27     int nargin,
28     const mxArray *pargin [ ]
29 )
30 {
31     double dummy = 0, one [2] = {1,0}, zero [2] = {0,0} ;
32     cholmod_sparse *S, Smatrix ;
33     cholmod_dense *F, Fmatrix, *C ;
34     cholmod_common Common, *cm ;
35     Long srow, scol, frow, fcol, crow, transpose ;
36 
37     /* ---------------------------------------------------------------------- */
38     /* start CHOLMOD and set parameters */
39     /* ---------------------------------------------------------------------- */
40 
41     cm = &Common ;
42     cholmod_l_start (cm) ;
43     sputil_config (SPUMONI, cm) ;
44 
45     /* ---------------------------------------------------------------------- */
46     /* check inputs */
47     /* ---------------------------------------------------------------------- */
48 
49     if (nargout > 1 || nargin < 2 || nargin > 3)
50     {
51 	mexErrMsgTxt ("Usage: C = sdmult (S,F,transpose)") ;
52     }
53 
54     srow = mxGetM (pargin [0]) ;
55     scol = mxGetN (pargin [0]) ;
56     frow = mxGetM (pargin [1]) ;
57     fcol = mxGetN (pargin [1]) ;
58 
59     transpose = !((nargin == 2) || (mxGetScalar (pargin [2]) == 0)) ;
60 
61     if (frow != (transpose ? srow : scol))
62     {
63 	mexErrMsgTxt ("invalid inner dimensions") ;
64     }
65 
66     if (!mxIsSparse (pargin [0]) || mxIsSparse (pargin [1]))
67     {
68 	mexErrMsgTxt ("sdmult (S,F): S must be sparse, F must be full") ;
69     }
70 
71     /* ---------------------------------------------------------------------- */
72     /* get S and F */
73     /* ---------------------------------------------------------------------- */
74 
75     S = sputil_get_sparse (pargin [0], &Smatrix, &dummy, 0) ;
76     F = sputil_get_dense  (pargin [1], &Fmatrix, &dummy) ;
77 
78     /* ---------------------------------------------------------------------- */
79     /* C = S*F or S'*F */
80     /* ---------------------------------------------------------------------- */
81 
82     crow = transpose ? scol : srow ;
83     C = cholmod_l_allocate_dense (crow, fcol, crow, F->xtype, cm) ;
84     cholmod_l_sdmult (S, transpose, one, zero, F, C, cm) ;
85     pargout [0] = sputil_put_dense (&C, cm) ;
86 
87     /* ---------------------------------------------------------------------- */
88     /* free workspace and the CHOLMOD L, except for what is copied to MATLAB */
89     /* ---------------------------------------------------------------------- */
90 
91     cholmod_l_finish (cm) ;
92     cholmod_l_print_common (" ", cm) ;
93     /*
94     if (cm->malloc_count != (mxIsComplex (pargout [0]) + 1)) mexErrMsgTxt ("!");
95     */
96 }
97