1 /* ========================================================================== */
2 /* === UMFPACK_col_to_triplet =============================================== */
3 /* ========================================================================== */
4
5 /* -------------------------------------------------------------------------- */
6 /* Copyright (c) 2005-2012 by Timothy A. Davis, http://www.suitesparse.com. */
7 /* All Rights Reserved. See ../Doc/License.txt for License. */
8 /* -------------------------------------------------------------------------- */
9
10 /*
11 User callable. Converts a column-oriented input matrix to triplet form by
12 constructing the column indices Tj from the column pointers Ap. The matrix
13 may be singular. See umfpack_col_to_triplet.h for details.
14
15 */
16
17 #include "umf_internal.h"
18
UMFPACK_col_to_triplet(Int n_col,const Int Ap[],Int Tj[])19 GLOBAL Int UMFPACK_col_to_triplet
20 (
21 Int n_col,
22 const Int Ap [ ],
23 Int Tj [ ]
24 )
25 {
26
27 /* ---------------------------------------------------------------------- */
28 /* local variables */
29 /* ---------------------------------------------------------------------- */
30
31 Int nz, j, p, p1, p2, length ;
32
33 /* ---------------------------------------------------------------------- */
34 /* construct the column indices */
35 /* ---------------------------------------------------------------------- */
36
37 if (!Ap || !Tj)
38 {
39 return (UMFPACK_ERROR_argument_missing) ;
40 }
41 if (n_col <= 0)
42 {
43 return (UMFPACK_ERROR_n_nonpositive) ;
44 }
45 if (Ap [0] != 0)
46 {
47 return (UMFPACK_ERROR_invalid_matrix) ;
48 }
49 nz = Ap [n_col] ;
50 if (nz < 0)
51 {
52 return (UMFPACK_ERROR_invalid_matrix) ;
53 }
54
55 for (j = 0 ; j < n_col ; j++)
56 {
57 p1 = Ap [j] ;
58 p2 = Ap [j+1] ;
59 length = p2 - p1 ;
60 if (length < 0 || p2 > nz)
61 {
62 return (UMFPACK_ERROR_invalid_matrix) ;
63 }
64 for (p = p1 ; p < p2 ; p++)
65 {
66 Tj [p] = j ;
67 }
68 }
69
70 return (UMFPACK_OK) ;
71 }
72