Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/colamd.cc @ 15020:560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
* Array-util.cc, Array.cc, DASPK.cc, DASRT.cc, DASSL.cc, LSODE.cc,
MatrixType.cc, Sparse.cc, Sparse.h, dim-vector.h, eigs-base.cc, idx-vector.cc,
oct-alloc.cc, oct-locbuf.cc, oct-locbuf.h, oct-mem.h, oct-sort.cc, oct-time.cc,
sparse-base-chol.cc, sparse-dmsolve.cc, ccolamd.cc, colamd.cc, spparms.cc,
symbfact.cc, symrcm.cc, help.cc, ls-mat5.cc, pt-idx.cc, utils.cc, variables.cc,
zfstream.cc: Cuddle open bracket used for indexing C++ arrays in source code.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 26 Jul 2012 09:25:47 -0700 |
parents | 5ae9f0f77635 |
children |
comparison
equal
deleted
inserted
replaced
15019:ae3670d4df29 | 15020:560317fd5977 |
---|---|
61 OCTAVE_LOCAL_BUFFER (octave_idx_type, Flag, n); | 61 OCTAVE_LOCAL_BUFFER (octave_idx_type, Flag, n); |
62 OCTAVE_LOCAL_BUFFER (octave_idx_type, Pinv, (P ? n : 0)); | 62 OCTAVE_LOCAL_BUFFER (octave_idx_type, Pinv, (P ? n : 0)); |
63 if (P) | 63 if (P) |
64 // If P is present then compute Pinv, the inverse of P | 64 // If P is present then compute Pinv, the inverse of P |
65 for (octave_idx_type k = 0 ; k < n ; k++) | 65 for (octave_idx_type k = 0 ; k < n ; k++) |
66 Pinv [P [k]] = k ; | 66 Pinv[P[k]] = k ; |
67 | 67 |
68 for (octave_idx_type k = 0 ; k < n ; k++) | 68 for (octave_idx_type k = 0 ; k < n ; k++) |
69 { | 69 { |
70 // L(k,:) pattern: all nodes reachable in etree from nz in A(0:k-1,k) | 70 // L(k,:) pattern: all nodes reachable in etree from nz in A(0:k-1,k) |
71 Parent [k] = n ; // parent of k is not yet known | 71 Parent[k] = n ; // parent of k is not yet known |
72 Flag [k] = k ; // mark node k as visited | 72 Flag[k] = k ; // mark node k as visited |
73 octave_idx_type kk = (P) ? (P [k]) : (k) ; // kth original, or permuted, column | 73 octave_idx_type kk = (P) ? (P[k]) : (k) ; // kth original, or permuted, column |
74 octave_idx_type p2 = cidx [kk+1] ; | 74 octave_idx_type p2 = cidx[kk+1] ; |
75 for (octave_idx_type p = cidx [kk] ; p < p2 ; p++) | 75 for (octave_idx_type p = cidx[kk] ; p < p2 ; p++) |
76 { | 76 { |
77 // A (i,k) is nonzero (original or permuted A) | 77 // A (i,k) is nonzero (original or permuted A) |
78 octave_idx_type i = (Pinv) ? (Pinv [ridx [p]]) : (ridx [p]) ; | 78 octave_idx_type i = (Pinv) ? (Pinv[ridx[p]]) : (ridx[p]) ; |
79 if (i < k) | 79 if (i < k) |
80 { | 80 { |
81 // follow path from i to root of etree, stop at flagged node | 81 // follow path from i to root of etree, stop at flagged node |
82 for ( ; Flag [i] != k ; i = Parent [i]) | 82 for ( ; Flag[i] != k ; i = Parent[i]) |
83 { | 83 { |
84 // find parent of i if not yet determined | 84 // find parent of i if not yet determined |
85 if (Parent [i] == n) | 85 if (Parent[i] == n) |
86 Parent [i] = k ; | 86 Parent[i] = k ; |
87 Flag [i] = k ; // mark i as visited | 87 Flag[i] = k ; // mark i as visited |
88 } | 88 } |
89 } | 89 } |
90 } | 90 } |
91 } | 91 } |
92 } | 92 } |
297 { | 297 { |
298 NDArray User_knobs = args(1).array_value (); | 298 NDArray User_knobs = args(1).array_value (); |
299 int nel_User_knobs = User_knobs.length (); | 299 int nel_User_knobs = User_knobs.length (); |
300 | 300 |
301 if (nel_User_knobs > 0) | 301 if (nel_User_knobs > 0) |
302 knobs [COLAMD_DENSE_ROW] = User_knobs (0); | 302 knobs[COLAMD_DENSE_ROW] = User_knobs(0); |
303 if (nel_User_knobs > 1) | 303 if (nel_User_knobs > 1) |
304 knobs [COLAMD_DENSE_COL] = User_knobs (1) ; | 304 knobs[COLAMD_DENSE_COL] = User_knobs(1) ; |
305 if (nel_User_knobs > 2) | 305 if (nel_User_knobs > 2) |
306 spumoni = static_cast<int> (User_knobs (2)); | 306 spumoni = static_cast<int> (User_knobs(2)); |
307 | 307 |
308 // print knob settings if spumoni is set | 308 // print knob settings if spumoni is set |
309 if (spumoni) | 309 if (spumoni) |
310 { | 310 { |
311 | 311 |
312 octave_stdout << "\ncolamd version " << COLAMD_MAIN_VERSION << "." | 312 octave_stdout << "\ncolamd version " << COLAMD_MAIN_VERSION << "." |
313 << COLAMD_SUB_VERSION << ", " << COLAMD_DATE << ":\n"; | 313 << COLAMD_SUB_VERSION << ", " << COLAMD_DATE << ":\n"; |
314 | 314 |
315 if (knobs [COLAMD_DENSE_ROW] >= 0) | 315 if (knobs[COLAMD_DENSE_ROW] >= 0) |
316 octave_stdout << "knobs(1): " << User_knobs (0) | 316 octave_stdout << "knobs(1): " << User_knobs (0) |
317 << ", rows with > max (16," | 317 << ", rows with > max (16," |
318 << knobs [COLAMD_DENSE_ROW] << "*sqrt (size(A,2)))" | 318 << knobs[COLAMD_DENSE_ROW] << "*sqrt (size(A,2)))" |
319 << " entries removed\n"; | 319 << " entries removed\n"; |
320 else | 320 else |
321 octave_stdout << "knobs(1): " << User_knobs (0) | 321 octave_stdout << "knobs(1): " << User_knobs (0) |
322 << ", only completely dense rows removed\n"; | 322 << ", only completely dense rows removed\n"; |
323 | 323 |
324 if (knobs [COLAMD_DENSE_COL] >= 0) | 324 if (knobs[COLAMD_DENSE_COL] >= 0) |
325 octave_stdout << "knobs(2): " << User_knobs (1) | 325 octave_stdout << "knobs(2): " << User_knobs (1) |
326 << ", cols with > max (16," | 326 << ", cols with > max (16," |
327 << knobs [COLAMD_DENSE_COL] << "*sqrt (size(A)))" | 327 << knobs[COLAMD_DENSE_COL] << "*sqrt (size(A)))" |
328 << " entries removed\n"; | 328 << " entries removed\n"; |
329 else | 329 else |
330 octave_stdout << "knobs(2): " << User_knobs (1) | 330 octave_stdout << "knobs(2): " << User_knobs (1) |
331 << ", only completely dense columns removed\n"; | 331 << ", only completely dense columns removed\n"; |
332 | 332 |
378 } | 378 } |
379 | 379 |
380 // Allocate workspace for colamd | 380 // Allocate workspace for colamd |
381 OCTAVE_LOCAL_BUFFER (octave_idx_type, p, n_col+1); | 381 OCTAVE_LOCAL_BUFFER (octave_idx_type, p, n_col+1); |
382 for (octave_idx_type i = 0; i < n_col+1; i++) | 382 for (octave_idx_type i = 0; i < n_col+1; i++) |
383 p[i] = cidx [i]; | 383 p[i] = cidx[i]; |
384 | 384 |
385 octave_idx_type Alen = COLAMD_NAME (_recommended) (nnz, n_row, n_col); | 385 octave_idx_type Alen = COLAMD_NAME (_recommended) (nnz, n_row, n_col); |
386 OCTAVE_LOCAL_BUFFER (octave_idx_type, A, Alen); | 386 OCTAVE_LOCAL_BUFFER (octave_idx_type, A, Alen); |
387 for (octave_idx_type i = 0; i < nnz; i++) | 387 for (octave_idx_type i = 0; i < nnz; i++) |
388 A[i] = ridx [i]; | 388 A[i] = ridx[i]; |
389 | 389 |
390 // Order the columns (destroys A) | 390 // Order the columns (destroys A) |
391 OCTAVE_LOCAL_BUFFER (octave_idx_type, stats, COLAMD_STATS); | 391 OCTAVE_LOCAL_BUFFER (octave_idx_type, stats, COLAMD_STATS); |
392 if (! COLAMD_NAME () (n_row, n_col, Alen, A, p, knobs, stats)) | 392 if (! COLAMD_NAME () (n_row, n_col, Alen, A, p, knobs, stats)) |
393 { | 393 { |
413 tree_postorder (n_col, etree, colbeg); | 413 tree_postorder (n_col, etree, colbeg); |
414 | 414 |
415 // return the permutation vector | 415 // return the permutation vector |
416 NDArray out_perm (dim_vector (1, n_col)); | 416 NDArray out_perm (dim_vector (1, n_col)); |
417 for (octave_idx_type i = 0; i < n_col; i++) | 417 for (octave_idx_type i = 0; i < n_col; i++) |
418 out_perm(i) = p[colbeg [i]] + 1; | 418 out_perm(i) = p[colbeg[i]] + 1; |
419 | 419 |
420 retval(0) = out_perm; | 420 retval(0) = out_perm; |
421 | 421 |
422 // print stats if spumoni > 0 | 422 // print stats if spumoni > 0 |
423 if (spumoni > 0) | 423 if (spumoni > 0) |
426 // Return the stats vector | 426 // Return the stats vector |
427 if (nargout == 2) | 427 if (nargout == 2) |
428 { | 428 { |
429 NDArray out_stats (dim_vector (1, COLAMD_STATS)); | 429 NDArray out_stats (dim_vector (1, COLAMD_STATS)); |
430 for (octave_idx_type i = 0 ; i < COLAMD_STATS ; i++) | 430 for (octave_idx_type i = 0 ; i < COLAMD_STATS ; i++) |
431 out_stats (i) = stats [i] ; | 431 out_stats(i) = stats[i] ; |
432 retval(1) = out_stats; | 432 retval(1) = out_stats; |
433 | 433 |
434 // fix stats (5) and (6), for 1-based information on | 434 // fix stats (5) and (6), for 1-based information on |
435 // jumbled matrix. note that this correction doesn't | 435 // jumbled matrix. note that this correction doesn't |
436 // occur if symamd returns FALSE | 436 // occur if symamd returns FALSE |
532 { | 532 { |
533 NDArray User_knobs = args(1).array_value (); | 533 NDArray User_knobs = args(1).array_value (); |
534 int nel_User_knobs = User_knobs.length (); | 534 int nel_User_knobs = User_knobs.length (); |
535 | 535 |
536 if (nel_User_knobs > 0) | 536 if (nel_User_knobs > 0) |
537 knobs [COLAMD_DENSE_ROW] = User_knobs (COLAMD_DENSE_ROW); | 537 knobs[COLAMD_DENSE_ROW] = User_knobs(COLAMD_DENSE_ROW); |
538 if (nel_User_knobs > 1) | 538 if (nel_User_knobs > 1) |
539 spumoni = static_cast<int> (User_knobs (1)); | 539 spumoni = static_cast<int> (User_knobs (1)); |
540 } | 540 } |
541 | 541 |
542 // print knob settings if spumoni is set | 542 // print knob settings if spumoni is set |
543 if (spumoni > 0) | 543 if (spumoni > 0) |
544 octave_stdout << "symamd: dense row/col fraction: " | 544 octave_stdout << "symamd: dense row/col fraction: " |
545 << knobs [COLAMD_DENSE_ROW] << std::endl; | 545 << knobs[COLAMD_DENSE_ROW] << std::endl; |
546 | 546 |
547 octave_idx_type n_row, n_col; | 547 octave_idx_type n_row, n_col; |
548 octave_idx_type *ridx, *cidx; | 548 octave_idx_type *ridx, *cidx; |
549 SparseMatrix sm; | 549 SparseMatrix sm; |
550 SparseComplexMatrix scm; | 550 SparseComplexMatrix scm; |
606 tree_postorder (n_col, etree, post); | 606 tree_postorder (n_col, etree, post); |
607 | 607 |
608 // return the permutation vector | 608 // return the permutation vector |
609 NDArray out_perm (dim_vector (1, n_col)); | 609 NDArray out_perm (dim_vector (1, n_col)); |
610 for (octave_idx_type i = 0; i < n_col; i++) | 610 for (octave_idx_type i = 0; i < n_col; i++) |
611 out_perm(i) = perm[post [i]] + 1; | 611 out_perm(i) = perm[post[i]] + 1; |
612 | 612 |
613 retval(0) = out_perm; | 613 retval(0) = out_perm; |
614 | 614 |
615 // print stats if spumoni > 0 | 615 // print stats if spumoni > 0 |
616 if (spumoni > 0) | 616 if (spumoni > 0) |
619 // Return the stats vector | 619 // Return the stats vector |
620 if (nargout == 2) | 620 if (nargout == 2) |
621 { | 621 { |
622 NDArray out_stats (dim_vector (1, COLAMD_STATS)); | 622 NDArray out_stats (dim_vector (1, COLAMD_STATS)); |
623 for (octave_idx_type i = 0 ; i < COLAMD_STATS ; i++) | 623 for (octave_idx_type i = 0 ; i < COLAMD_STATS ; i++) |
624 out_stats (i) = stats [i] ; | 624 out_stats(i) = stats[i] ; |
625 retval(1) = out_stats; | 625 retval(1) = out_stats; |
626 | 626 |
627 // fix stats (5) and (6), for 1-based information on | 627 // fix stats (5) and (6), for 1-based information on |
628 // jumbled matrix. note that this correction doesn't | 628 // jumbled matrix. note that this correction doesn't |
629 // occur if symamd returns FALSE | 629 // occur if symamd returns FALSE |