feat:node-modules

This commit is contained in:
houjunxiang
2025-11-24 10:26:18 +08:00
parent 753766893b
commit 8a3e48d856
8825 changed files with 567399 additions and 1 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.csCumsum = csCumsum;
// Copyright (c) 2006-2024, Timothy A. Davis, All Rights Reserved.
// SPDX-License-Identifier: LGPL-2.1+
// https://github.com/DrTimothyAldenDavis/SuiteSparse/tree/dev/CSparse/Source
/**
* It sets the p[i] equal to the sum of c[0] through c[i-1].
*
* @param {Array} ptr The Sparse Matrix ptr array
* @param {Array} c The Sparse Matrix ptr array
* @param {Number} n The number of columns
*/
function csCumsum(ptr, c, n) {
// variables
let i;
let nz = 0;
for (i = 0; i < n; i++) {
// initialize ptr @ i
ptr[i] = nz;
// increment number of nonzeros
nz += c[i];
// also copy p[0..n-1] back into c[0..n-1]
c[i] = ptr[i];
}
// finalize ptr
ptr[n] = nz;
// return sum (c [0..n-1])
return nz;
}

View File

@@ -0,0 +1,82 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.csDfs = csDfs;
var _csMarked = require("./csMarked.js");
var _csMark = require("./csMark.js");
var _csUnflip = require("./csUnflip.js");
// Copyright (c) 2006-2024, Timothy A. Davis, All Rights Reserved.
// SPDX-License-Identifier: LGPL-2.1+
// https://github.com/DrTimothyAldenDavis/SuiteSparse/tree/dev/CSparse/Source
/**
* Depth-first search computes the nonzero pattern xi of the directed graph G (Matrix) starting
* at nodes in B (see csReach()).
*
* @param {Number} j The starting node for the DFS algorithm
* @param {Matrix} g The G matrix to search, ptr array modified, then restored
* @param {Number} top Start index in stack xi[top..n-1]
* @param {Number} k The kth column in B
* @param {Array} xi The nonzero pattern xi[top] .. xi[n - 1], an array of size = 2 * n
* The first n entries is the nonzero pattern, the last n entries is the stack
* @param {Array} pinv The inverse row permutation vector, must be null for L * x = b
*
* @return {Number} New value of top
*/
function csDfs(j, g, top, xi, pinv) {
// g arrays
const index = g._index;
const ptr = g._ptr;
const size = g._size;
// columns
const n = size[1];
// vars
let i, p, p2;
// initialize head
let head = 0;
// initialize the recursion stack
xi[0] = j;
// loop
while (head >= 0) {
// get j from the top of the recursion stack
j = xi[head];
// apply permutation vector
const jnew = pinv ? pinv[j] : j;
// check node j is marked
if (!(0, _csMarked.csMarked)(ptr, j)) {
// mark node j as visited
(0, _csMark.csMark)(ptr, j);
// update stack (last n entries in xi)
xi[n + head] = jnew < 0 ? 0 : (0, _csUnflip.csUnflip)(ptr[jnew]);
}
// node j done if no unvisited neighbors
let done = 1;
// examine all neighbors of j, stack (last n entries in xi)
for (p = xi[n + head], p2 = jnew < 0 ? 0 : (0, _csUnflip.csUnflip)(ptr[jnew + 1]); p < p2; p++) {
// consider neighbor node i
i = index[p];
// check we have visited node i, skip it
if ((0, _csMarked.csMarked)(ptr, i)) {
continue;
}
// pause depth-first search of node j, update stack (last n entries in xi)
xi[n + head] = p;
// start dfs at node i
xi[++head] = i;
// node j is not done
done = 0;
// break, to start dfs(i)
break;
}
// check depth-first search at node j is done
if (done) {
// remove j from the recursion stack
head--;
// and place in the output stack
xi[--top] = j;
}
}
return top;
}

View File

@@ -0,0 +1,69 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.csEreach = csEreach;
var _csMark = require("./csMark.js");
var _csMarked = require("./csMarked.js");
// Copyright (c) 2006-2024, Timothy A. Davis, All Rights Reserved.
// SPDX-License-Identifier: LGPL-2.1+
// https://github.com/DrTimothyAldenDavis/SuiteSparse/tree/dev/CSparse/Source
/**
* Find nonzero pattern of Cholesky L(k,1:k-1) using etree and triu(A(:,k))
*
* @param {Matrix} a The A matrix
* @param {Number} k The kth column in A
* @param {Array} parent The parent vector from the symbolic analysis result
* @param {Array} w The nonzero pattern xi[top] .. xi[n - 1], an array of size = 2 * n
* The first n entries is the nonzero pattern, the last n entries is the stack
*
* @return {Number} The index for the nonzero pattern
*/
function csEreach(a, k, parent, w) {
// a arrays
const aindex = a._index;
const aptr = a._ptr;
const asize = a._size;
// columns
const n = asize[1];
// initialize top
let top = n;
// vars
let p, p0, p1, len;
// mark node k as visited
(0, _csMark.csMark)(w, k);
// loop values & index for column k
for (p0 = aptr[k], p1 = aptr[k + 1], p = p0; p < p1; p++) {
// A(i,k) is nonzero
let i = aindex[p];
// only use upper triangular part of A
if (i > k) {
continue;
}
// traverse up etree
for (len = 0; !(0, _csMarked.csMarked)(w, i); i = parent[i]) {
// L(k,i) is nonzero, last n entries in w
w[n + len++] = i;
// mark i as visited
(0, _csMark.csMark)(w, i);
}
while (len > 0) {
// decrement top & len
--top;
--len;
// push path onto stack, last n entries in w
w[n + top] = w[n + len];
}
}
// unmark all nodes
for (p = top; p < n; p++) {
// use stack value, last n entries in w
(0, _csMark.csMark)(w, w[n + p]);
}
// unmark node k
(0, _csMark.csMark)(w, k);
// s[top..n-1] contains pattern of L(k,:)
return top;
}

View File

@@ -0,0 +1,77 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.csEtree = csEtree;
// Copyright (c) 2006-2024, Timothy A. Davis, All Rights Reserved.
// SPDX-License-Identifier: LGPL-2.1+
// https://github.com/DrTimothyAldenDavis/SuiteSparse/tree/dev/CSparse/Source
/**
* Computes the elimination tree of Matrix A (using triu(A)) or the
* elimination tree of A'A without forming A'A.
*
* @param {Matrix} a The A Matrix
* @param {boolean} ata A value of true the function computes the etree of A'A
*/
function csEtree(a, ata) {
// check inputs
if (!a) {
return null;
}
// a arrays
const aindex = a._index;
const aptr = a._ptr;
const asize = a._size;
// rows & columns
const m = asize[0];
const n = asize[1];
// allocate result
const parent = []; // (n)
// allocate workspace
const w = []; // (n + (ata ? m : 0))
const ancestor = 0; // first n entries in w
const prev = n; // last m entries (ata = true)
let i, inext;
// check we are calculating A'A
if (ata) {
// initialize workspace
for (i = 0; i < m; i++) {
w[prev + i] = -1;
}
}
// loop columns
for (let k = 0; k < n; k++) {
// node k has no parent yet
parent[k] = -1;
// nor does k have an ancestor
w[ancestor + k] = -1;
// values in column k
for (let p0 = aptr[k], p1 = aptr[k + 1], p = p0; p < p1; p++) {
// row
const r = aindex[p];
// node
i = ata ? w[prev + r] : r;
// traverse from i to k
for (; i !== -1 && i < k; i = inext) {
// inext = ancestor of i
inext = w[ancestor + i];
// path compression
w[ancestor + i] = k;
// check no anc., parent is k
if (inext === -1) {
parent[i] = k;
}
}
if (ata) {
w[prev + r] = k;
}
}
}
return parent;
}

View File

@@ -0,0 +1,64 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.csFkeep = csFkeep;
// Copyright (c) 2006-2024, Timothy A. Davis, All Rights Reserved.
// SPDX-License-Identifier: LGPL-2.1+
// https://github.com/DrTimothyAldenDavis/SuiteSparse/tree/dev/CSparse/Source
/**
* Keeps entries in the matrix when the callback function returns true, removes the entry otherwise
*
* @param {Matrix} a The sparse matrix
* @param {function} callback The callback function, function will be invoked with the following args:
* - The entry row
* - The entry column
* - The entry value
* - The state parameter
* @param {any} other The state
*
* @return The number of nonzero elements in the matrix
*/
function csFkeep(a, callback, other) {
// a arrays
const avalues = a._values;
const aindex = a._index;
const aptr = a._ptr;
const asize = a._size;
// columns
const n = asize[1];
// nonzero items
let nz = 0;
// loop columns
for (let j = 0; j < n; j++) {
// get current location of col j
let p = aptr[j];
// record new location of col j
aptr[j] = nz;
for (; p < aptr[j + 1]; p++) {
// check we need to keep this item
if (callback(aindex[p], j, avalues ? avalues[p] : 1, other)) {
// keep A(i,j)
aindex[nz] = aindex[p];
// check we need to process values (pattern only)
if (avalues) {
avalues[nz] = avalues[p];
}
// increment nonzero items
nz++;
}
}
}
// finalize A
aptr[n] = nz;
// trim arrays
aindex.splice(nz, aindex.length - nz);
// check we need to process values (pattern only)
if (avalues) {
avalues.splice(nz, avalues.length - nz);
}
// return number of nonzero items
return nz;
}

View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.csFlip = csFlip;
// Copyright (c) 2006-2024, Timothy A. Davis, All Rights Reserved.
// SPDX-License-Identifier: LGPL-2.1+
// https://github.com/DrTimothyAldenDavis/SuiteSparse/tree/dev/CSparse/Source
/**
* This function "flips" its input about the integer -1.
*
* @param {Number} i The value to flip
*/
function csFlip(i) {
// flip the value
return -i - 2;
}

View File

@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.csIpvec = csIpvec;
// Copyright (c) 2006-2024, Timothy A. Davis, All Rights Reserved.
// SPDX-License-Identifier: LGPL-2.1+
// https://github.com/DrTimothyAldenDavis/SuiteSparse/tree/dev/CSparse/Source
/**
* Permutes a vector; x = P'b. In MATLAB notation, x(p)=b.
*
* @param {Array} p The permutation vector of length n. null value denotes identity
* @param {Array} b The input vector
*
* @return {Array} The output vector x = P'b
*/
function csIpvec(p, b) {
// vars
let k;
const n = b.length;
const x = [];
// check permutation vector was provided, p = null denotes identity
if (p) {
// loop vector
for (k = 0; k < n; k++) {
// apply permutation
x[p[k]] = b[k];
}
} else {
// loop vector
for (k = 0; k < n; k++) {
// x[i] = b[i]
x[k] = b[k];
}
}
return x;
}

Some files were not shown because too many files have changed in this diff Show More