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,28 @@
// 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
*/
export function csCumsum(ptr, c, n) {
// variables
var i;
var 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,76 @@
// 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
import { csMarked } from './csMarked.js';
import { csMark } from './csMark.js';
import { csUnflip } from './csUnflip.js';
/**
* 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
*/
export function csDfs(j, g, top, xi, pinv) {
// g arrays
var index = g._index;
var ptr = g._ptr;
var size = g._size;
// columns
var n = size[1];
// vars
var i, p, p2;
// initialize head
var 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
var jnew = pinv ? pinv[j] : j;
// check node j is marked
if (!csMarked(ptr, j)) {
// mark node j as visited
csMark(ptr, j);
// update stack (last n entries in xi)
xi[n + head] = jnew < 0 ? 0 : csUnflip(ptr[jnew]);
}
// node j done if no unvisited neighbors
var done = 1;
// examine all neighbors of j, stack (last n entries in xi)
for (p = xi[n + head], p2 = jnew < 0 ? 0 : csUnflip(ptr[jnew + 1]); p < p2; p++) {
// consider neighbor node i
i = index[p];
// check we have visited node i, skip it
if (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,63 @@
// 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
import { csMark } from './csMark.js';
import { csMarked } from './csMarked.js';
/**
* 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
*/
export function csEreach(a, k, parent, w) {
// a arrays
var aindex = a._index;
var aptr = a._ptr;
var asize = a._size;
// columns
var n = asize[1];
// initialize top
var top = n;
// vars
var p, p0, p1, len;
// mark node k as visited
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
var i = aindex[p];
// only use upper triangular part of A
if (i > k) {
continue;
}
// traverse up etree
for (len = 0; !csMarked(w, i); i = parent[i]) {
// L(k,i) is nonzero, last n entries in w
w[n + len++] = i;
// mark i as visited
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
csMark(w, w[n + p]);
}
// unmark node k
csMark(w, k);
// s[top..n-1] contains pattern of L(k,:)
return top;
}

View File

@@ -0,0 +1,71 @@
// 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
*/
export function csEtree(a, ata) {
// check inputs
if (!a) {
return null;
}
// a arrays
var aindex = a._index;
var aptr = a._ptr;
var asize = a._size;
// rows & columns
var m = asize[0];
var n = asize[1];
// allocate result
var parent = []; // (n)
// allocate workspace
var w = []; // (n + (ata ? m : 0))
var ancestor = 0; // first n entries in w
var prev = n; // last m entries (ata = true)
var 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 (var 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 (var p0 = aptr[k], p1 = aptr[k + 1], p = p0; p < p1; p++) {
// row
var 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,58 @@
// 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
*/
export function csFkeep(a, callback, other) {
// a arrays
var avalues = a._values;
var aindex = a._index;
var aptr = a._ptr;
var asize = a._size;
// columns
var n = asize[1];
// nonzero items
var nz = 0;
// loop columns
for (var j = 0; j < n; j++) {
// get current location of col j
var 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,13 @@
// 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
*/
export function csFlip(i) {
// flip the value
return -i - 2;
}

View File

@@ -0,0 +1,33 @@
// 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
*/
export function csIpvec(p, b) {
// vars
var k;
var n = b.length;
var 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