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,35 @@
import { createAnd } from '../../function/logical/and.js';
import { factory } from '../../utils/factory.js';
import { isCollection } from '../../utils/is.js';
var name = 'and';
var dependencies = ['typed', 'matrix', 'zeros', 'add', 'equalScalar', 'not', 'concat'];
export var createAndTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
matrix,
equalScalar,
zeros,
not,
concat
} = _ref;
var and = createAnd({
typed,
matrix,
equalScalar,
zeros,
not,
concat
});
function andTransform(args, math, scope) {
var condition1 = args[0].compile().evaluate(scope);
if (!isCollection(condition1) && !and(condition1, true)) {
return false;
}
var condition2 = args[1].compile().evaluate(scope);
return and(condition1, condition2);
}
andTransform.rawArgs = true;
return andTransform;
}, {
isTransformFunction: true
});

View File

@@ -0,0 +1,44 @@
import { errorTransform } from './utils/errorTransform.js';
import { factory } from '../../utils/factory.js';
import { createApply } from '../../function/matrix/apply.js';
import { isBigNumber, isNumber } from '../../utils/is.js';
var name = 'apply';
var dependencies = ['typed', 'isInteger'];
/**
* Attach a transform function to math.apply
* Adds a property transform containing the transform function.
*
* This transform changed the last `dim` parameter of function apply
* from one-based to zero based
*/
export var createApplyTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
isInteger
} = _ref;
var apply = createApply({
typed,
isInteger
});
// @see: comment of concat itself
return typed('apply', {
'...any': function any(args) {
// change dim from one-based to zero-based
var dim = args[1];
if (isNumber(dim)) {
args[1] = dim - 1;
} else if (isBigNumber(dim)) {
args[1] = dim.minus(1);
}
try {
return apply.apply(null, args);
} catch (err) {
throw errorTransform(err);
}
}
});
}, {
isTransformFunction: true
});

View File

@@ -0,0 +1,40 @@
import { createBitAnd } from '../../function/bitwise/bitAnd.js';
import { factory } from '../../utils/factory.js';
import { isCollection } from '../../utils/is.js';
var name = 'bitAnd';
var dependencies = ['typed', 'matrix', 'zeros', 'add', 'equalScalar', 'not', 'concat'];
export var createBitAndTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
matrix,
equalScalar,
zeros,
not,
concat
} = _ref;
var bitAnd = createBitAnd({
typed,
matrix,
equalScalar,
zeros,
not,
concat
});
function bitAndTransform(args, math, scope) {
var condition1 = args[0].compile().evaluate(scope);
if (!isCollection(condition1)) {
if (isNaN(condition1)) {
return NaN;
}
if (condition1 === 0 || condition1 === false) {
return 0;
}
}
var condition2 = args[1].compile().evaluate(scope);
return bitAnd(condition1, condition2);
}
bitAndTransform.rawArgs = true;
return bitAndTransform;
}, {
isTransformFunction: true
});

View File

@@ -0,0 +1,41 @@
import { createBitOr } from '../../function/bitwise/bitOr.js';
import { factory } from '../../utils/factory.js';
import { isCollection } from '../../utils/is.js';
var name = 'bitOr';
var dependencies = ['typed', 'matrix', 'equalScalar', 'DenseMatrix', 'concat'];
export var createBitOrTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
matrix,
equalScalar,
DenseMatrix,
concat
} = _ref;
var bitOr = createBitOr({
typed,
matrix,
equalScalar,
DenseMatrix,
concat
});
function bitOrTransform(args, math, scope) {
var condition1 = args[0].compile().evaluate(scope);
if (!isCollection(condition1)) {
if (isNaN(condition1)) {
return NaN;
}
if (condition1 === -1) {
return -1;
}
if (condition1 === true) {
return 1;
}
}
var condition2 = args[1].compile().evaluate(scope);
return bitOr(condition1, condition2);
}
bitOrTransform.rawArgs = true;
return bitOrTransform;
}, {
isTransformFunction: true
});

View File

@@ -0,0 +1,47 @@
import { errorTransform } from './utils/errorTransform.js';
import { factory } from '../../utils/factory.js';
import { createColumn } from '../../function/matrix/column.js';
import { isNumber } from '../../utils/is.js';
var name = 'column';
var dependencies = ['typed', 'Index', 'matrix', 'range'];
/**
* Attach a transform function to matrix.column
* Adds a property transform containing the transform function.
*
* This transform changed the last `index` parameter of function column
* from zero-based to one-based
*/
export var createColumnTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
Index,
matrix,
range
} = _ref;
var column = createColumn({
typed,
Index,
matrix,
range
});
// @see: comment of column itself
return typed('column', {
'...any': function any(args) {
// change last argument from zero-based to one-based
var lastIndex = args.length - 1;
var last = args[lastIndex];
if (isNumber(last)) {
args[lastIndex] = last - 1;
}
try {
return column.apply(null, args);
} catch (err) {
throw errorTransform(err);
}
}
});
}, {
isTransformFunction: true
});

View File

@@ -0,0 +1,45 @@
import { isBigNumber, isNumber } from '../../utils/is.js';
import { errorTransform } from './utils/errorTransform.js';
import { factory } from '../../utils/factory.js';
import { createConcat } from '../../function/matrix/concat.js';
var name = 'concat';
var dependencies = ['typed', 'matrix', 'isInteger'];
export var createConcatTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
matrix,
isInteger
} = _ref;
var concat = createConcat({
typed,
matrix,
isInteger
});
/**
* Attach a transform function to math.range
* Adds a property transform containing the transform function.
*
* This transform changed the last `dim` parameter of function concat
* from one-based to zero based
*/
return typed('concat', {
'...any': function any(args) {
// change last argument from one-based to zero-based
var lastIndex = args.length - 1;
var last = args[lastIndex];
if (isNumber(last)) {
args[lastIndex] = last - 1;
} else if (isBigNumber(last)) {
args[lastIndex] = last.minus(1);
}
try {
return concat.apply(null, args);
} catch (err) {
throw errorTransform(err);
}
}
});
}, {
isTransformFunction: true
});

View File

@@ -0,0 +1,46 @@
import { isBigNumber, isCollection, isNumber } from '../../utils/is.js';
import { factory } from '../../utils/factory.js';
import { errorTransform } from './utils/errorTransform.js';
import { createCumSum } from '../../function/statistics/cumsum.js';
/**
* Attach a transform function to math.sum
* Adds a property transform containing the transform function.
*
* This transform changed the last `dim` parameter of function sum
* from one-based to zero based
*/
var name = 'cumsum';
var dependencies = ['typed', 'add', 'unaryPlus'];
export var createCumSumTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
add,
unaryPlus
} = _ref;
var cumsum = createCumSum({
typed,
add,
unaryPlus
});
return typed(name, {
'...any': function any(args) {
// change last argument dim from one-based to zero-based
if (args.length === 2 && isCollection(args[0])) {
var dim = args[1];
if (isNumber(dim)) {
args[1] = dim - 1;
} else if (isBigNumber(dim)) {
args[1] = dim.minus(1);
}
}
try {
return cumsum.apply(null, args);
} catch (err) {
throw errorTransform(err);
}
}
});
}, {
isTransformFunction: true
});

View File

@@ -0,0 +1,41 @@
import { factory } from '../../utils/factory.js';
import { errorTransform } from './utils/errorTransform.js';
import { createDiff } from '../../function/matrix/diff.js';
import { lastDimToZeroBase } from './utils/lastDimToZeroBase.js';
var name = 'diff';
var dependencies = ['typed', 'matrix', 'subtract', 'number', 'bignumber'];
export var createDiffTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
matrix,
subtract,
number,
bignumber
} = _ref;
var diff = createDiff({
typed,
matrix,
subtract,
number,
bignumber
});
/**
* Attach a transform function to math.diff
* Adds a property transform containing the transform function.
*
* This transform creates a range which includes the end value
*/
return typed(name, {
'...any': function any(args) {
args = lastDimToZeroBase(args);
try {
return diff.apply(null, args);
} catch (err) {
throw errorTransform(err);
}
}
});
}, {
isTransformFunction: true
});

View File

@@ -0,0 +1,56 @@
import { createFilter } from '../../function/matrix/filter.js';
import { factory } from '../../utils/factory.js';
import { isFunctionAssignmentNode, isSymbolNode } from '../../utils/is.js';
import { compileInlineExpression } from './utils/compileInlineExpression.js';
import { createTransformCallback } from './utils/transformCallback.js';
var name = 'filter';
var dependencies = ['typed'];
export var createFilterTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed
} = _ref;
/**
* Attach a transform function to math.filter
* Adds a property transform containing the transform function.
*
* This transform adds support for equations as test function for math.filter,
* so you can do something like 'filter([3, -2, 5], x > 0)'.
*/
function filterTransform(args, math, scope) {
var filter = createFilter({
typed
});
var transformCallback = createTransformCallback({
typed
});
if (args.length === 0) {
return filter();
}
var x = args[0];
if (args.length === 1) {
return filter(x);
}
var N = args.length - 1;
var callback = args[N];
if (x) {
x = _compileAndEvaluate(x, scope);
}
if (callback) {
if (isSymbolNode(callback) || isFunctionAssignmentNode(callback)) {
// a function pointer, like filter([3, -2, 5], myTestFunction)
callback = _compileAndEvaluate(callback, scope);
} else {
// an expression like filter([3, -2, 5], x > 0)
callback = compileInlineExpression(callback, math, scope);
}
}
return filter(x, transformCallback(callback, N));
}
filterTransform.rawArgs = true;
function _compileAndEvaluate(arg, scope) {
return arg.compile().evaluate(scope);
}
return filterTransform;
}, {
isTransformFunction: true
});

View File

@@ -0,0 +1,55 @@
import { createForEach } from '../../function/matrix/forEach.js';
import { createTransformCallback } from './utils/transformCallback.js';
import { factory } from '../../utils/factory.js';
import { isFunctionAssignmentNode, isSymbolNode } from '../../utils/is.js';
import { compileInlineExpression } from './utils/compileInlineExpression.js';
var name = 'forEach';
var dependencies = ['typed'];
export var createForEachTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed
} = _ref;
/**
* Attach a transform function to math.forEach
* Adds a property transform containing the transform function.
*
* This transform creates a one-based index instead of a zero-based index
*/
var forEach = createForEach({
typed
});
var transformCallback = createTransformCallback({
typed
});
function forEachTransform(args, math, scope) {
if (args.length === 0) {
return forEach();
}
var x = args[0];
if (args.length === 1) {
return forEach(x);
}
var N = args.length - 1;
var callback = args[N];
if (x) {
x = _compileAndEvaluate(x, scope);
}
if (callback) {
if (isSymbolNode(callback) || isFunctionAssignmentNode(callback)) {
// a function pointer, like filter([3, -2, 5], myTestFunction)
callback = _compileAndEvaluate(callback, scope);
} else {
// an expression like filter([3, -2, 5], x > 0)
callback = compileInlineExpression(callback, math, scope);
}
}
return forEach(x, transformCallback(callback, N));
}
forEachTransform.rawArgs = true;
function _compileAndEvaluate(arg, scope) {
return arg.compile().evaluate(scope);
}
return forEachTransform;
}, {
isTransformFunction: true
});

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