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,114 @@
import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual.js';
import { nearlyEqual } from '../../utils/number.js';
import { factory } from '../../utils/factory.js';
import { createMatAlgo03xDSf } from '../../type/matrix/utils/matAlgo03xDSf.js';
import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
import { createMatAlgo05xSfSf } from '../../type/matrix/utils/matAlgo05xSfSf.js';
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
import { createCompareUnits } from './compareUnits.js';
var name = 'compare';
var dependencies = ['typed', 'config', 'matrix', 'equalScalar', 'BigNumber', 'Fraction', 'DenseMatrix', 'concat'];
export var createCompare = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
config,
equalScalar,
matrix,
BigNumber,
Fraction,
DenseMatrix,
concat
} = _ref;
var matAlgo03xDSf = createMatAlgo03xDSf({
typed
});
var matAlgo05xSfSf = createMatAlgo05xSfSf({
typed,
equalScalar
});
var matAlgo12xSfs = createMatAlgo12xSfs({
typed,
DenseMatrix
});
var matrixAlgorithmSuite = createMatrixAlgorithmSuite({
typed,
matrix,
concat
});
var compareUnits = createCompareUnits({
typed
});
/**
* Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x == y.
*
* x and y are considered equal when the relative difference between x and y
* is smaller than the configured absTol and relTol. The function cannot be used to
* compare values smaller than approximately 2.22e-16.
*
* For matrices, the function is evaluated element wise.
* Strings are compared by their numerical value.
*
* Syntax:
*
* math.compare(x, y)
*
* Examples:
*
* math.compare(6, 1) // returns 1
* math.compare(2, 3) // returns -1
* math.compare(7, 7) // returns 0
* math.compare('10', '2') // returns 1
* math.compare('1000', '1e3') // returns 0
*
* const a = math.unit('5 cm')
* const b = math.unit('40 mm')
* math.compare(a, b) // returns 1
*
* math.compare(2, [1, 2, 3]) // returns [1, 0, -1]
*
* See also:
*
* equal, unequal, smaller, smallerEq, larger, largerEq, compareNatural, compareText
*
* @param {number | BigNumber | bigint | Fraction | Unit | string | Array | Matrix} x First value to compare
* @param {number | BigNumber | bigint | Fraction | Unit | string | Array | Matrix} y Second value to compare
* @return {number | BigNumber | bigint | Fraction | Array | Matrix} Returns the result of the comparison:
* 1 when x > y, -1 when x < y, and 0 when x == y.
*/
return typed(name, createCompareNumber({
typed,
config
}), {
'boolean, boolean': function boolean_boolean(x, y) {
return x === y ? 0 : x > y ? 1 : -1;
},
'BigNumber, BigNumber': function BigNumber_BigNumber(x, y) {
return bigNearlyEqual(x, y, config.relTol, config.absTol) ? new BigNumber(0) : new BigNumber(x.cmp(y));
},
'bigint, bigint': function bigint_bigint(x, y) {
return x === y ? 0n : x > y ? 1n : -1n;
},
'Fraction, Fraction': function Fraction_Fraction(x, y) {
return new Fraction(x.compare(y));
},
'Complex, Complex': function Complex_Complex() {
throw new TypeError('No ordering relation is defined for complex numbers');
}
}, compareUnits, matrixAlgorithmSuite({
SS: matAlgo05xSfSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
});
export var createCompareNumber = /* #__PURE__ */factory(name, ['typed', 'config'], _ref2 => {
var {
typed,
config
} = _ref2;
return typed(name, {
'number, number': function number_number(x, y) {
return nearlyEqual(x, y, config.relTol, config.absTol) ? 0 : x > y ? 1 : -1;
}
});
});

View File

@@ -0,0 +1,274 @@
import naturalSort from 'javascript-natural-sort';
import { isDenseMatrix, isSparseMatrix, typeOf } from '../../utils/is.js';
import { factory } from '../../utils/factory.js';
var name = 'compareNatural';
var dependencies = ['typed', 'compare'];
export var createCompareNatural = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
compare
} = _ref;
var compareBooleans = compare.signatures['boolean,boolean'];
/**
* Compare two values of any type in a deterministic, natural way.
*
* For numeric values, the function works the same as `math.compare`.
* For types of values that can't be compared mathematically,
* the function compares in a natural way.
*
* For numeric values, x and y are considered equal when the relative
* difference between x and y is smaller than the configured relTol and absTol.
* The function cannot be used to compare values smaller than
* approximately 2.22e-16.
*
* For Complex numbers, first the real parts are compared. If equal,
* the imaginary parts are compared.
*
* Strings are compared with a natural sorting algorithm, which
* orders strings in a "logic" way following some heuristics.
* This differs from the function `compare`, which converts the string
* into a numeric value and compares that. The function `compareText`
* on the other hand compares text lexically.
*
* Arrays and Matrices are compared value by value until there is an
* unequal pair of values encountered. Objects are compared by sorted
* keys until the keys or their values are unequal.
*
* Syntax:
*
* math.compareNatural(x, y)
*
* Examples:
*
* math.compareNatural(6, 1) // returns 1
* math.compareNatural(2, 3) // returns -1
* math.compareNatural(7, 7) // returns 0
*
* math.compareNatural('10', '2') // returns 1
* math.compareText('10', '2') // returns -1
* math.compare('10', '2') // returns 1
*
* math.compareNatural('Answer: 10', 'Answer: 2') // returns 1
* math.compareText('Answer: 10', 'Answer: 2') // returns -1
* math.compare('Answer: 10', 'Answer: 2')
* // Error: Cannot convert "Answer: 10" to a number
*
* const a = math.unit('5 cm')
* const b = math.unit('40 mm')
* math.compareNatural(a, b) // returns 1
*
* const c = math.complex('2 + 3i')
* const d = math.complex('2 + 4i')
* math.compareNatural(c, d) // returns -1
*
* math.compareNatural([1, 2, 4], [1, 2, 3]) // returns 1
* math.compareNatural([1, 2, 3], [1, 2]) // returns 1
* math.compareNatural([1, 5], [1, 2, 3]) // returns 1
* math.compareNatural([1, 2], [1, 2]) // returns 0
*
* math.compareNatural({a: 2}, {a: 4}) // returns -1
*
* See also:
*
* compare, compareText
*
* @param {*} x First value to compare
* @param {*} y Second value to compare
* @return {number} Returns the result of the comparison:
* 1 when x > y, -1 when x < y, and 0 when x == y.
*/
return typed(name, {
'any, any': _compareNatural
}); // just to check # args
function _compareNatural(x, y) {
var typeX = typeOf(x);
var typeY = typeOf(y);
var c;
// numeric types
if ((typeX === 'number' || typeX === 'BigNumber' || typeX === 'Fraction') && (typeY === 'number' || typeY === 'BigNumber' || typeY === 'Fraction')) {
c = compare(x, y);
if (c.toString() !== '0') {
// c can be number, BigNumber, or Fraction
return c > 0 ? 1 : -1; // return a number
} else {
return naturalSort(typeX, typeY);
}
}
// matrix types
var matTypes = ['Array', 'DenseMatrix', 'SparseMatrix'];
if (matTypes.includes(typeX) || matTypes.includes(typeY)) {
c = compareMatricesAndArrays(_compareNatural, x, y);
if (c !== 0) {
return c;
} else {
return naturalSort(typeX, typeY);
}
}
// in case of different types, order by name of type, i.e. 'BigNumber' < 'Complex'
if (typeX !== typeY) {
return naturalSort(typeX, typeY);
}
if (typeX === 'Complex') {
return compareComplexNumbers(x, y);
}
if (typeX === 'Unit') {
if (x.equalBase(y)) {
return _compareNatural(x.value, y.value);
}
// compare by units
return compareArrays(_compareNatural, x.formatUnits(), y.formatUnits());
}
if (typeX === 'boolean') {
return compareBooleans(x, y);
}
if (typeX === 'string') {
return naturalSort(x, y);
}
if (typeX === 'Object') {
return compareObjects(_compareNatural, x, y);
}
if (typeX === 'null') {
return 0;
}
if (typeX === 'undefined') {
return 0;
}
// this should not occur...
throw new TypeError('Unsupported type of value "' + typeX + '"');
}
/**
* Compare mixed matrix/array types, by converting to same-shaped array.
* This comparator is non-deterministic regarding input types.
* @param {Array | SparseMatrix | DenseMatrix | *} x
* @param {Array | SparseMatrix | DenseMatrix | *} y
* @returns {number} Returns the comparison result: -1, 0, or 1
*/
function compareMatricesAndArrays(compareNatural, x, y) {
if (isSparseMatrix(x) && isSparseMatrix(y)) {
return compareArrays(compareNatural, x.toJSON().values, y.toJSON().values);
}
if (isSparseMatrix(x)) {
// note: convert to array is expensive
return compareMatricesAndArrays(compareNatural, x.toArray(), y);
}
if (isSparseMatrix(y)) {
// note: convert to array is expensive
return compareMatricesAndArrays(compareNatural, x, y.toArray());
}
// convert DenseArray into Array
if (isDenseMatrix(x)) {
return compareMatricesAndArrays(compareNatural, x.toJSON().data, y);
}
if (isDenseMatrix(y)) {
return compareMatricesAndArrays(compareNatural, x, y.toJSON().data);
}
// convert scalars to array
if (!Array.isArray(x)) {
return compareMatricesAndArrays(compareNatural, [x], y);
}
if (!Array.isArray(y)) {
return compareMatricesAndArrays(compareNatural, x, [y]);
}
return compareArrays(compareNatural, x, y);
}
/**
* Compare two Arrays
*
* - First, compares value by value
* - Next, if all corresponding values are equal,
* look at the length: longest array will be considered largest
*
* @param {Array} x
* @param {Array} y
* @returns {number} Returns the comparison result: -1, 0, or 1
*/
function compareArrays(compareNatural, x, y) {
// compare each value
for (var i = 0, ii = Math.min(x.length, y.length); i < ii; i++) {
var v = compareNatural(x[i], y[i]);
if (v !== 0) {
return v;
}
}
// compare the size of the arrays
if (x.length > y.length) {
return 1;
}
if (x.length < y.length) {
return -1;
}
// both Arrays have equal size and content
return 0;
}
/**
* Compare two objects
*
* - First, compare sorted property names
* - Next, compare the property values
*
* @param {Object} x
* @param {Object} y
* @returns {number} Returns the comparison result: -1, 0, or 1
*/
function compareObjects(compareNatural, x, y) {
var keysX = Object.keys(x);
var keysY = Object.keys(y);
// compare keys
keysX.sort(naturalSort);
keysY.sort(naturalSort);
var c = compareArrays(compareNatural, keysX, keysY);
if (c !== 0) {
return c;
}
// compare values
for (var i = 0; i < keysX.length; i++) {
var v = compareNatural(x[keysX[i]], y[keysY[i]]);
if (v !== 0) {
return v;
}
}
return 0;
}
});
/**
* Compare two complex numbers, `x` and `y`:
*
* - First, compare the real values of `x` and `y`
* - If equal, compare the imaginary values of `x` and `y`
*
* @params {Complex} x
* @params {Complex} y
* @returns {number} Returns the comparison result: -1, 0, or 1
*/
function compareComplexNumbers(x, y) {
if (x.re > y.re) {
return 1;
}
if (x.re < y.re) {
return -1;
}
if (x.im > y.im) {
return 1;
}
if (x.im < y.im) {
return -1;
}
return 0;
}

View File

@@ -0,0 +1,57 @@
import { compareText as _compareText } from '../../utils/string.js';
import { factory } from '../../utils/factory.js';
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
var name = 'compareText';
var dependencies = ['typed', 'matrix', 'concat'];
_compareText.signature = 'any, any';
export var createCompareText = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
matrix,
concat
} = _ref;
var matrixAlgorithmSuite = createMatrixAlgorithmSuite({
typed,
matrix,
concat
});
/**
* Compare two strings lexically. Comparison is case sensitive.
* Returns 1 when x > y, -1 when x < y, and 0 when x == y.
*
* For matrices, the function is evaluated element wise.
*
* Syntax:
*
* math.compareText(x, y)
*
* Examples:
*
* math.compareText('B', 'A') // returns 1
* math.compareText('2', '10') // returns 1
* math.compare('2', '10') // returns -1
* math.compareNatural('2', '10') // returns -1
*
* math.compareText('B', ['A', 'B', 'C']) // returns [1, 0, -1]
*
* See also:
*
* equal, equalText, compare, compareNatural
*
* @param {string | Array | DenseMatrix} x First string to compare
* @param {string | Array | DenseMatrix} y Second string to compare
* @return {number | Array | DenseMatrix} Returns the result of the comparison:
* 1 when x > y, -1 when x < y, and 0 when x == y.
*/
return typed(name, _compareText, matrixAlgorithmSuite({
elop: _compareText,
Ds: true
}));
});
export var createCompareTextNumber = /* #__PURE__ */factory(name, ['typed'], _ref2 => {
var {
typed
} = _ref2;
return typed(name, _compareText);
});

View File

@@ -0,0 +1,14 @@
import { factory } from '../../utils/factory.js';
export var createCompareUnits = /* #__PURE__ */factory('compareUnits', ['typed'], _ref => {
var {
typed
} = _ref;
return {
'Unit, Unit': typed.referToSelf(self => (x, y) => {
if (!x.equalBase(y)) {
throw new Error('Cannot compare units with different base');
}
return typed.find(self, [x.valueType(), y.valueType()])(x.value, y.value);
})
};
});

View File

@@ -0,0 +1,74 @@
import { factory } from '../../utils/factory.js';
var name = 'deepEqual';
var dependencies = ['typed', 'equal'];
export var createDeepEqual = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
equal
} = _ref;
/**
* Test element wise whether two matrices are equal.
* The function accepts both matrices and scalar values.
*
* Strings are compared by their numerical value.
*
* Syntax:
*
* math.deepEqual(x, y)
*
* Examples:
*
* math.deepEqual(2, 4) // returns false
*
* a = [2, 5, 1]
* b = [2, 7, 1]
*
* math.deepEqual(a, b) // returns false
* math.equal(a, b) // returns [true, false, true]
*
* See also:
*
* equal, unequal
*
* @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x First matrix to compare
* @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} y Second matrix to compare
* @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix}
* Returns true when the input matrices have the same size and each of their elements is equal.
*/
return typed(name, {
'any, any': function any_any(x, y) {
return _deepEqual(x.valueOf(), y.valueOf());
}
});
/**
* Test whether two arrays have the same size and all elements are equal
* @param {Array | *} x
* @param {Array | *} y
* @return {boolean} Returns true if both arrays are deep equal
*/
function _deepEqual(x, y) {
if (Array.isArray(x)) {
if (Array.isArray(y)) {
var len = x.length;
if (len !== y.length) {
return false;
}
for (var i = 0; i < len; i++) {
if (!_deepEqual(x[i], y[i])) {
return false;
}
}
return true;
} else {
return false;
}
} else {
if (Array.isArray(y)) {
return false;
} else {
return equal(x, y);
}
}
}
});

View File

@@ -0,0 +1,110 @@
import { factory } from '../../utils/factory.js';
import { createMatAlgo03xDSf } from '../../type/matrix/utils/matAlgo03xDSf.js';
import { createMatAlgo07xSSf } from '../../type/matrix/utils/matAlgo07xSSf.js';
import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
var name = 'equal';
var dependencies = ['typed', 'matrix', 'equalScalar', 'DenseMatrix', 'concat'];
export var createEqual = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
matrix,
equalScalar,
DenseMatrix,
concat
} = _ref;
var matAlgo03xDSf = createMatAlgo03xDSf({
typed
});
var matAlgo07xSSf = createMatAlgo07xSSf({
typed,
DenseMatrix
});
var matAlgo12xSfs = createMatAlgo12xSfs({
typed,
DenseMatrix
});
var matrixAlgorithmSuite = createMatrixAlgorithmSuite({
typed,
matrix,
concat
});
/**
* Test whether two values are equal.
*
* The function tests whether the relative difference between x and y is
* smaller than the configured relTol and absTol. The function cannot be used to
* compare values smaller than approximately 2.22e-16.
*
* For matrices, the function is evaluated element wise.
* In case of complex numbers, x.re must equal y.re, and x.im must equal y.im.
*
* Values `null` and `undefined` are compared strictly, thus `null` is only
* equal to `null` and nothing else, and `undefined` is only equal to
* `undefined` and nothing else. Strings are compared by their numerical value.
*
* Syntax:
*
* math.equal(x, y)
*
* Examples:
*
* math.equal(2 + 2, 3) // returns false
* math.equal(2 + 2, 4) // returns true
*
* const a = math.unit('50 cm')
* const b = math.unit('5 m')
* math.equal(a, b) // returns true
*
* const c = [2, 5, 1]
* const d = [2, 7, 1]
*
* math.equal(c, d) // returns [true, false, true]
* math.deepEqual(c, d) // returns false
*
* math.equal("1000", "1e3") // returns true
* math.equal(0, null) // returns false
*
* See also:
*
* unequal, smaller, smallerEq, larger, largerEq, compare, deepEqual, equalText
*
* @param {number | BigNumber | bigint | boolean | Complex | Unit | string | Array | Matrix} x First value to compare
* @param {number | BigNumber | bigint | boolean | Complex | Unit | string | Array | Matrix} y Second value to compare
* @return {boolean | Array | Matrix} Returns true when the compared values are equal, else returns false
*/
return typed(name, createEqualNumber({
typed,
equalScalar
}), matrixAlgorithmSuite({
elop: equalScalar,
SS: matAlgo07xSSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
});
export var createEqualNumber = factory(name, ['typed', 'equalScalar'], _ref2 => {
var {
typed,
equalScalar
} = _ref2;
return typed(name, {
'any, any': function any_any(x, y) {
// strict equality for null and undefined?
if (x === null) {
return y === null;
}
if (y === null) {
return x === null;
}
if (x === undefined) {
return y === undefined;
}
if (y === undefined) {
return x === undefined;
}
return equalScalar(x, y);
}
});
});

View File

@@ -0,0 +1,56 @@
import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual.js';
import { nearlyEqual } from '../../utils/number.js';
import { factory } from '../../utils/factory.js';
import { complexEquals } from '../../utils/complex.js';
import { createCompareUnits } from './compareUnits.js';
var name = 'equalScalar';
var dependencies = ['typed', 'config'];
export var createEqualScalar = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
config
} = _ref;
var compareUnits = createCompareUnits({
typed
});
/**
* Test whether two scalar values are nearly equal.
*
* @param {number | BigNumber | bigint | Fraction | boolean | Complex | Unit} x First value to compare
* @param {number | BigNumber | bigint | Fraction | boolean | Complex} y Second value to compare
* @return {boolean} Returns true when the compared values are equal, else returns false
* @private
*/
return typed(name, {
'boolean, boolean': function boolean_boolean(x, y) {
return x === y;
},
'number, number': function number_number(x, y) {
return nearlyEqual(x, y, config.relTol, config.absTol);
},
'BigNumber, BigNumber': function BigNumber_BigNumber(x, y) {
return x.eq(y) || bigNearlyEqual(x, y, config.relTol, config.absTol);
},
'bigint, bigint': function bigint_bigint(x, y) {
return x === y;
},
'Fraction, Fraction': function Fraction_Fraction(x, y) {
return x.equals(y);
},
'Complex, Complex': function Complex_Complex(x, y) {
return complexEquals(x, y, config.relTol, config.absTol);
}
}, compareUnits);
});
export var createEqualScalarNumber = factory(name, ['typed', 'config'], _ref2 => {
var {
typed,
config
} = _ref2;
return typed(name, {
'number, number': function number_number(x, y) {
return nearlyEqual(x, y, config.relTol, config.absTol);
}
});
});

View File

@@ -0,0 +1,41 @@
import { factory } from '../../utils/factory.js';
var name = 'equalText';
var dependencies = ['typed', 'compareText', 'isZero'];
export var createEqualText = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
compareText,
isZero
} = _ref;
/**
* Check equality of two strings. Comparison is case sensitive.
*
* For matrices, the function is evaluated element wise.
*
* Syntax:
*
* math.equalText(x, y)
*
* Examples:
*
* math.equalText('Hello', 'Hello') // returns true
* math.equalText('a', 'A') // returns false
* math.equal('2e3', '2000') // returns true
* math.equalText('2e3', '2000') // returns false
*
* math.equalText('B', ['A', 'B', 'C']) // returns [false, true, false]
*
* See also:
*
* equal, compareText, compare, compareNatural
*
* @param {string | Array | DenseMatrix} x First string to compare
* @param {string | Array | DenseMatrix} y Second string to compare
* @return {number | Array | DenseMatrix} Returns true if the values are equal, and false if not.
*/
return typed(name, {
'any, any': function any_any(x, y) {
return isZero(compareText(x, y));
}
});
});

View File

@@ -0,0 +1,99 @@
import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual.js';
import { nearlyEqual } from '../../utils/number.js';
import { factory } from '../../utils/factory.js';
import { createMatAlgo03xDSf } from '../../type/matrix/utils/matAlgo03xDSf.js';
import { createMatAlgo07xSSf } from '../../type/matrix/utils/matAlgo07xSSf.js';
import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
import { createCompareUnits } from './compareUnits.js';
var name = 'larger';
var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat'];
export var createLarger = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
config,
matrix,
DenseMatrix,
concat
} = _ref;
var matAlgo03xDSf = createMatAlgo03xDSf({
typed
});
var matAlgo07xSSf = createMatAlgo07xSSf({
typed,
DenseMatrix
});
var matAlgo12xSfs = createMatAlgo12xSfs({
typed,
DenseMatrix
});
var matrixAlgorithmSuite = createMatrixAlgorithmSuite({
typed,
matrix,
concat
});
var compareUnits = createCompareUnits({
typed
});
/**
* Test whether value x is larger than y.
*
* The function returns true when x is larger than y and the relative
* difference between x and y is larger than the configured relTol and absTol. The
* function cannot be used to compare values smaller than approximately 2.22e-16.
*
* For matrices, the function is evaluated element wise.
* Strings are compared by their numerical value.
*
* Syntax:
*
* math.larger(x, y)
*
* Examples:
*
* math.larger(2, 3) // returns false
* math.larger(5, 2 + 2) // returns true
*
* const a = math.unit('5 cm')
* const b = math.unit('2 inch')
* math.larger(a, b) // returns false
*
* See also:
*
* equal, unequal, smaller, smallerEq, largerEq, compare
*
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
* @return {boolean | Array | Matrix} Returns true when the x is larger than y, else returns false
*/
return typed(name, createLargerNumber({
typed,
config
}), {
'boolean, boolean': (x, y) => x > y,
'BigNumber, BigNumber': function BigNumber_BigNumber(x, y) {
return x.gt(y) && !bigNearlyEqual(x, y, config.relTol, config.absTol);
},
'bigint, bigint': (x, y) => x > y,
'Fraction, Fraction': (x, y) => x.compare(y) === 1,
'Complex, Complex': function Complex_Complex() {
throw new TypeError('No ordering relation is defined for complex numbers');
}
}, compareUnits, matrixAlgorithmSuite({
SS: matAlgo07xSSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
});
export var createLargerNumber = /* #__PURE__ */factory(name, ['typed', 'config'], _ref2 => {
var {
typed,
config
} = _ref2;
return typed(name, {
'number, number': function number_number(x, y) {
return x > y && !nearlyEqual(x, y, config.relTol, config.absTol);
}
});
});

View File

@@ -0,0 +1,97 @@
import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual.js';
import { nearlyEqual } from '../../utils/number.js';
import { factory } from '../../utils/factory.js';
import { createMatAlgo03xDSf } from '../../type/matrix/utils/matAlgo03xDSf.js';
import { createMatAlgo07xSSf } from '../../type/matrix/utils/matAlgo07xSSf.js';
import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
import { createCompareUnits } from './compareUnits.js';
var name = 'largerEq';
var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat'];
export var createLargerEq = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
config,
matrix,
DenseMatrix,
concat
} = _ref;
var matAlgo03xDSf = createMatAlgo03xDSf({
typed
});
var matAlgo07xSSf = createMatAlgo07xSSf({
typed,
DenseMatrix
});
var matAlgo12xSfs = createMatAlgo12xSfs({
typed,
DenseMatrix
});
var matrixAlgorithmSuite = createMatrixAlgorithmSuite({
typed,
matrix,
concat
});
var compareUnits = createCompareUnits({
typed
});
/**
* Test whether value x is larger or equal to y.
*
* The function returns true when x is larger than y or the relative
* difference between x and y is smaller than the configured relTol and absTol. The
* function cannot be used to compare values smaller than approximately 2.22e-16.
*
* For matrices, the function is evaluated element wise.
* Strings are compared by their numerical value.
*
* Syntax:
*
* math.largerEq(x, y)
*
* Examples:
*
* math.larger(2, 1 + 1) // returns false
* math.largerEq(2, 1 + 1) // returns true
*
* See also:
*
* equal, unequal, smaller, smallerEq, larger, compare
*
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
* @return {boolean | Array | Matrix} Returns true when the x is larger or equal to y, else returns false
*/
return typed(name, createLargerEqNumber({
typed,
config
}), {
'boolean, boolean': (x, y) => x >= y,
'BigNumber, BigNumber': function BigNumber_BigNumber(x, y) {
return x.gte(y) || bigNearlyEqual(x, y, config.relTol, config.absTol);
},
'bigint, bigint': function bigint_bigint(x, y) {
return x >= y;
},
'Fraction, Fraction': (x, y) => x.compare(y) !== -1,
'Complex, Complex': function Complex_Complex() {
throw new TypeError('No ordering relation is defined for complex numbers');
}
}, compareUnits, matrixAlgorithmSuite({
SS: matAlgo07xSSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
});
export var createLargerEqNumber = /* #__PURE__ */factory(name, ['typed', 'config'], _ref2 => {
var {
typed,
config
} = _ref2;
return typed(name, {
'number, number': function number_number(x, y) {
return x >= y || nearlyEqual(x, y, config.relTol, config.absTol);
}
});
});

View File

@@ -0,0 +1,99 @@
import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual.js';
import { nearlyEqual } from '../../utils/number.js';
import { factory } from '../../utils/factory.js';
import { createMatAlgo03xDSf } from '../../type/matrix/utils/matAlgo03xDSf.js';
import { createMatAlgo07xSSf } from '../../type/matrix/utils/matAlgo07xSSf.js';
import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
import { createCompareUnits } from './compareUnits.js';
var name = 'smaller';
var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat'];
export var createSmaller = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
config,
matrix,
DenseMatrix,
concat
} = _ref;
var matAlgo03xDSf = createMatAlgo03xDSf({
typed
});
var matAlgo07xSSf = createMatAlgo07xSSf({
typed,
DenseMatrix
});
var matAlgo12xSfs = createMatAlgo12xSfs({
typed,
DenseMatrix
});
var matrixAlgorithmSuite = createMatrixAlgorithmSuite({
typed,
matrix,
concat
});
var compareUnits = createCompareUnits({
typed
});
/**
* Test whether value x is smaller than y.
*
* The function returns true when x is smaller than y and the relative
* difference between x and y is smaller than the configured relTol and absTol. The
* function cannot be used to compare values smaller than approximately 2.22e-16.
*
* For matrices, the function is evaluated element wise.
* Strings are compared by their numerical value.
*
* Syntax:
*
* math.smaller(x, y)
*
* Examples:
*
* math.smaller(2, 3) // returns true
* math.smaller(5, 2 * 2) // returns false
*
* const a = math.unit('5 cm')
* const b = math.unit('2 inch')
* math.smaller(a, b) // returns true
*
* See also:
*
* equal, unequal, smallerEq, smaller, smallerEq, compare
*
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
* @return {boolean | Array | Matrix} Returns true when the x is smaller than y, else returns false
*/
return typed(name, createSmallerNumber({
typed,
config
}), {
'boolean, boolean': (x, y) => x < y,
'BigNumber, BigNumber': function BigNumber_BigNumber(x, y) {
return x.lt(y) && !bigNearlyEqual(x, y, config.relTol, config.absTol);
},
'bigint, bigint': (x, y) => x < y,
'Fraction, Fraction': (x, y) => x.compare(y) === -1,
'Complex, Complex': function Complex_Complex(x, y) {
throw new TypeError('No ordering relation is defined for complex numbers');
}
}, compareUnits, matrixAlgorithmSuite({
SS: matAlgo07xSSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
});
export var createSmallerNumber = /* #__PURE__ */factory(name, ['typed', 'config'], _ref2 => {
var {
typed,
config
} = _ref2;
return typed(name, {
'number, number': function number_number(x, y) {
return x < y && !nearlyEqual(x, y, config.relTol, config.absTol);
}
});
});

View File

@@ -0,0 +1,95 @@
import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual.js';
import { nearlyEqual } from '../../utils/number.js';
import { factory } from '../../utils/factory.js';
import { createMatAlgo03xDSf } from '../../type/matrix/utils/matAlgo03xDSf.js';
import { createMatAlgo07xSSf } from '../../type/matrix/utils/matAlgo07xSSf.js';
import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
import { createCompareUnits } from './compareUnits.js';
var name = 'smallerEq';
var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat'];
export var createSmallerEq = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
config,
matrix,
DenseMatrix,
concat
} = _ref;
var matAlgo03xDSf = createMatAlgo03xDSf({
typed
});
var matAlgo07xSSf = createMatAlgo07xSSf({
typed,
DenseMatrix
});
var matAlgo12xSfs = createMatAlgo12xSfs({
typed,
DenseMatrix
});
var matrixAlgorithmSuite = createMatrixAlgorithmSuite({
typed,
matrix,
concat
});
var compareUnits = createCompareUnits({
typed
});
/**
* Test whether value x is smaller or equal to y.
*
* The function returns true when x is smaller than y or the relative
* difference between x and y is smaller than the configured relTol and absTol. The
* function cannot be used to compare values smaller than approximately 2.22e-16.
*
* For matrices, the function is evaluated element wise.
* Strings are compared by their numerical value.
*
* Syntax:
*
* math.smallerEq(x, y)
*
* Examples:
*
* math.smaller(1 + 2, 3) // returns false
* math.smallerEq(1 + 2, 3) // returns true
*
* See also:
*
* equal, unequal, smaller, larger, largerEq, compare
*
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
* @param {number | BigNumber | bigint | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
* @return {boolean | Array | Matrix} Returns true when the x is smaller than y, else returns false
*/
return typed(name, createSmallerEqNumber({
typed,
config
}), {
'boolean, boolean': (x, y) => x <= y,
'BigNumber, BigNumber': function BigNumber_BigNumber(x, y) {
return x.lte(y) || bigNearlyEqual(x, y, config.relTol, config.absTol);
},
'bigint, bigint': (x, y) => x <= y,
'Fraction, Fraction': (x, y) => x.compare(y) !== 1,
'Complex, Complex': function Complex_Complex() {
throw new TypeError('No ordering relation is defined for complex numbers');
}
}, compareUnits, matrixAlgorithmSuite({
SS: matAlgo07xSSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
});
export var createSmallerEqNumber = /* #__PURE__ */factory(name, ['typed', 'config'], _ref2 => {
var {
typed,
config
} = _ref2;
return typed(name, {
'number, number': function number_number(x, y) {
return x <= y || nearlyEqual(x, y, config.relTol, config.absTol);
}
});
});

View File

@@ -0,0 +1,113 @@
import { factory } from '../../utils/factory.js';
import { createMatAlgo03xDSf } from '../../type/matrix/utils/matAlgo03xDSf.js';
import { createMatAlgo07xSSf } from '../../type/matrix/utils/matAlgo07xSSf.js';
import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
var name = 'unequal';
var dependencies = ['typed', 'config', 'equalScalar', 'matrix', 'DenseMatrix', 'concat'];
export var createUnequal = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
config,
equalScalar,
matrix,
DenseMatrix,
concat
} = _ref;
var matAlgo03xDSf = createMatAlgo03xDSf({
typed
});
var matAlgo07xSSf = createMatAlgo07xSSf({
typed,
DenseMatrix
});
var matAlgo12xSfs = createMatAlgo12xSfs({
typed,
DenseMatrix
});
var matrixAlgorithmSuite = createMatrixAlgorithmSuite({
typed,
matrix,
concat
});
/**
* Test whether two values are unequal.
*
* The function tests whether the relative difference between x and y is
* larger than the configured relTol and absTol. The function cannot be used to compare
* values smaller than approximately 2.22e-16.
*
* For matrices, the function is evaluated element wise.
* In case of complex numbers, x.re must unequal y.re, or x.im must unequal y.im.
* Strings are compared by their numerical value.
*
* Values `null` and `undefined` are compared strictly, thus `null` is unequal
* with everything except `null`, and `undefined` is unequal with everything
* except `undefined`.
*
* Syntax:
*
* math.unequal(x, y)
*
* Examples:
*
* math.unequal(2 + 2, 3) // returns true
* math.unequal(2 + 2, 4) // returns false
*
* const a = math.unit('50 cm')
* const b = math.unit('5 m')
* math.unequal(a, b) // returns false
*
* const c = [2, 5, 1]
* const d = [2, 7, 1]
*
* math.unequal(c, d) // returns [false, true, false]
* math.deepEqual(c, d) // returns false
*
* math.unequal(0, null) // returns true
* See also:
*
* equal, deepEqual, smaller, smallerEq, larger, largerEq, compare
*
* @param {number | BigNumber | Fraction | boolean | Complex | Unit | string | Array | Matrix | undefined} x First value to compare
* @param {number | BigNumber | Fraction | boolean | Complex | Unit | string | Array | Matrix | undefined} y Second value to compare
* @return {boolean | Array | Matrix} Returns true when the compared values are unequal, else returns false
*/
return typed(name, createUnequalNumber({
typed,
equalScalar
}), matrixAlgorithmSuite({
elop: _unequal,
SS: matAlgo07xSSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
}));
function _unequal(x, y) {
return !equalScalar(x, y);
}
});
export var createUnequalNumber = factory(name, ['typed', 'equalScalar'], _ref2 => {
var {
typed,
equalScalar
} = _ref2;
return typed(name, {
'any, any': function any_any(x, y) {
// strict equality for null and undefined?
if (x === null) {
return y !== null;
}
if (y === null) {
return x !== null;
}
if (x === undefined) {
return y !== undefined;
}
if (y === undefined) {
return x !== undefined;
}
return !equalScalar(x, y);
}
});
});