~ubuntu-branches/ubuntu/hardy/suitesparse/hardy

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
#include "cs_mex.h"
/* A = cs_sparse2 (i,j,x), removing duplicates and numerically zero entries,
 * and returning A sorted (test cs_entry) */
void mexFunction
(
    int nargout,
    mxArray *pargout [ ],
    int nargin,
    const mxArray *pargin [ ]
)
{
    CS_INT k, m, n, nz, *Ti, *Tj ;
    if (nargout > 1 || nargin != 3)
    {
	mexErrMsgTxt ("Usage: A = cs_sparse2(i,j,x)") ;
    }
    nz = mxGetM (pargin [0]) ;
    Ti = cs_dl_mex_get_int (nz, pargin [0], &m, 1) ;
    Tj = cs_dl_mex_get_int (nz, pargin [1], &n, 1) ;
    cs_mex_check (1, nz, 1, 0, 0, 1, pargin [2]) ;
    if (mxIsComplex (pargin [2]))
    {
#ifdef NCOMPLEX
        mexErrMsgTxt ("complex case not supported") ;
#else
	cs_complex_t *Tx ;
	cs_cl *A, *C, *T ;
	Tx = cs_cl_mex_get_double (nz, pargin [2]) ;
	T = cs_cl_spalloc (n, m, 1, 1, 1) ;
	for (k = 0 ; k < nz ; k++)
	{
	    cs_cl_entry (T, Tj [k], Ti [k], Tx [k]) ;
	}
	C = cs_cl_compress (T) ;
	cs_cl_spfree (T) ;
	cs_cl_dupl (C) ;
	cs_cl_dropzeros (C) ;
	A = cs_cl_transpose (C, -1) ;
	cs_cl_spfree (C) ;
	pargout [0] = cs_cl_mex_put_sparse (&A) ;
	cs_free (Tx) ;
#endif
    }
    else
    {
	double *Tx ;
	cs_dl *A, *C, *T ;
	Tx = mxGetPr (pargin [2]) ;
	T = cs_dl_spalloc (n, m, 1, 1, 1) ;
	for (k = 0 ; k < nz ; k++)
	{
	    cs_dl_entry (T, Tj [k], Ti [k], Tx [k]) ;
	}
	C = cs_dl_compress (T) ;
	cs_dl_spfree (T) ;
	cs_dl_dupl (C) ;
	cs_dl_dropzeros (C) ;
	A = cs_dl_transpose (C, 1) ;
	cs_dl_spfree (C) ;
	pargout [0] = cs_dl_mex_put_sparse (&A) ;
    }
    cs_free (Ti) ;
    cs_free (Tj) ;
}