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

View File

@@ -0,0 +1,58 @@
import { flatten } from '../../utils/array.js';
import { factory } from '../../utils/factory.js';
var name = 'setCartesian';
var dependencies = ['typed', 'size', 'subset', 'compareNatural', 'Index', 'DenseMatrix'];
export var createSetCartesian = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
size,
subset,
compareNatural,
Index,
DenseMatrix
} = _ref;
/**
* Create the cartesian product of two (multi)sets.
* Multi-dimension arrays will be converted to single-dimension arrays
* and the values will be sorted in ascending order before the operation.
*
* Syntax:
*
* math.setCartesian(set1, set2)
*
* Examples:
*
* math.setCartesian([1, 2], [3, 4]) // returns [[1, 3], [1, 4], [2, 3], [2, 4]]
* math.setCartesian([4, 3], [2, 1]) // returns [[3, 1], [3, 2], [4, 1], [4, 2]]
*
* See also:
*
* setUnion, setIntersect, setDifference, setPowerset
*
* @param {Array | Matrix} a1 A (multi)set
* @param {Array | Matrix} a2 A (multi)set
* @return {Array | Matrix} The cartesian product of two (multi)sets
*/
return typed(name, {
'Array | Matrix, Array | Matrix': function Array__Matrix_Array__Matrix(a1, a2) {
var result = [];
if (subset(size(a1), new Index(0)) !== 0 && subset(size(a2), new Index(0)) !== 0) {
// if any of them is empty, return empty
var b1 = flatten(Array.isArray(a1) ? a1 : a1.toArray()).sort(compareNatural);
var b2 = flatten(Array.isArray(a2) ? a2 : a2.toArray()).sort(compareNatural);
result = [];
for (var i = 0; i < b1.length; i++) {
for (var j = 0; j < b2.length; j++) {
result.push([b1[i], b2[j]]);
}
}
}
// return an array, if both inputs were arrays
if (Array.isArray(a1) && Array.isArray(a2)) {
return result;
}
// return a matrix otherwise
return new DenseMatrix(result);
}
});
});

View File

@@ -0,0 +1,71 @@
import { flatten, generalize, identify } from '../../utils/array.js';
import { factory } from '../../utils/factory.js';
var name = 'setDifference';
var dependencies = ['typed', 'size', 'subset', 'compareNatural', 'Index', 'DenseMatrix'];
export var createSetDifference = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
size,
subset,
compareNatural,
Index,
DenseMatrix
} = _ref;
/**
* Create the difference of two (multi)sets: every element of set1, that is not the element of set2.
* Multi-dimension arrays will be converted to single-dimension arrays before the operation.
*
* Syntax:
*
* math.setDifference(set1, set2)
*
* Examples:
*
* math.setDifference([1, 2, 3, 4], [3, 4, 5, 6]) // returns [1, 2]
* math.setDifference([[1, 2], [3, 4]], [[3, 4], [5, 6]]) // returns [1, 2]
*
* See also:
*
* setUnion, setIntersect, setSymDifference
*
* @param {Array | Matrix} a1 A (multi)set
* @param {Array | Matrix} a2 A (multi)set
* @return {Array | Matrix} The difference of two (multi)sets
*/
return typed(name, {
'Array | Matrix, Array | Matrix': function Array__Matrix_Array__Matrix(a1, a2) {
var result;
if (subset(size(a1), new Index(0)) === 0) {
// empty-anything=empty
result = [];
} else if (subset(size(a2), new Index(0)) === 0) {
// anything-empty=anything
return flatten(a1.toArray());
} else {
var b1 = identify(flatten(Array.isArray(a1) ? a1 : a1.toArray()).sort(compareNatural));
var b2 = identify(flatten(Array.isArray(a2) ? a2 : a2.toArray()).sort(compareNatural));
result = [];
var inb2;
for (var i = 0; i < b1.length; i++) {
inb2 = false;
for (var j = 0; j < b2.length; j++) {
if (compareNatural(b1[i].value, b2[j].value) === 0 && b1[i].identifier === b2[j].identifier) {
// the identifier is always a decimal int
inb2 = true;
break;
}
}
if (!inb2) {
result.push(b1[i]);
}
}
}
// return an array, if both inputs were arrays
if (Array.isArray(a1) && Array.isArray(a2)) {
return generalize(result);
}
// return a matrix otherwise
return new DenseMatrix(generalize(result));
}
});
});

View File

@@ -0,0 +1,57 @@
import { flatten } from '../../utils/array.js';
import { factory } from '../../utils/factory.js';
var name = 'setDistinct';
var dependencies = ['typed', 'size', 'subset', 'compareNatural', 'Index', 'DenseMatrix'];
export var createSetDistinct = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
size,
subset,
compareNatural,
Index,
DenseMatrix
} = _ref;
/**
* Collect the distinct elements of a multiset.
* A multi-dimension array will be converted to a single-dimension array before the operation.
*
* Syntax:
*
* math.setDistinct(set)
*
* Examples:
*
* math.setDistinct([1, 1, 1, 2, 2, 3]) // returns [1, 2, 3]
*
* See also:
*
* setMultiplicity
*
* @param {Array | Matrix} a A multiset
* @return {Array | Matrix} A set containing the distinc elements of the multiset
*/
return typed(name, {
'Array | Matrix': function Array__Matrix(a) {
var result;
if (subset(size(a), new Index(0)) === 0) {
// if empty, return empty
result = [];
} else {
var b = flatten(Array.isArray(a) ? a : a.toArray()).sort(compareNatural);
result = [];
result.push(b[0]);
for (var i = 1; i < b.length; i++) {
if (compareNatural(b[i], b[i - 1]) !== 0) {
result.push(b[i]);
}
}
}
// return an array, if the input was an array
if (Array.isArray(a)) {
return result;
}
// return a matrix otherwise
return new DenseMatrix(result);
}
});
});

View File

@@ -0,0 +1,63 @@
import { flatten, generalize, identify } from '../../utils/array.js';
import { factory } from '../../utils/factory.js';
var name = 'setIntersect';
var dependencies = ['typed', 'size', 'subset', 'compareNatural', 'Index', 'DenseMatrix'];
export var createSetIntersect = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
size,
subset,
compareNatural,
Index,
DenseMatrix
} = _ref;
/**
* Create the intersection of two (multi)sets.
* Multi-dimension arrays will be converted to single-dimension arrays before the operation.
*
* Syntax:
*
* math.setIntersect(set1, set2)
*
* Examples:
*
* math.setIntersect([1, 2, 3, 4], [3, 4, 5, 6]) // returns [3, 4]
* math.setIntersect([[1, 2], [3, 4]], [[3, 4], [5, 6]]) // returns [3, 4]
*
* See also:
*
* setUnion, setDifference
*
* @param {Array | Matrix} a1 A (multi)set
* @param {Array | Matrix} a2 A (multi)set
* @return {Array | Matrix} The intersection of two (multi)sets
*/
return typed(name, {
'Array | Matrix, Array | Matrix': function Array__Matrix_Array__Matrix(a1, a2) {
var result;
if (subset(size(a1), new Index(0)) === 0 || subset(size(a2), new Index(0)) === 0) {
// of any of them is empty, return empty
result = [];
} else {
var b1 = identify(flatten(Array.isArray(a1) ? a1 : a1.toArray()).sort(compareNatural));
var b2 = identify(flatten(Array.isArray(a2) ? a2 : a2.toArray()).sort(compareNatural));
result = [];
for (var i = 0; i < b1.length; i++) {
for (var j = 0; j < b2.length; j++) {
if (compareNatural(b1[i].value, b2[j].value) === 0 && b1[i].identifier === b2[j].identifier) {
// the identifier is always a decimal int
result.push(b1[i]);
break;
}
}
}
}
// return an array, if both inputs were arrays
if (Array.isArray(a1) && Array.isArray(a2)) {
return generalize(result);
}
// return a matrix otherwise
return new DenseMatrix(generalize(result));
}
});
});

View File

@@ -0,0 +1,62 @@
import { flatten, identify } from '../../utils/array.js';
import { factory } from '../../utils/factory.js';
var name = 'setIsSubset';
var dependencies = ['typed', 'size', 'subset', 'compareNatural', 'Index'];
export var createSetIsSubset = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
size,
subset,
compareNatural,
Index
} = _ref;
/**
* Check whether a (multi)set is a subset of another (multi)set. (Every element of set1 is the element of set2.)
* Multi-dimension arrays will be converted to single-dimension arrays before the operation.
*
* Syntax:
*
* math.setIsSubset(set1, set2)
*
* Examples:
*
* math.setIsSubset([1, 2], [3, 4, 5, 6]) // returns false
* math.setIsSubset([3, 4], [3, 4, 5, 6]) // returns true
*
* See also:
*
* setUnion, setIntersect, setDifference
*
* @param {Array | Matrix} a1 A (multi)set
* @param {Array | Matrix} a2 A (multi)set
* @return {boolean} Returns true when a1 is a subset of a2, returns false otherwise
*/
return typed(name, {
'Array | Matrix, Array | Matrix': function Array__Matrix_Array__Matrix(a1, a2) {
if (subset(size(a1), new Index(0)) === 0) {
// empty is a subset of anything
return true;
} else if (subset(size(a2), new Index(0)) === 0) {
// anything is not a subset of empty
return false;
}
var b1 = identify(flatten(Array.isArray(a1) ? a1 : a1.toArray()).sort(compareNatural));
var b2 = identify(flatten(Array.isArray(a2) ? a2 : a2.toArray()).sort(compareNatural));
var inb2;
for (var i = 0; i < b1.length; i++) {
inb2 = false;
for (var j = 0; j < b2.length; j++) {
if (compareNatural(b1[i].value, b2[j].value) === 0 && b1[i].identifier === b2[j].identifier) {
// the identifier is always a decimal int
inb2 = true;
break;
}
}
if (inb2 === false) {
return false;
}
}
return true;
}
});
});

View File

@@ -0,0 +1,50 @@
import { flatten } from '../../utils/array.js';
import { factory } from '../../utils/factory.js';
var name = 'setMultiplicity';
var dependencies = ['typed', 'size', 'subset', 'compareNatural', 'Index'];
export var createSetMultiplicity = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
size,
subset,
compareNatural,
Index
} = _ref;
/**
* Count the multiplicity of an element in a multiset.
* A multi-dimension array will be converted to a single-dimension array before the operation.
*
* Syntax:
*
* math.setMultiplicity(element, set)
*
* Examples:
*
* math.setMultiplicity(1, [1, 2, 2, 4]) // returns 1
* math.setMultiplicity(2, [1, 2, 2, 4]) // returns 2
*
* See also:
*
* setDistinct, setSize
*
* @param {number | BigNumber | Fraction | Complex} e An element in the multiset
* @param {Array | Matrix} a A multiset
* @return {number} The number of how many times the multiset contains the element
*/
return typed(name, {
'number | BigNumber | Fraction | Complex, Array | Matrix': function number__BigNumber__Fraction__Complex_Array__Matrix(e, a) {
if (subset(size(a), new Index(0)) === 0) {
// if empty, return 0
return 0;
}
var b = flatten(Array.isArray(a) ? a : a.toArray());
var count = 0;
for (var i = 0; i < b.length; i++) {
if (compareNatural(b[i], e) === 0) {
count++;
}
}
return count;
}
});
});

View File

@@ -0,0 +1,75 @@
import { flatten } from '../../utils/array.js';
import { factory } from '../../utils/factory.js';
var name = 'setPowerset';
var dependencies = ['typed', 'size', 'subset', 'compareNatural', 'Index'];
export var createSetPowerset = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
size,
subset,
compareNatural,
Index
} = _ref;
/**
* Create the powerset of a (multi)set. (The powerset contains very possible subsets of a (multi)set.)
* A multi-dimension array will be converted to a single-dimension array before the operation.
*
* Syntax:
*
* math.setPowerset(set)
*
* Examples:
*
* math.setPowerset([1, 2, 3]) // returns [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]
*
* See also:
*
* setCartesian
*
* @param {Array | Matrix} a A (multi)set
* @return {Array} The powerset of the (multi)set
*/
return typed(name, {
'Array | Matrix': function Array__Matrix(a) {
if (subset(size(a), new Index(0)) === 0) {
// if empty, return empty
return [];
}
var b = flatten(Array.isArray(a) ? a : a.toArray()).sort(compareNatural);
var result = [];
var number = 0;
while (number.toString(2).length <= b.length) {
result.push(_subset(b, number.toString(2).split('').reverse()));
number++;
}
// can not return a matrix, because of the different size of the subarrays
return _sort(result);
}
});
// create subset
function _subset(array, bitarray) {
var result = [];
for (var i = 0; i < bitarray.length; i++) {
if (bitarray[i] === '1') {
result.push(array[i]);
}
}
return result;
}
// sort subsests by length
function _sort(array) {
var temp = [];
for (var i = array.length - 1; i > 0; i--) {
for (var j = 0; j < i; j++) {
if (array[j].length > array[j + 1].length) {
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
return array;
}
});

51
node_modules/mathjs/lib/esm/function/set/setSize.js generated vendored Normal file
View File

@@ -0,0 +1,51 @@
import { flatten } from '../../utils/array.js';
import { factory } from '../../utils/factory.js';
var name = 'setSize';
var dependencies = ['typed', 'compareNatural'];
export var createSetSize = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
compareNatural
} = _ref;
/**
* Count the number of elements of a (multi)set. When a second parameter is 'true', count only the unique values.
* A multi-dimension array will be converted to a single-dimension array before the operation.
*
* Syntax:
*
* math.setSize(set)
* math.setSize(set, unique)
*
* Examples:
*
* math.setSize([1, 2, 2, 4]) // returns 4
* math.setSize([1, 2, 2, 4], true) // returns 3
*
* See also:
*
* setUnion, setIntersect, setDifference
*
* @param {Array | Matrix} a A multiset
* @param {boolean} [unique] If true, only the unique values are counted. False by default
* @return {number} The number of elements of the (multi)set
*/
return typed(name, {
'Array | Matrix': function Array__Matrix(a) {
return Array.isArray(a) ? flatten(a).length : flatten(a.toArray()).length;
},
'Array | Matrix, boolean': function Array__Matrix_boolean(a, unique) {
if (unique === false || a.length === 0) {
return Array.isArray(a) ? flatten(a).length : flatten(a.toArray()).length;
} else {
var b = flatten(Array.isArray(a) ? a : a.toArray()).sort(compareNatural);
var count = 1;
for (var i = 1; i < b.length; i++) {
if (compareNatural(b[i], b[i - 1]) !== 0) {
count++;
}
}
return count;
}
}
});
});

View File

@@ -0,0 +1,48 @@
import { flatten } from '../../utils/array.js';
import { factory } from '../../utils/factory.js';
var name = 'setSymDifference';
var dependencies = ['typed', 'size', 'concat', 'subset', 'setDifference', 'Index'];
export var createSetSymDifference = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
size,
concat,
subset,
setDifference,
Index
} = _ref;
/**
* Create the symmetric difference of two (multi)sets.
* Multi-dimension arrays will be converted to single-dimension arrays before the operation.
*
* Syntax:
*
* math.setSymDifference(set1, set2)
*
* Examples:
*
* math.setSymDifference([1, 2, 3, 4], [3, 4, 5, 6]) // returns [1, 2, 5, 6]
* math.setSymDifference([[1, 2], [3, 4]], [[3, 4], [5, 6]]) // returns [1, 2, 5, 6]
*
* See also:
*
* setUnion, setIntersect, setDifference
*
* @param {Array | Matrix} a1 A (multi)set
* @param {Array | Matrix} a2 A (multi)set
* @return {Array | Matrix} The symmetric difference of two (multi)sets
*/
return typed(name, {
'Array | Matrix, Array | Matrix': function Array__Matrix_Array__Matrix(a1, a2) {
if (subset(size(a1), new Index(0)) === 0) {
// if any of them is empty, return the other one
return flatten(a2);
} else if (subset(size(a2), new Index(0)) === 0) {
return flatten(a1);
}
var b1 = flatten(a1);
var b2 = flatten(a2);
return concat(setDifference(b1, b2), setDifference(b2, b1));
}
});
});

49
node_modules/mathjs/lib/esm/function/set/setUnion.js generated vendored Normal file
View File

@@ -0,0 +1,49 @@
import { flatten } from '../../utils/array.js';
import { factory } from '../../utils/factory.js';
var name = 'setUnion';
var dependencies = ['typed', 'size', 'concat', 'subset', 'setIntersect', 'setSymDifference', 'Index'];
export var createSetUnion = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
size,
concat,
subset,
setIntersect,
setSymDifference,
Index
} = _ref;
/**
* Create the union of two (multi)sets.
* Multi-dimension arrays will be converted to single-dimension arrays before the operation.
*
* Syntax:
*
* math.setUnion(set1, set2)
*
* Examples:
*
* math.setUnion([1, 2, 3, 4], [3, 4, 5, 6]) // returns [1, 2, 3, 4, 5, 6]
* math.setUnion([[1, 2], [3, 4]], [[3, 4], [5, 6]]) // returns [1, 2, 3, 4, 5, 6]
*
* See also:
*
* setIntersect, setDifference
*
* @param {Array | Matrix} a1 A (multi)set
* @param {Array | Matrix} a2 A (multi)set
* @return {Array | Matrix} The union of two (multi)sets
*/
return typed(name, {
'Array | Matrix, Array | Matrix': function Array__Matrix_Array__Matrix(a1, a2) {
if (subset(size(a1), new Index(0)) === 0) {
// if any of them is empty, return the other one
return flatten(a2);
} else if (subset(size(a2), new Index(0)) === 0) {
return flatten(a1);
}
var b1 = flatten(a1);
var b2 = flatten(a2);
return concat(setSymDifference(b1, b2), setIntersect(b1, b2));
}
});
});