This commit is contained in:
yuanteng0011 2025-04-05 16:12:28 +08:00
parent 8272aa9c7a
commit aabda4cca2
16 changed files with 552 additions and 0 deletions

View File

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mapSlicesDependencies = void 0;
var _dependenciesIsIntegerGenerated = require("./dependenciesIsInteger.generated.js");
var _dependenciesTypedGenerated = require("./dependenciesTyped.generated.js");
var _factoriesAny = require("../../factoriesAny.js");
/**
* THIS FILE IS AUTO-GENERATED
* DON'T MAKE CHANGES HERE
*/
const mapSlicesDependencies = exports.mapSlicesDependencies = {
isIntegerDependencies: _dependenciesIsIntegerGenerated.isIntegerDependencies,
typedDependencies: _dependenciesTypedGenerated.typedDependencies,
createMapSlices: _factoriesAny.createMapSlices
};

View File

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mapSlicesTransformDependencies = void 0;
var _dependenciesIsIntegerGenerated = require("./dependenciesIsInteger.generated.js");
var _dependenciesTypedGenerated = require("./dependenciesTyped.generated.js");
var _factoriesAny = require("../../factoriesAny.js");
/**
* THIS FILE IS AUTO-GENERATED
* DON'T MAKE CHANGES HERE
*/
const mapSlicesTransformDependencies = exports.mapSlicesTransformDependencies = {
isIntegerDependencies: _dependenciesIsIntegerGenerated.isIntegerDependencies,
typedDependencies: _dependenciesTypedGenerated.typedDependencies,
createMapSlicesTransform: _factoriesAny.createMapSlicesTransform
};

View File

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mapSlicesDependencies = void 0;
var _dependenciesIsIntegerGenerated = require("./dependenciesIsInteger.generated.js");
var _dependenciesTypedGenerated = require("./dependenciesTyped.generated.js");
var _factoriesNumber = require("../../factoriesNumber.js");
/**
* THIS FILE IS AUTO-GENERATED
* DON'T MAKE CHANGES HERE
*/
const mapSlicesDependencies = exports.mapSlicesDependencies = {
isIntegerDependencies: _dependenciesIsIntegerGenerated.isIntegerDependencies,
typedDependencies: _dependenciesTypedGenerated.typedDependencies,
createMapSlices: _factoriesNumber.createMapSlices
};

View File

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mapSlicesTransformDependencies = void 0;
var _dependenciesIsIntegerGenerated = require("./dependenciesIsInteger.generated.js");
var _dependenciesTypedGenerated = require("./dependenciesTyped.generated.js");
var _factoriesNumber = require("../../factoriesNumber.js");
/**
* THIS FILE IS AUTO-GENERATED
* DON'T MAKE CHANGES HERE
*/
const mapSlicesTransformDependencies = exports.mapSlicesTransformDependencies = {
isIntegerDependencies: _dependenciesIsIntegerGenerated.isIntegerDependencies,
typedDependencies: _dependenciesTypedGenerated.typedDependencies,
createMapSlicesTransform: _factoriesNumber.createMapSlicesTransform
};

View File

@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mapSlicesDocs = void 0;
const mapSlicesDocs = exports.mapSlicesDocs = {
name: 'mapSlices',
category: 'Matrix',
syntax: ['mapSlices(A, dim, callback)'],
description: 'Generate a matrix one dimension less than A by applying callback to ' + 'each slice of A along dimension dim.',
examples: ['A = [[1, 2], [3, 4]]', 'mapSlices(A, 1, sum)',
// returns [4, 6]
'mapSlices(A, 2, prod)' // returns [2, 12]
],
seealso: ['map', 'forEach']
};

View File

@ -0,0 +1,51 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createMapSlicesTransform = void 0;
var _errorTransform = require("./utils/errorTransform.js");
var _factory = require("../../utils/factory.js");
var _mapSlices = require("../../function/matrix/mapSlices.js");
var _is = require("../../utils/is.js");
const name = 'mapSlices';
const dependencies = ['typed', 'isInteger'];
/**
* Attach a transform function to math.mapSlices
* Adds a property transform containing the transform function.
*
* This transform changed the last `dim` parameter of function mapSlices
* from one-based to zero based
*/
const createMapSlicesTransform = exports.createMapSlicesTransform = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
typed,
isInteger
} = _ref;
const mapSlices = (0, _mapSlices.createMapSlices)({
typed,
isInteger
});
// @see: comment of concat itself
return typed('mapSlices', {
'...any': function (args) {
// change dim from one-based to zero-based
const dim = args[1];
if ((0, _is.isNumber)(dim)) {
args[1] = dim - 1;
} else if ((0, _is.isBigNumber)(dim)) {
args[1] = dim.minus(1);
}
try {
return mapSlices.apply(null, args);
} catch (err) {
throw (0, _errorTransform.errorTransform)(err);
}
}
});
}, {
isTransformFunction: true,
..._mapSlices.createMapSlices.meta
});

View File

@ -0,0 +1,124 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createMapSlices = void 0;
var _factory = require("../../utils/factory.js");
var _array = require("../../utils/array.js");
var _is = require("../../utils/is.js");
var _IndexError = require("../../error/IndexError.js");
const name = 'mapSlices';
const dependencies = ['typed', 'isInteger'];
const createMapSlices = exports.createMapSlices = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
let {
typed,
isInteger
} = _ref;
/**
* Apply a function that maps an array to a scalar
* along a given axis of a matrix or array.
* Returns a new matrix or array with one less dimension than the input.
*
* Syntax:
*
* math.mapSlices(A, dim, callback)
*
* Where:
*
* - `dim: number` is a zero-based dimension over which to concatenate the matrices.
*
* Examples:
*
* const A = [[1, 2], [3, 4]]
* const sum = math.sum
*
* math.mapSlices(A, 0, sum) // returns [4, 6]
* math.mapSlices(A, 1, sum) // returns [3, 7]
*
* See also:
*
* map, filter, forEach
*
* Note:
*
* `mapSlices()` is also currently available via its deprecated
* synonym `apply()`.
*
* @param {Array | Matrix} array The input Matrix
* @param {number} dim The dimension along which the callback is applied
* @param {Function} callback The callback function that is applied. This Function
* should take an array or 1-d matrix as an input and
* return a number.
* @return {Array | Matrix} res The residual matrix with the function mapped on the slices over some dimension.
*/
return typed(name, {
'Array | Matrix, number | BigNumber, function': function (mat, dim, callback) {
if (!isInteger(dim)) {
throw new TypeError('Integer number expected for dimension');
}
const size = Array.isArray(mat) ? (0, _array.arraySize)(mat) : mat.size();
if (dim < 0 || dim >= size.length) {
throw new _IndexError.IndexError(dim, size.length);
}
if ((0, _is.isMatrix)(mat)) {
return mat.create(_mapSlices(mat.valueOf(), dim, callback), mat.datatype());
} else {
return _mapSlices(mat, dim, callback);
}
}
});
}, {
formerly: 'apply'
});
/**
* Recursively reduce a matrix
* @param {Array} mat
* @param {number} dim
* @param {Function} callback
* @returns {Array} ret
* @private
*/
function _mapSlices(mat, dim, callback) {
let i, ret, tran;
if (dim <= 0) {
if (!Array.isArray(mat[0])) {
return callback(mat);
} else {
tran = _switch(mat);
ret = [];
for (i = 0; i < tran.length; i++) {
ret[i] = _mapSlices(tran[i], dim - 1, callback);
}
return ret;
}
} else {
ret = [];
for (i = 0; i < mat.length; i++) {
ret[i] = _mapSlices(mat[i], dim - 1, callback);
}
return ret;
}
}
/**
* Transpose a matrix
* @param {Array} mat
* @returns {Array} ret
* @private
*/
function _switch(mat) {
const I = mat.length;
const J = mat[0].length;
let i, j;
const ret = [];
for (j = 0; j < J; j++) {
const tmp = [];
for (i = 0; i < I; i++) {
tmp.push(mat[i][j]);
}
ret.push(tmp);
}
return ret;
}

33
node_modules/mathjs/lib/cjs/utils/bigint.js generated vendored Normal file
View File

@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.promoteLogarithm = promoteLogarithm;
/**
* Build a bigint logarithm function from a number logarithm,
* still returning a number. The idea is that 15 hexadecimal digits
* (60 bits) saturates the mantissa of the log, and each additional hex
* digit effectively just adds the log of 16 to the resulting value. So
* convert the most significant 15 hex digits to a number and take its
* log, and then add the log of 16 for each additional hex digit that
* was in the bigint.
* For negative numbers (complex logarithms), following the bignum
* implementation, it just downgrades to number and uses the complex result.
* @param {number} log16 the log of 16
* @param {(number) -> number} numberLog the logarithm function for numbers
* @param {ConfigurationObject} config the mathjs configuration
* @param {(number) -> Complex} cplx the associated Complex log
* @returns {(bigint) -> number} the corresponding logarithm for bigints
*/
function promoteLogarithm(log16, numberLog, config, cplx) {
return function (b) {
if (b > 0 || config.predictable) {
if (b <= 0) return NaN;
const s = b.toString(16);
const s15 = s.substring(0, 15);
return log16 * (s.length - s15.length) + numberLog(Number('0x' + s15));
}
return cplx(b.toNumber());
};
}

View File

@ -0,0 +1,12 @@
/**
* THIS FILE IS AUTO-GENERATED
* DON'T MAKE CHANGES HERE
*/
import { isIntegerDependencies } from './dependenciesIsInteger.generated.js';
import { typedDependencies } from './dependenciesTyped.generated.js';
import { createMapSlices } from '../../factoriesAny.js';
export var mapSlicesDependencies = {
isIntegerDependencies,
typedDependencies,
createMapSlices
};

View File

@ -0,0 +1,12 @@
/**
* THIS FILE IS AUTO-GENERATED
* DON'T MAKE CHANGES HERE
*/
import { isIntegerDependencies } from './dependenciesIsInteger.generated.js';
import { typedDependencies } from './dependenciesTyped.generated.js';
import { createMapSlicesTransform } from '../../factoriesAny.js';
export var mapSlicesTransformDependencies = {
isIntegerDependencies,
typedDependencies,
createMapSlicesTransform
};

View File

@ -0,0 +1,12 @@
/**
* THIS FILE IS AUTO-GENERATED
* DON'T MAKE CHANGES HERE
*/
import { isIntegerDependencies } from './dependenciesIsInteger.generated.js';
import { typedDependencies } from './dependenciesTyped.generated.js';
import { createMapSlices } from '../../factoriesNumber.js';
export var mapSlicesDependencies = {
isIntegerDependencies,
typedDependencies,
createMapSlices
};

View File

@ -0,0 +1,12 @@
/**
* THIS FILE IS AUTO-GENERATED
* DON'T MAKE CHANGES HERE
*/
import { isIntegerDependencies } from './dependenciesIsInteger.generated.js';
import { typedDependencies } from './dependenciesTyped.generated.js';
import { createMapSlicesTransform } from '../../factoriesNumber.js';
export var mapSlicesTransformDependencies = {
isIntegerDependencies,
typedDependencies,
createMapSlicesTransform
};

View File

@ -0,0 +1,11 @@
export var mapSlicesDocs = {
name: 'mapSlices',
category: 'Matrix',
syntax: ['mapSlices(A, dim, callback)'],
description: 'Generate a matrix one dimension less than A by applying callback to ' + 'each slice of A along dimension dim.',
examples: ['A = [[1, 2], [3, 4]]', 'mapSlices(A, 1, sum)',
// returns [4, 6]
'mapSlices(A, 2, prod)' // returns [2, 12]
],
seealso: ['map', 'forEach']
};

View File

@ -0,0 +1,47 @@
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import { errorTransform } from './utils/errorTransform.js';
import { factory } from '../../utils/factory.js';
import { createMapSlices } from '../../function/matrix/mapSlices.js';
import { isBigNumber, isNumber } from '../../utils/is.js';
var name = 'mapSlices';
var dependencies = ['typed', 'isInteger'];
/**
* Attach a transform function to math.mapSlices
* Adds a property transform containing the transform function.
*
* This transform changed the last `dim` parameter of function mapSlices
* from one-based to zero based
*/
export var createMapSlicesTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
isInteger
} = _ref;
var mapSlices = createMapSlices({
typed,
isInteger
});
// @see: comment of concat itself
return typed('mapSlices', {
'...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 mapSlices.apply(null, args);
} catch (err) {
throw errorTransform(err);
}
}
});
}, _objectSpread({
isTransformFunction: true
}, createMapSlices.meta));

View File

@ -0,0 +1,118 @@
import { factory } from '../../utils/factory.js';
import { arraySize } from '../../utils/array.js';
import { isMatrix } from '../../utils/is.js';
import { IndexError } from '../../error/IndexError.js';
var name = 'mapSlices';
var dependencies = ['typed', 'isInteger'];
export var createMapSlices = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
isInteger
} = _ref;
/**
* Apply a function that maps an array to a scalar
* along a given axis of a matrix or array.
* Returns a new matrix or array with one less dimension than the input.
*
* Syntax:
*
* math.mapSlices(A, dim, callback)
*
* Where:
*
* - `dim: number` is a zero-based dimension over which to concatenate the matrices.
*
* Examples:
*
* const A = [[1, 2], [3, 4]]
* const sum = math.sum
*
* math.mapSlices(A, 0, sum) // returns [4, 6]
* math.mapSlices(A, 1, sum) // returns [3, 7]
*
* See also:
*
* map, filter, forEach
*
* Note:
*
* `mapSlices()` is also currently available via its deprecated
* synonym `apply()`.
*
* @param {Array | Matrix} array The input Matrix
* @param {number} dim The dimension along which the callback is applied
* @param {Function} callback The callback function that is applied. This Function
* should take an array or 1-d matrix as an input and
* return a number.
* @return {Array | Matrix} res The residual matrix with the function mapped on the slices over some dimension.
*/
return typed(name, {
'Array | Matrix, number | BigNumber, function': function Array__Matrix_number__BigNumber_function(mat, dim, callback) {
if (!isInteger(dim)) {
throw new TypeError('Integer number expected for dimension');
}
var size = Array.isArray(mat) ? arraySize(mat) : mat.size();
if (dim < 0 || dim >= size.length) {
throw new IndexError(dim, size.length);
}
if (isMatrix(mat)) {
return mat.create(_mapSlices(mat.valueOf(), dim, callback), mat.datatype());
} else {
return _mapSlices(mat, dim, callback);
}
}
});
}, {
formerly: 'apply'
});
/**
* Recursively reduce a matrix
* @param {Array} mat
* @param {number} dim
* @param {Function} callback
* @returns {Array} ret
* @private
*/
function _mapSlices(mat, dim, callback) {
var i, ret, tran;
if (dim <= 0) {
if (!Array.isArray(mat[0])) {
return callback(mat);
} else {
tran = _switch(mat);
ret = [];
for (i = 0; i < tran.length; i++) {
ret[i] = _mapSlices(tran[i], dim - 1, callback);
}
return ret;
}
} else {
ret = [];
for (i = 0; i < mat.length; i++) {
ret[i] = _mapSlices(mat[i], dim - 1, callback);
}
return ret;
}
}
/**
* Transpose a matrix
* @param {Array} mat
* @returns {Array} ret
* @private
*/
function _switch(mat) {
var I = mat.length;
var J = mat[0].length;
var i, j;
var ret = [];
for (j = 0; j < J; j++) {
var tmp = [];
for (i = 0; i < I; i++) {
tmp.push(mat[i][j]);
}
ret.push(tmp);
}
return ret;
}

27
node_modules/mathjs/lib/esm/utils/bigint.js generated vendored Normal file
View File

@ -0,0 +1,27 @@
/**
* Build a bigint logarithm function from a number logarithm,
* still returning a number. The idea is that 15 hexadecimal digits
* (60 bits) saturates the mantissa of the log, and each additional hex
* digit effectively just adds the log of 16 to the resulting value. So
* convert the most significant 15 hex digits to a number and take its
* log, and then add the log of 16 for each additional hex digit that
* was in the bigint.
* For negative numbers (complex logarithms), following the bignum
* implementation, it just downgrades to number and uses the complex result.
* @param {number} log16 the log of 16
* @param {(number) -> number} numberLog the logarithm function for numbers
* @param {ConfigurationObject} config the mathjs configuration
* @param {(number) -> Complex} cplx the associated Complex log
* @returns {(bigint) -> number} the corresponding logarithm for bigints
*/
export function promoteLogarithm(log16, numberLog, config, cplx) {
return function (b) {
if (b > 0 || config.predictable) {
if (b <= 0) return NaN;
var s = b.toString(16);
var s15 = s.substring(0, 15);
return log16 * (s.length - s15.length) + numberLog(Number('0x' + s15));
}
return cplx(b.toNumber());
};
}