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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
|
/* ========================================================================== */
/* === UMF_transpose ======================================================== */
/* ========================================================================== */
/* -------------------------------------------------------------------------- */
/* UMFPACK Version 4.1 (Apr. 30, 2003), Copyright (c) 2003 by Timothy A. */
/* Davis. All Rights Reserved. See ../README for License. */
/* email: davis@cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/umfpack */
/* -------------------------------------------------------------------------- */
/* Not user-callable. Computes a permuted transpose, R = (A (P,Q(1:nq)))' in
MATLAB notation, where R is in column-form. A is n_row-by-n_col, the
row-form matrix R is n_row-by-nq, where nq <= n_col. A may be singular.
The complex version can do transpose (') or array transpose (.').
Uses Gustavson's method (Two Fast Algorithms for Sparse Matrices:
Multiplication and Permuted Transposition, ACM Trans. on Math. Softw.,
vol 4, no 3, pp. 250-269).
*/
#include "umf_internal.h"
#include "umf_is_permutation.h"
GLOBAL Int UMF_transpose
(
Int n_row, /* A is n_row-by-n_col */
Int n_col,
const Int Ap [ ], /* size n_col+1 */
const Int Ai [ ], /* size nz = Ap [n_col] */
const double Ax [ ], /* size nz if present */
const Int P [ ], /* P [k] = i means original row i is kth row in A(P,Q)*/
/* P is identity if not present */
/* size n_row, if present */
const Int Q [ ], /* Q [k] = j means original col j is kth col in A(P,Q)*/
/* Q is identity if not present */
/* size nq, if present */
Int nq, /* size of Q, ignored if Q is (Int *) NULL */
/* output matrix: Rp, Ri, Rx, and Rz: */
Int Rp [ ], /* size n_row+1 */
Int Ri [ ], /* size nz */
double Rx [ ], /* size nz, if present */
Int W [ ], /* size max (n_row,n_col) workspace */
Int check /* if true, then check inputs */
#ifdef COMPLEX
, const double Az [ ] /* size nz */
, double Rz [ ] /* size nz */
, Int do_conjugate /* if true, then do conjugate transpose */
/* otherwise, do array transpose */
#endif
)
{
/* ---------------------------------------------------------------------- */
/* local variables */
/* ---------------------------------------------------------------------- */
Int i, j, k, p, bp, newj, do_values ;
/* ---------------------------------------------------------------------- */
/* check inputs */
/* ---------------------------------------------------------------------- */
#ifndef NDEBUG
Int nz ;
ASSERT (n_col >= 0) ;
nz = (Ap != (Int *) NULL) ? Ap [n_col] : 0 ;
DEBUG2 (("UMF_transpose: "ID"-by-"ID" nz "ID"\n", n_row, n_col, nz)) ;
#endif
if (check)
{
/* UMFPACK_symbolic skips this check */
/* UMFPACK_transpose always does this check */
if (!Ai || !Ap || !Ri || !Rp || !W)
{
return (UMFPACK_ERROR_argument_missing) ;
}
if (n_row <= 0 || n_col <= 0) /* n_row,n_col must be > 0 */
{
return (UMFPACK_ERROR_n_nonpositive) ;
}
if (!UMF_is_permutation (P, W, n_row, n_row) ||
!UMF_is_permutation (Q, W, nq, nq))
{
return (UMFPACK_ERROR_invalid_permutation) ;
}
if (!AMD_valid (n_row, n_col, Ap, Ai))
{
return (UMFPACK_ERROR_invalid_matrix) ;
}
}
#ifndef NDEBUG
DEBUG2 (("UMF_transpose, input matrix:\n")) ;
UMF_dump_col_matrix (Ax,
#ifdef COMPLEX
Az,
#endif
Ai, Ap, n_row, n_col, nz) ;
#endif
/* ---------------------------------------------------------------------- */
/* count the entries in each row of A */
/* ---------------------------------------------------------------------- */
/* use W as workspace for RowCount */
for (i = 0 ; i < n_row ; i++)
{
W [i] = 0 ;
Rp [i] = 0 ;
}
if (Q != (Int *) NULL)
{
for (newj = 0 ; newj < nq ; newj++)
{
j = Q [newj] ;
ASSERT (j >= 0 && j < n_col) ;
for (p = Ap [j] ; p < Ap [j+1] ; p++)
{
i = Ai [p] ;
ASSERT (i >= 0 && i < n_row) ;
W [i]++ ;
}
}
}
else
{
for (j = 0 ; j < n_col ; j++)
{
for (p = Ap [j] ; p < Ap [j+1] ; p++)
{
i = Ai [p] ;
ASSERT (i >= 0 && i < n_row) ;
W [i]++ ;
}
}
}
/* ---------------------------------------------------------------------- */
/* compute the row pointers for R = A (P,Q) */
/* ---------------------------------------------------------------------- */
if (P != (Int *) NULL)
{
Rp [0] = 0 ;
for (k = 0 ; k < n_row ; k++)
{
i = P [k] ;
ASSERT (i >= 0 && i < n_row) ;
Rp [k+1] = Rp [k] + W [i] ;
}
for (k = 0 ; k < n_row ; k++)
{
i = P [k] ;
ASSERT (i >= 0 && i < n_row) ;
W [i] = Rp [k] ;
}
}
else
{
Rp [0] = 0 ;
for (i = 0 ; i < n_row ; i++)
{
Rp [i+1] = Rp [i] + W [i] ;
}
for (i = 0 ; i < n_row ; i++)
{
W [i] = Rp [i] ;
}
}
ASSERT (Rp [n_row] <= Ap [n_col]) ;
/* at this point, W holds the permuted row pointers */
/* ---------------------------------------------------------------------- */
/* construct the row form of B */
/* ---------------------------------------------------------------------- */
do_values = Ax && Rx ;
#ifdef COMPLEX
do_values = do_values && Az && Rz ;
#endif
#ifdef COMPLEX
if (do_conjugate && do_values)
{
if (Q != (Int *) NULL)
{
/* R = A (P,Q)' */
for (newj = 0 ; newj < nq ; newj++)
{
j = Q [newj] ;
ASSERT (j >= 0 && j < n_col) ;
for (p = Ap [j] ; p < Ap [j+1] ; p++)
{
bp = W [Ai [p]]++ ;
Ri [bp] = newj ;
Rx [bp] = Ax [p] ;
Rz [bp] = -Az [p] ;
}
}
}
else
{
/* R = A (P,:)' */
for (j = 0 ; j < n_col ; j++)
{
for (p = Ap [j] ; p < Ap [j+1] ; p++)
{
bp = W [Ai [p]]++ ;
Ri [bp] = j ;
Rx [bp] = Ax [p] ;
Rz [bp] = -Az [p] ;
}
}
}
}
else
#endif
{
if (Q != (Int *) NULL)
{
if (do_values)
{
/* R = A (P,Q).' */
for (newj = 0 ; newj < nq ; newj++)
{
j = Q [newj] ;
ASSERT (j >= 0 && j < n_col) ;
for (p = Ap [j] ; p < Ap [j+1] ; p++)
{
bp = W [Ai [p]]++ ;
Ri [bp] = newj ;
Rx [bp] = Ax [p] ;
#ifdef COMPLEX
Rz [bp] = Az [p] ;
#endif
}
}
}
else
{
/* R = pattern of A (P,Q).' */
for (newj = 0 ; newj < nq ; newj++)
{
j = Q [newj] ;
ASSERT (j >= 0 && j < n_col) ;
for (p = Ap [j] ; p < Ap [j+1] ; p++)
{
Ri [W [Ai [p]]++] = newj ;
}
}
}
}
else
{
if (do_values)
{
/* R = A (P,:).' */
for (j = 0 ; j < n_col ; j++)
{
for (p = Ap [j] ; p < Ap [j+1] ; p++)
{
bp = W [Ai [p]]++ ;
Ri [bp] = j ;
Rx [bp] = Ax [p] ;
#ifdef COMPLEX
Rz [bp] = Az [p] ;
#endif
}
}
}
else
{
/* R = pattern of A (P,:).' */
for (j = 0 ; j < n_col ; j++)
{
for (p = Ap [j] ; p < Ap [j+1] ; p++)
{
Ri [W [Ai [p]]++] = j ;
}
}
}
}
}
#ifndef NDEBUG
for (k = 0 ; k < n_row ; k++)
{
if (P != (Int *) NULL)
{
i = P [k] ;
}
else
{
i = k ;
}
DEBUG3 ((ID": W[i] "ID" Rp[k+1] "ID"\n", i, W [i], Rp [k+1])) ;
ASSERT (W [i] == Rp [k+1]) ;
}
DEBUG2 (("UMF_transpose, output matrix:\n")) ;
UMF_dump_col_matrix (Rx,
#ifdef COMPLEX
Rz,
#endif
Ri, Rp, n_col, n_row, Rp [n_row]) ;
ASSERT (AMD_valid (n_col, n_row, Rp, Ri)) ;
#endif
return (UMFPACK_OK) ;
}
|