* Creates the matrix that will be used by the approximate minimum degree ordering algorithm. The function accepts the matrix M as input and returns a permutation * vector P. The amd algorithm operates on a symmetrix matrix, so one of three symmetric matrices is formed. * * Order: 0 * A
(order, a, m, n, dense)
| 399 | * P = M' * M |
| 400 | */ |
| 401 | function _createTargetMatrix (order, a, m, n, dense) { |
| 402 | // compute A' |
| 403 | const at = transpose(a) |
| 404 | |
| 405 | // check order = 1, matrix must be square |
| 406 | if (order === 1 && n === m) { |
| 407 | // C = A + A' |
| 408 | return add(a, at) |
| 409 | } |
| 410 | |
| 411 | // check order = 2, drop dense columns from M' |
| 412 | if (order === 2) { |
| 413 | // transpose arrays |
| 414 | const tindex = at._index |
| 415 | const tptr = at._ptr |
| 416 | // new column index |
| 417 | let p2 = 0 |
| 418 | // loop A' columns (rows) |
| 419 | for (let j = 0; j < m; j++) { |
| 420 | // column j of AT starts here |
| 421 | let p = tptr[j] |
| 422 | // new column j starts here |
| 423 | tptr[j] = p2 |
| 424 | // skip dense col j |
| 425 | if (tptr[j + 1] - p > dense) { continue } |
| 426 | // map rows in column j of A |
| 427 | for (const p1 = tptr[j + 1]; p < p1; p++) { tindex[p2++] = tindex[p] } |
| 428 | } |
| 429 | // finalize AT |
| 430 | tptr[m] = p2 |
| 431 | // recreate A from new transpose matrix |
| 432 | a = transpose(at) |
| 433 | // use A' * A |
| 434 | return multiply(at, a) |
| 435 | } |
| 436 | |
| 437 | // use A' * A, square or rectangular matrix |
| 438 | return multiply(at, a) |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * Initialize quotient graph. There are four kind of nodes and elements that must be represented: |