From 0f834fbbc1a0dcd22a5595409f4c67e939e079d3 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 8 Dec 2025 20:54:56 -0600 Subject: [PATCH 01/46] Refactor matAlgo14xDs --- src/type/matrix/utils/matAlgo14xDs.js | 39 ++------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/src/type/matrix/utils/matAlgo14xDs.js b/src/type/matrix/utils/matAlgo14xDs.js index 342b2b19d9..12ae4ea273 100644 --- a/src/type/matrix/utils/matAlgo14xDs.js +++ b/src/type/matrix/utils/matAlgo14xDs.js @@ -1,5 +1,4 @@ import { factory } from '../../../utils/factory.js' -import { clone } from '../../../utils/object.js' const name = 'matAlgo14xDs' const dependencies = ['typed'] @@ -21,11 +20,6 @@ export const createMatAlgo14xDs = /* #__PURE__ */ factory(name, dependencies, ({ * https://github.com/josdejong/mathjs/pull/346#issuecomment-97659042 */ return function matAlgo14xDs (a, b, callback, inverse) { - // a arrays - const adata = a._data - const asize = a._size - const adt = a._datatype - // datatype let dt // callback signature to use @@ -34,42 +28,13 @@ export const createMatAlgo14xDs = /* #__PURE__ */ factory(name, dependencies, ({ // process data types if (typeof adt === 'string') { // datatype - dt = adt + dt = a._datatype // convert b to the same datatype b = typed.convert(b, dt) // callback cf = typed.find(callback, [dt, dt]) } - // populate cdata, iterate through dimensions - const cdata = asize.length > 0 ? _iterate(cf, 0, asize, asize[0], adata, b, inverse) : [] - - // c matrix - return a.createDenseMatrix({ - data: cdata, - size: clone(asize), - datatype: dt - }) - } - - // recursive function - function _iterate (f, level, s, n, av, bv, inverse) { - // initialize array for this level - const cv = [] - // check we reach the last level - if (level === s.length - 1) { - // loop arrays in last level - for (let i = 0; i < n; i++) { - // invoke callback and store value - cv[i] = inverse ? f(bv, av[i]) : f(av[i], bv) - } - } else { - // iterate current level - for (let j = 0; j < n; j++) { - // iterate next level - cv[j] = _iterate(f, level + 1, s, s[level + 1], av[j], bv, inverse) - } - } - return cv + return inverse ? a.map(v => cf(b, v)) : a.map(v => cf(v, b)) } }) From c9d57a11f29ce7186b56d5902406ba82235c88d3 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 8 Dec 2025 21:20:50 -0600 Subject: [PATCH 02/46] Included an algorithm for Array and scalars --- src/type/matrix/utils/matAlgo15xAs.js | 26 +++++++++++++++++++ src/type/matrix/utils/matrixAlgorithmSuite.js | 10 ++++--- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 src/type/matrix/utils/matAlgo15xAs.js diff --git a/src/type/matrix/utils/matAlgo15xAs.js b/src/type/matrix/utils/matAlgo15xAs.js new file mode 100644 index 0000000000..2adb07a54c --- /dev/null +++ b/src/type/matrix/utils/matAlgo15xAs.js @@ -0,0 +1,26 @@ +import { factory } from '../../../utils/factory.js' +import { deepMap as map } from '../../../utils/array.js' + +const name = 'matAlgo15xAs' +const dependencies = [] + +export const createMatAlgo15xAs = /* #__PURE__ */ factory(name, dependencies, () => { + /** + * Iterates over Array items and invokes the callback function f(Aij..z, b). + * Callback function invoked MxN times. + * + * C(i,j,...z) = f(Aij..z, b) + * + * @param {Array} a The Array instance (A) + * @param {Scalar} b The Scalar value + * @param {Function} cf The f(Aij..z,b) operation to invoke + * @param {boolean} inverse A true value indicates callback should be invoked f(b,Aij..z) + * + * @return {Array} Array (C) + * + * https://github.com/josdejong/mathjs/pull/346#issuecomment-97659042 + */ + return function matAlgo14xDs (a, b, cf, inverse) { + return inverse ? map(a, v => cf(b, v)) : map(a, v => cf(v, b)) + } +}) diff --git a/src/type/matrix/utils/matrixAlgorithmSuite.js b/src/type/matrix/utils/matrixAlgorithmSuite.js index 216935b20e..db02f6d38d 100644 --- a/src/type/matrix/utils/matrixAlgorithmSuite.js +++ b/src/type/matrix/utils/matrixAlgorithmSuite.js @@ -2,6 +2,7 @@ import { factory } from '../../../utils/factory.js' import { extend } from '../../../utils/object.js' import { createMatAlgo13xDD } from './matAlgo13xDD.js' import { createMatAlgo14xDs } from './matAlgo14xDs.js' +import { createMatAlgo15xAs } from './matAlgo15xAs.js' import { broadcast } from './broadcast.js' const name = 'matrixAlgorithmSuite' @@ -11,6 +12,7 @@ export const createMatrixAlgorithmSuite = /* #__PURE__ */ factory( name, dependencies, ({ typed, matrix }) => { const matAlgo13xDD = createMatAlgo13xDD({ typed }) const matAlgo14xDs = createMatAlgo14xDs({ typed }) + const matAlgo15xAs = createMatAlgo15xAs() /** * Return a signatures object with the usual boilerplate of @@ -115,9 +117,9 @@ export const createMatrixAlgorithmSuite = /* #__PURE__ */ factory( matrixSignatures[scalar + ', DenseMatrix'] = (x, y) => matAlgo14xDs(y, x, elop, true) matrixSignatures['Array,' + scalar] = - (x, y) => matAlgo14xDs(matrix(x), y, elop, false).valueOf() + (x, y) => matAlgo15xAs(x, y, elop, false) matrixSignatures[scalar + ', Array'] = - (x, y) => matAlgo14xDs(matrix(y), x, elop, true).valueOf() + (x, y) => matAlgo15xAs(y, x, elop, true) } else { matrixSignatures['DenseMatrix,' + scalar] = typed.referToSelf(self => (x, y) => { @@ -129,11 +131,11 @@ export const createMatrixAlgorithmSuite = /* #__PURE__ */ factory( }) matrixSignatures['Array,' + scalar] = typed.referToSelf(self => (x, y) => { - return matAlgo14xDs(matrix(x), y, self, false).valueOf() + return matAlgo15xAs(x, y, self, false) }) matrixSignatures[scalar + ', Array'] = typed.referToSelf(self => (x, y) => { - return matAlgo14xDs(matrix(y), x, self, true).valueOf() + return matAlgo15xAs(y, x, self, true) }) } } From d27318215ec80d17bc474342c99803f4ba0cd6b8 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 8 Dec 2025 21:39:00 -0600 Subject: [PATCH 03/46] fixed name of the exporter function --- src/type/matrix/utils/matAlgo15xAs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/type/matrix/utils/matAlgo15xAs.js b/src/type/matrix/utils/matAlgo15xAs.js index 2adb07a54c..5e664122f1 100644 --- a/src/type/matrix/utils/matAlgo15xAs.js +++ b/src/type/matrix/utils/matAlgo15xAs.js @@ -20,7 +20,7 @@ export const createMatAlgo15xAs = /* #__PURE__ */ factory(name, dependencies, () * * https://github.com/josdejong/mathjs/pull/346#issuecomment-97659042 */ - return function matAlgo14xDs (a, b, cf, inverse) { + return function matAlgo15xAs (a, b, cf, inverse) { return inverse ? map(a, v => cf(b, v)) : map(a, v => cf(v, b)) } }) From af646a87418f5b0f471ea1358a7e97678d0a949a Mon Sep 17 00:00:00 2001 From: David Contreras Date: Thu, 11 Dec 2025 23:09:26 -0600 Subject: [PATCH 04/46] Fixed missing variable --- src/type/matrix/utils/matAlgo14xDs.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/type/matrix/utils/matAlgo14xDs.js b/src/type/matrix/utils/matAlgo14xDs.js index 12ae4ea273..f7a3b7f9f8 100644 --- a/src/type/matrix/utils/matAlgo14xDs.js +++ b/src/type/matrix/utils/matAlgo14xDs.js @@ -20,19 +20,18 @@ export const createMatAlgo14xDs = /* #__PURE__ */ factory(name, dependencies, ({ * https://github.com/josdejong/mathjs/pull/346#issuecomment-97659042 */ return function matAlgo14xDs (a, b, callback, inverse) { - // datatype - let dt + // a arrays + const adt = a._datatype + // callback signature to use let cf = callback // process data types if (typeof adt === 'string') { - // datatype - dt = a._datatype // convert b to the same datatype - b = typed.convert(b, dt) + b = typed.convert(b, adt) // callback - cf = typed.find(callback, [dt, dt]) + cf = typed.find(callback, [adt, adt]) } return inverse ? a.map(v => cf(b, v)) : a.map(v => cf(v, b)) From 57c4cb27493d543dd0b6ce2169d44db8d721bde9 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Sun, 14 Dec 2025 10:34:04 -0600 Subject: [PATCH 05/46] Added tests and removed useMatrixForArrayScalar.js --- src/function/bitwise/leftShift.js | 21 +++++++++++++++--- src/function/bitwise/rightArithShift.js | 21 +++++++++++++++--- src/function/bitwise/rightLogShift.js | 22 ++++++++++++++++--- .../bitwise/useMatrixForArrayScalar.js | 15 ------------- .../function/arithmetic/add.test.js | 5 +++++ .../function/arithmetic/mod.test.js | 5 +++++ .../function/arithmetic/subtract.test.js | 7 +++++- .../function/bitwise/bitAnd.test.js | 5 +++++ .../unit-tests/function/bitwise/bitOr.test.js | 5 +++++ .../function/bitwise/leftShift.test.js | 5 +++++ 10 files changed, 86 insertions(+), 25 deletions(-) delete mode 100644 src/function/bitwise/useMatrixForArrayScalar.js diff --git a/src/function/bitwise/leftShift.js b/src/function/bitwise/leftShift.js index 18b406fc61..fa8761203f 100644 --- a/src/function/bitwise/leftShift.js +++ b/src/function/bitwise/leftShift.js @@ -1,14 +1,15 @@ import { createMatAlgo02xDS0 } from '../../type/matrix/utils/matAlgo02xDS0.js' import { createMatAlgo11xS0s } from '../../type/matrix/utils/matAlgo11xS0s.js' import { createMatAlgo14xDs } from '../../type/matrix/utils/matAlgo14xDs.js' +import { createMatAlgo15xAs } from '../../type/matrix/utils/matAlgo15xAs.js' import { createMatAlgo01xDSid } from '../../type/matrix/utils/matAlgo01xDSid.js' import { createMatAlgo10xSids } from '../../type/matrix/utils/matAlgo10xSids.js' import { createMatAlgo08xS0Sid } from '../../type/matrix/utils/matAlgo08xS0Sid.js' import { factory } from '../../utils/factory.js' import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js' -import { createUseMatrixForArrayScalar } from './useMatrixForArrayScalar.js' import { leftShiftNumber } from '../../plain/number/index.js' import { leftShiftBigNumber } from '../../utils/bignumber/bitwise.js' +import { deepMap, clone } from '../../utils/array.js' const name = 'leftShift' const dependencies = [ @@ -27,8 +28,8 @@ export const createLeftShift = /* #__PURE__ */ factory(name, dependencies, ({ ty const matAlgo10xSids = createMatAlgo10xSids({ typed, DenseMatrix }) const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) const matAlgo14xDs = createMatAlgo14xDs({ typed }) + const matAlgo15xAs = createMatAlgo15xAs() const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) - const useMatrixForArrayScalar = createUseMatrixForArrayScalar({ typed, matrix }) /** * Bitwise left logical shift of a value x by y number of bits, `x << y`. @@ -78,6 +79,14 @@ export const createLeftShift = /* #__PURE__ */ factory(name, dependencies, ({ ty return matAlgo14xDs(x, y, self, false) }), + 'Array, number | BigNumber': typed.referToSelf(self => (x, y) => { + // check scalar + if (equalScalar(y, 0)) { + return clone(x) + } + return matAlgo15xAs(x, y, self, false) + }), + 'number | BigNumber, SparseMatrix': typed.referToSelf(self => (x, y) => { // check scalar if (equalScalar(x, 0)) { @@ -92,9 +101,15 @@ export const createLeftShift = /* #__PURE__ */ factory(name, dependencies, ({ ty return zeros(y.size(), y.storage()) } return matAlgo14xDs(y, x, self, true) + }), + 'number | BigNumber, Array': typed.referToSelf(self => (x, y) => { + // check scalar + if (equalScalar(x, 0)) { + return deepMap(y, () => x) + } + return matAlgo15xAs(y, x, self, true) }) }, - useMatrixForArrayScalar, matrixAlgorithmSuite({ SS: matAlgo08xS0Sid, DS: matAlgo01xDSid, diff --git a/src/function/bitwise/rightArithShift.js b/src/function/bitwise/rightArithShift.js index c84a411d06..ff71fbd546 100644 --- a/src/function/bitwise/rightArithShift.js +++ b/src/function/bitwise/rightArithShift.js @@ -2,13 +2,14 @@ import { rightArithShiftBigNumber } from '../../utils/bignumber/bitwise.js' import { createMatAlgo02xDS0 } from '../../type/matrix/utils/matAlgo02xDS0.js' import { createMatAlgo11xS0s } from '../../type/matrix/utils/matAlgo11xS0s.js' import { createMatAlgo14xDs } from '../../type/matrix/utils/matAlgo14xDs.js' +import { createMatAlgo15xAs } from '../../type/matrix/utils/matAlgo15xAs.js' import { createMatAlgo01xDSid } from '../../type/matrix/utils/matAlgo01xDSid.js' import { createMatAlgo10xSids } from '../../type/matrix/utils/matAlgo10xSids.js' import { createMatAlgo08xS0Sid } from '../../type/matrix/utils/matAlgo08xS0Sid.js' import { factory } from '../../utils/factory.js' import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js' -import { createUseMatrixForArrayScalar } from './useMatrixForArrayScalar.js' import { rightArithShiftNumber } from '../../plain/number/index.js' +import { clone, deepMap } from '../../utils/array.js' const name = 'rightArithShift' const dependencies = [ @@ -27,8 +28,8 @@ export const createRightArithShift = /* #__PURE__ */ factory(name, dependencies, const matAlgo10xSids = createMatAlgo10xSids({ typed, DenseMatrix }) const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) const matAlgo14xDs = createMatAlgo14xDs({ typed }) + const matAlgo15xAs = createMatAlgo15xAs() const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) - const useMatrixForArrayScalar = createUseMatrixForArrayScalar({ typed, matrix }) /** * Bitwise right arithmetic shift of a value x by y number of bits, `x >> y`. @@ -78,6 +79,14 @@ export const createRightArithShift = /* #__PURE__ */ factory(name, dependencies, return matAlgo14xDs(x, y, self, false) }), + 'Array, number | BigNumber': typed.referToSelf(self => (x, y) => { + // check scalar + if (equalScalar(y, 0)) { + return clone(x) + } + return matAlgo15xAs(x, y, self, false) + }), + 'number | BigNumber, SparseMatrix': typed.referToSelf(self => (x, y) => { // check scalar if (equalScalar(x, 0)) { @@ -92,9 +101,15 @@ export const createRightArithShift = /* #__PURE__ */ factory(name, dependencies, return zeros(y.size(), y.storage()) } return matAlgo14xDs(y, x, self, true) + }), + 'number | BigNumber, Array': typed.referToSelf(self => (x, y) => { + // check scalar + if (equalScalar(x, 0)) { + return deepMap(y, () => x) + } + return matAlgo15xAs(y, x, self, true) }) }, - useMatrixForArrayScalar, matrixAlgorithmSuite({ SS: matAlgo08xS0Sid, DS: matAlgo01xDSid, diff --git a/src/function/bitwise/rightLogShift.js b/src/function/bitwise/rightLogShift.js index 55cef7d355..f06abceef9 100644 --- a/src/function/bitwise/rightLogShift.js +++ b/src/function/bitwise/rightLogShift.js @@ -4,10 +4,11 @@ import { createMatAlgo14xDs } from '../../type/matrix/utils/matAlgo14xDs.js' import { createMatAlgo01xDSid } from '../../type/matrix/utils/matAlgo01xDSid.js' import { createMatAlgo10xSids } from '../../type/matrix/utils/matAlgo10xSids.js' import { createMatAlgo08xS0Sid } from '../../type/matrix/utils/matAlgo08xS0Sid.js' +import { createMatAlgo15xAs } from '../../type/matrix/utils/matAlgo15xAs.js' import { factory } from '../../utils/factory.js' import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js' import { rightLogShiftNumber } from '../../plain/number/index.js' -import { createUseMatrixForArrayScalar } from './useMatrixForArrayScalar.js' +import { deepMap, clone } from '../../utils/array.js' const name = 'rightLogShift' const dependencies = [ @@ -26,8 +27,8 @@ export const createRightLogShift = /* #__PURE__ */ factory(name, dependencies, ( const matAlgo10xSids = createMatAlgo10xSids({ typed, DenseMatrix }) const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) const matAlgo14xDs = createMatAlgo14xDs({ typed }) + const matAlgo15xAs = createMatAlgo15xAs() const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) - const useMatrixForArrayScalar = createUseMatrixForArrayScalar({ typed, matrix }) /** * Bitwise right logical shift of value x by y number of bits, `x >>> y`. @@ -76,6 +77,14 @@ export const createRightLogShift = /* #__PURE__ */ factory(name, dependencies, ( return matAlgo14xDs(x, y, self, false) }), + 'Array, number | BigNumber': typed.referToSelf(self => (x, y) => { + // check scalar + if (equalScalar(y, 0)) { + return clone(x) + } + return matAlgo15xAs(x, y, self, false) + }), + 'number | BigNumber, SparseMatrix': typed.referToSelf(self => (x, y) => { // check scalar if (equalScalar(x, 0)) { @@ -90,9 +99,16 @@ export const createRightLogShift = /* #__PURE__ */ factory(name, dependencies, ( return zeros(y.size(), y.storage()) } return matAlgo14xDs(y, x, self, true) + }), + + 'number | BigNumber, Array': typed.referToSelf(self => (x, y) => { + // check scalar + if (equalScalar(x, 0)) { + return deepMap(y, () => x) + } + return matAlgo15xAs(y, x, self, true) }) }, - useMatrixForArrayScalar, matrixAlgorithmSuite({ SS: matAlgo08xS0Sid, DS: matAlgo01xDSid, diff --git a/src/function/bitwise/useMatrixForArrayScalar.js b/src/function/bitwise/useMatrixForArrayScalar.js deleted file mode 100644 index ff7f231e2f..0000000000 --- a/src/function/bitwise/useMatrixForArrayScalar.js +++ /dev/null @@ -1,15 +0,0 @@ -import { factory } from '../../utils/factory.js' - -export const createUseMatrixForArrayScalar = /* #__PURE__ */ factory('useMatrixForArrayScalar', ['typed', 'matrix'], ({ typed, matrix }) => ({ - 'Array, number': typed.referTo('DenseMatrix, number', - selfDn => (x, y) => selfDn(matrix(x), y).valueOf()), - - 'Array, BigNumber': typed.referTo('DenseMatrix, BigNumber', - selfDB => (x, y) => selfDB(matrix(x), y).valueOf()), - - 'number, Array': typed.referTo('number, DenseMatrix', - selfnD => (x, y) => selfnD(x, matrix(y)).valueOf()), - - 'BigNumber, Array': typed.referTo('BigNumber, DenseMatrix', - selfBD => (x, y) => selfBD(x, matrix(y)).valueOf()) -})) diff --git a/test/unit-tests/function/arithmetic/add.test.js b/test/unit-tests/function/arithmetic/add.test.js index aa5c385bf3..1aab403f21 100644 --- a/test/unit-tests/function/arithmetic/add.test.js +++ b/test/unit-tests/function/arithmetic/add.test.js @@ -31,6 +31,11 @@ describe('add', function () { assert.deepStrictEqual(add([3, 4], 2), [5, 6]) }) + it('should add a scalar and a jagged array correctly', function () { + assert.deepStrictEqual(add(2, [[3, 4], 5]), [[5, 6], 7]) + assert.deepStrictEqual(add([[3, 4], 5], 2), [[5, 6], 7]) + }) + it('should add broadcastable arrays correctly', function () { const a2 = [1, 2] const a3 = [[3], [4]] diff --git a/test/unit-tests/function/arithmetic/mod.test.js b/test/unit-tests/function/arithmetic/mod.test.js index 5055a0f0b5..9906e3990e 100644 --- a/test/unit-tests/function/arithmetic/mod.test.js +++ b/test/unit-tests/function/arithmetic/mod.test.js @@ -155,6 +155,11 @@ describe('mod', function () { approxDeepEqual(mod(3, [[4, 3], [2, 1]]), [[3, 0], [1, 0]]) }) + it('should perform element-wise modulus on a jagged array and a scalar', function () { + approxDeepEqual(mod([[-4, -3, 0, -1], [0, 1, 2]], 3), [[2, 0, 0, 2], [0, 1, 2]]) + approxDeepEqual(mod(3, [[4, 3, 2], [2, 1]]), [[3, 0, 1], [1, 0]]) + }) + it('should perform element-wise modulus on broadcastable arrays', function () { approxDeepEqual(mod([-40, -31], [[3], [1]]), [[2, 2], [0, 0]]) approxDeepEqual(mod([[-40], [-31]], [3, 1]), [[2, 0], [2, 0]]) diff --git a/test/unit-tests/function/arithmetic/subtract.test.js b/test/unit-tests/function/arithmetic/subtract.test.js index 1302032171..5a8c1525f7 100644 --- a/test/unit-tests/function/arithmetic/subtract.test.js +++ b/test/unit-tests/function/arithmetic/subtract.test.js @@ -148,7 +148,12 @@ describe('subtract', function () { assert.deepStrictEqual(subtract([3, 0], 2), [1, -2]) }) - it('should substract broadcastable arrays correctly', function () { + it('should subtract a scalar and a jagged array correctly', function () { + assert.deepStrictEqual(subtract(2, [[3, 4], 5]), [[-1, -2], -3]) + assert.deepStrictEqual(subtract([[3, 4], 5], 2), [[1, 2], 3]) + }) + + it('should subtract broadcastable arrays correctly', function () { const a2 = [1, 2] const a3 = [[3], [4]] const a4 = subtract(a2, a3) diff --git a/test/unit-tests/function/bitwise/bitAnd.test.js b/test/unit-tests/function/bitwise/bitAnd.test.js index 9f1bee44e0..4fa95b61ac 100644 --- a/test/unit-tests/function/bitwise/bitAnd.test.js +++ b/test/unit-tests/function/bitwise/bitAnd.test.js @@ -199,6 +199,11 @@ describe('bitAnd', function () { assert.deepStrictEqual(bitAnd([3, 9], 12), [0, 8]) }) + it('should bitwise and a scalar and an jagged array correctly', function () { + assert.deepStrictEqual(bitAnd(12, [[3, 9], 5]), [[0, 8], 4]) + assert.deepStrictEqual(bitAnd([[3, 9], 5], 12), [[0, 8], 4]) + }) + it('should bitwise and broadcastable arrays correctly', function () { assert.deepStrictEqual(bitAnd([12, 13], [[3], [9]]), [[0, 1], [8, 9]]) assert.deepStrictEqual(bitAnd([[12], [13]], [3, 9]), [[0, 8], [1, 9]]) diff --git a/test/unit-tests/function/bitwise/bitOr.test.js b/test/unit-tests/function/bitwise/bitOr.test.js index d0a9aa27f7..c4a9a2bb82 100644 --- a/test/unit-tests/function/bitwise/bitOr.test.js +++ b/test/unit-tests/function/bitwise/bitOr.test.js @@ -199,6 +199,11 @@ describe('bitOr', function () { assert.deepStrictEqual(bitOr([3, 9], 12), [15, 13]) }) + it('should bitwise or a scalar and a jagged array correctly', function () { + assert.deepStrictEqual(bitOr(12, [[3, 9], 5]), [[15, 13], 13]) + assert.deepStrictEqual(bitOr([[3, 9], 5], 12), [[15, 13], 13]) + }) + it('should bitwise or broadcastable arrays correctly', function () { const a = [6, 4, 28] const b = [[13], [92], [101]] diff --git a/test/unit-tests/function/bitwise/leftShift.test.js b/test/unit-tests/function/bitwise/leftShift.test.js index 321d701438..f7c8b66794 100644 --- a/test/unit-tests/function/bitwise/leftShift.test.js +++ b/test/unit-tests/function/bitwise/leftShift.test.js @@ -111,6 +111,11 @@ describe('leftShift', function () { assert.deepStrictEqual(leftShift(2, [[1, 2], [8, 0]]), [[4, 8], [512, 2]]) }) + it('should left shift a jagged array and scalar', function () { + assert.deepStrictEqual(leftShift([[1, 2], [8, 0, 2]], 2), [[4, 8], [32, 0, 8]]) + assert.deepStrictEqual(leftShift(2, [[1, 2], [8, 0, 8]]), [[4, 8], [512, 2, 512]]) + }) + it('should left shift array - array', function () { assert.deepStrictEqual(leftShift([[1, 2], [8, 0]], [[4, 8], [32, 0]]), [[16, 512], [8, 0]]) assert.deepStrictEqual(leftShift([[4, 8], [32, 0]], [[1, 2], [8, 0]]), [[8, 32], [8192, 0]]) From 8e58d2bcbe94a47fa8a0887afb6254b3f3a3584b Mon Sep 17 00:00:00 2001 From: David Contreras Date: Sun, 14 Dec 2025 10:48:02 -0600 Subject: [PATCH 06/46] added more tests --- test/unit-tests/function/arithmetic/dotDivide.test.js | 3 +++ test/unit-tests/function/arithmetic/dotMultiply.test.js | 4 ++++ test/unit-tests/function/arithmetic/dotPow.test.js | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/test/unit-tests/function/arithmetic/dotDivide.test.js b/test/unit-tests/function/arithmetic/dotDivide.test.js index e99fa1cde9..feb4c35c94 100644 --- a/test/unit-tests/function/arithmetic/dotDivide.test.js +++ b/test/unit-tests/function/arithmetic/dotDivide.test.js @@ -68,6 +68,9 @@ describe('dotDivide', function () { const a = [[1, 2], [3, 4]] assert.deepStrictEqual(dotDivide(a, 2), [[0.5, 1], [1.5, 2]]) assert.deepStrictEqual(dotDivide([], 2), []) + // jagged array + const ja = [[1, 2, 3], [4], [5, 6]] + assert.deepStrictEqual(dotDivide(ja, 2), [[0.5, 1, 1.5], [2], [2.5, 3]]) }) it('should divide 1 over a array element-wise', function () { diff --git a/test/unit-tests/function/arithmetic/dotMultiply.test.js b/test/unit-tests/function/arithmetic/dotMultiply.test.js index 8e7fb57e75..9468737962 100644 --- a/test/unit-tests/function/arithmetic/dotMultiply.test.js +++ b/test/unit-tests/function/arithmetic/dotMultiply.test.js @@ -76,6 +76,10 @@ describe('dotMultiply', function () { approxDeepEqual(dotMultiply(3, a), [[3, 0], [9, 12]]) approxDeepEqual(dotMultiply([1, 2, 3, 4], 2), [2, 4, 6, 8]) approxDeepEqual(dotMultiply(2, [1, 2, 3, 4]), [2, 4, 6, 8]) + // jagged array + const ja = [[1, 2, 3], [4], [5, 6]] + approxDeepEqual(dotMultiply(ja, 2), [[2, 4, 6], [8], [10, 12]]) + approxDeepEqual(dotMultiply(2, ja), [[2, 4, 6], [8], [10, 12]]) }) it('should multiply broadcastable arrays element-wise', function () { diff --git a/test/unit-tests/function/arithmetic/dotPow.test.js b/test/unit-tests/function/arithmetic/dotPow.test.js index 86bcff95c5..a543c14ec4 100644 --- a/test/unit-tests/function/arithmetic/dotPow.test.js +++ b/test/unit-tests/function/arithmetic/dotPow.test.js @@ -92,12 +92,16 @@ describe('dotPow', function () { approxDeepEqual(dotPow([[1, 2], [0, 4]], 2), [[1, 4], [0, 16]]) approxDeepEqual(dotPow([[1, 2], [0, 4]], 2.5), [[1, 5.65685424949238], [0, 32]]) approxDeepEqual(dotPow([[1, 2, 3], [4, 5, 0]], 2), [[1, 4, 9], [16, 25, 0]]) + // jagged array + approxDeepEqual(dotPow([[1, 2, 3], [4], [5, 6]], 2), [[1, 4, 9], [16], [25, 36]]) }) it('should elevate scalar .^ array', function () { approxDeepEqual(dotPow(2, [[1, 2], [0, 4]]), [[2, 4], [1, 16]]) approxDeepEqual(dotPow(2.5, [[1, 2], [0, 4]]), [[2.5, 6.25], [1, 39.0625]]) approxDeepEqual(dotPow(2, [[1, 2, 3], [4, 5, 0]]), [[2, 4, 8], [16, 32, 1]]) + // jagged array + approxDeepEqual(dotPow(2, [[1, 2, 3], [4], [5, 6]]), [[2, 4, 8], [16], [32, 64]]) }) it('should elevate broadcastable arrays element-wise', function () { From cdceb7950bca310473132c8827bbea25cb59fe21 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Sun, 14 Dec 2025 21:25:07 -0600 Subject: [PATCH 07/46] Added documentation --- docs/datatypes/matrices.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/datatypes/matrices.md b/docs/datatypes/matrices.md index 01178f7413..8f22f0dfd3 100644 --- a/docs/datatypes/matrices.md +++ b/docs/datatypes/matrices.md @@ -12,7 +12,10 @@ dense and sparse matrices. Math.js supports two types of matrices: - `Array`, a regular JavaScript array. A multidimensional array can be created - by nesting arrays. + by nesting arrays. If the elements of an array are of the same size, it is a + rectangular array. If the elements are all arrays but not of the same size, + it is a jagged array and if not all elements are arrays then it's an + heterogeneous array. - `Matrix`, a matrix implementation by math.js. A `Matrix` is an object wrapped around a regular JavaScript `Array`, providing utility functions for easy matrix manipulation such as `subset`, `size`, `resize`, `clone`, and more. @@ -224,6 +227,27 @@ If you have a matrix where the first dimension means `x` and the second means `y`, this will look confusing since `x` is printed as _column_ (vertically) and `y` as _row_ (horizontally). +## Not rectangular arrays + +By nesting arrays it is possible to have arrays that are not rectangular, for example. +```js +[[1, 2], [3, 4]] // rectangular of size [2, 2] +[[1, 2], [3]] // jagged +[[1, 2], 3] // heterogeneous +``` + +These types of arrays can't be converted to a matrix, but many operations are available for them. +```js +const A = [[1, 2], 3] +math.add(A, 1) +math.map(A, a => a+1) +math.forEach(A, a => console.log(a)) +``` +Many matrix functions expect a rectangular array and might provide unexpected results with non rectangular arrays, for example. +```js +math.size([[1, 2], [3]]) // [2, 2] +``` +The process of validation for rectangularity is expensive and this provides a fast way of working with nested arrays of many kinds. ## Resizing From d67b73d541afaa92a10a7f0465ab194aba645ecf Mon Sep 17 00:00:00 2001 From: David Contreras Date: Tue, 16 Dec 2025 21:30:56 -0600 Subject: [PATCH 08/46] Added benchmarks --- src/type/matrix/utils/matAlgo14xDs.js | 2 +- src/type/matrix/utils/matAlgo15xAs.js | 2 +- test/benchmark/broadcast.js | 33 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 test/benchmark/broadcast.js diff --git a/src/type/matrix/utils/matAlgo14xDs.js b/src/type/matrix/utils/matAlgo14xDs.js index f7a3b7f9f8..14acc1ba0e 100644 --- a/src/type/matrix/utils/matAlgo14xDs.js +++ b/src/type/matrix/utils/matAlgo14xDs.js @@ -34,6 +34,6 @@ export const createMatAlgo14xDs = /* #__PURE__ */ factory(name, dependencies, ({ cf = typed.find(callback, [adt, adt]) } - return inverse ? a.map(v => cf(b, v)) : a.map(v => cf(v, b)) + return inverse ? a.map(v => cf(b, v), false, true) : a.map(v => cf(v, b), false, true) } }) diff --git a/src/type/matrix/utils/matAlgo15xAs.js b/src/type/matrix/utils/matAlgo15xAs.js index 5e664122f1..5808f21bb4 100644 --- a/src/type/matrix/utils/matAlgo15xAs.js +++ b/src/type/matrix/utils/matAlgo15xAs.js @@ -21,6 +21,6 @@ export const createMatAlgo15xAs = /* #__PURE__ */ factory(name, dependencies, () * https://github.com/josdejong/mathjs/pull/346#issuecomment-97659042 */ return function matAlgo15xAs (a, b, cf, inverse) { - return inverse ? map(a, v => cf(b, v)) : map(a, v => cf(v, b)) + return inverse ? map(a, v => cf(b, v), true) : map(a, v => cf(v, b), true) } }) diff --git a/test/benchmark/broadcast.js b/test/benchmark/broadcast.js new file mode 100644 index 0000000000..bb509c0b7e --- /dev/null +++ b/test/benchmark/broadcast.js @@ -0,0 +1,33 @@ +import { Bench } from 'tinybench' +import { matrix, add, subtract, random } from '../../lib/esm/index.js' +import { formatTaskResult } from './utils/formatTaskResult.js' + +const array = random([500, 500], -10, 10) +const genericMatrix = matrix(array) +const numberMatrix = matrix(array, 'dense', 'number') + +// console.log('data', array) +// console.log('abs(data)', abs(array))npm run + +const bench = new Bench({ time: 100, iterations: 100 }) + .add('add(array, 1)', () => { + add(array, 1) + }) + .add('add(matrix, 1)', () => { + add(genericMatrix, 1) + }) + .add('add(numberMatrix, 1)', () => { + add(numberMatrix, 1) + }) + .add('subtract(array, 1)', () => { + subtract(array, 1) + }) + .add('subtract(matrix, 1)', () => { + subtract(genericMatrix, 1) + }) + .add('subtract(numberMatrix, 1)', () => { + subtract(numberMatrix, 1) + }) + +bench.addEventListener('cycle', (event) => console.log(formatTaskResult(bench, event.task))) +await bench.run() From a720b664d9463d7d339210225e30616f0ca59f58 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Tue, 16 Dec 2025 21:35:41 -0600 Subject: [PATCH 09/46] Fixed comment to allow for non-rectangular arrays --- src/type/matrix/utils/matAlgo15xAs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/type/matrix/utils/matAlgo15xAs.js b/src/type/matrix/utils/matAlgo15xAs.js index 5808f21bb4..61c464b852 100644 --- a/src/type/matrix/utils/matAlgo15xAs.js +++ b/src/type/matrix/utils/matAlgo15xAs.js @@ -7,7 +7,7 @@ const dependencies = [] export const createMatAlgo15xAs = /* #__PURE__ */ factory(name, dependencies, () => { /** * Iterates over Array items and invokes the callback function f(Aij..z, b). - * Callback function invoked MxN times. + * Callback function invoked once for each item. * * C(i,j,...z) = f(Aij..z, b) * From 4a215ed86c777d6b0db8c6994841530cabaab618 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Fri, 19 Dec 2025 19:49:39 -0600 Subject: [PATCH 10/46] Define terminology used for nested arrays. --- docs/datatypes/matrices.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/datatypes/matrices.md b/docs/datatypes/matrices.md index 8f22f0dfd3..69e4ce5f78 100644 --- a/docs/datatypes/matrices.md +++ b/docs/datatypes/matrices.md @@ -12,13 +12,13 @@ dense and sparse matrices. Math.js supports two types of matrices: - `Array`, a regular JavaScript array. A multidimensional array can be created - by nesting arrays. If the elements of an array are of the same size, it is a - rectangular array. If the elements are all arrays but not of the same size, - it is a jagged array and if not all elements are arrays then it's an - heterogeneous array. + by nesting arrays. The following terminology will be used to define different kinds of nested arrays. + - **Recangular array**: All elements of an array are arrays of the same size. Like `[[1, 2], [3, 4]]` + - **Jagged arrays**: All elements of an array are arrays but not of the same size. Like `[[1, 2], [3, 4, 5]]` + - **Heterogeneous arrays**: If not all the elements inside an array are arrays. Like `[[1, 2], 3]`. - `Matrix`, a matrix implementation by math.js. A `Matrix` is an object wrapped around a regular JavaScript `Array`, providing utility functions for easy - matrix manipulation such as `subset`, `size`, `resize`, `clone`, and more. + matrix manipulation such as `subset`, `size`, `resize`, `clone`, and more. Nested arrays must be rectangular to be converted to a `Matrix`. In most cases, the type of matrix output from functions is determined by the function input: An `Array` as input will return an `Array`, a `Matrix` as input From 4bdb5cac035a6dff41f72d7cc3a35a632e7e6d70 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Fri, 19 Dec 2025 20:00:40 -0600 Subject: [PATCH 11/46] Documentation fixes for non-rectangular arrays --- docs/datatypes/matrices.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/datatypes/matrices.md b/docs/datatypes/matrices.md index 69e4ce5f78..a1d40d37ee 100644 --- a/docs/datatypes/matrices.md +++ b/docs/datatypes/matrices.md @@ -227,27 +227,27 @@ If you have a matrix where the first dimension means `x` and the second means `y`, this will look confusing since `x` is printed as _column_ (vertically) and `y` as _row_ (horizontally). -## Not rectangular arrays +## Non-rectangular arrays By nesting arrays it is possible to have arrays that are not rectangular, for example. ```js -[[1, 2], [3, 4]] // rectangular of size [2, 2] -[[1, 2], [3]] // jagged -[[1, 2], 3] // heterogeneous +[[1, 2], [3, 4]] // rectangular of size [2, 2] +[[1, 2], [3, 4, 5]] // jagged +[[1, 2], 3] // heterogeneous ``` -These types of arrays can't be converted to a matrix, but many operations are available for them. +Jagged and heterogeneous arrays can't be converted to a matrix, but many operations are available for them. ```js const A = [[1, 2], 3] math.add(A, 1) math.map(A, a => a+1) math.forEach(A, a => console.log(a)) ``` -Many matrix functions expect a rectangular array and might provide unexpected results with non rectangular arrays, for example. +Some matrix functions expect a rectangular array and might provide unexpected results with non rectangular arrays, for example. ```js math.size([[1, 2], [3]]) // [2, 2] ``` -The process of validation for rectangularity is expensive and this provides a fast way of working with nested arrays of many kinds. +The process of validation for rectangularity is expensive and is mandatory to create a `Matrix`, thus there might be a performance benefit of not converting an `Array` to a `Matrix`. ## Resizing From 8c6c47dad25403cbf67d618a9ffc09cd135ede6e Mon Sep 17 00:00:00 2001 From: David Contreras Date: Fri, 19 Dec 2025 20:16:13 -0600 Subject: [PATCH 12/46] Removed concat and other dependancies from factory functions --- src/function/arithmetic/add.js | 8 +++----- src/function/arithmetic/dotDivide.js | 5 ++--- src/function/arithmetic/dotMultiply.js | 7 +++---- src/function/arithmetic/dotPow.js | 5 ++--- src/function/arithmetic/gcd.js | 2 +- src/function/arithmetic/lcm.js | 7 +++---- src/function/arithmetic/mod.js | 7 +++---- src/function/arithmetic/nthRoot.js | 7 +++---- src/function/arithmetic/subtract.js | 8 +++----- src/function/bitwise/bitAnd.js | 7 +++---- src/function/bitwise/bitOr.js | 7 +++---- src/function/bitwise/bitXor.js | 5 ++--- src/function/bitwise/leftShift.js | 7 +++---- src/function/bitwise/rightArithShift.js | 7 +++---- src/function/bitwise/rightLogShift.js | 7 +++---- src/function/logical/and.js | 7 +++---- src/function/logical/or.js | 7 +++---- src/function/logical/xor.js | 5 ++--- src/function/relational/compare.js | 7 +++---- src/function/relational/compareText.js | 7 +++---- src/function/relational/equal.js | 2 +- src/function/relational/larger.js | 5 ++--- src/function/relational/largerEq.js | 5 ++--- src/function/relational/smaller.js | 5 ++--- src/function/relational/smallerEq.js | 5 ++--- src/function/relational/unequal.js | 6 ++---- src/function/trigonometry/atan2.js | 7 +++---- src/function/unit/to.js | 7 +++---- 28 files changed, 71 insertions(+), 100 deletions(-) diff --git a/src/function/arithmetic/add.js b/src/function/arithmetic/add.js index b9bc0ae9af..82d4114535 100644 --- a/src/function/arithmetic/add.js +++ b/src/function/arithmetic/add.js @@ -10,19 +10,17 @@ const dependencies = [ 'matrix', 'addScalar', 'equalScalar', - 'DenseMatrix', - 'SparseMatrix', - 'concat' + 'DenseMatrix' ] export const createAdd = /* #__PURE__ */ factory( name, dependencies, - ({ typed, matrix, addScalar, equalScalar, DenseMatrix, SparseMatrix, concat }) => { + ({ typed, matrix, addScalar, equalScalar, DenseMatrix }) => { const matAlgo01xDSid = createMatAlgo01xDSid({ typed }) const matAlgo04xSidSid = createMatAlgo04xSidSid({ typed, equalScalar }) const matAlgo10xSids = createMatAlgo10xSids({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Add two or more values, `x + y`. * For matrices, the function is evaluated element wise. diff --git a/src/function/arithmetic/dotDivide.js b/src/function/arithmetic/dotDivide.js index 3587faf762..f97a64e961 100644 --- a/src/function/arithmetic/dotDivide.js +++ b/src/function/arithmetic/dotDivide.js @@ -13,17 +13,16 @@ const dependencies = [ 'equalScalar', 'divideScalar', 'DenseMatrix', - 'concat', 'SparseMatrix' ] -export const createDotDivide = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, divideScalar, DenseMatrix, concat, SparseMatrix }) => { +export const createDotDivide = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, divideScalar, DenseMatrix, SparseMatrix }) => { const matAlgo02xDS0 = createMatAlgo02xDS0({ typed, equalScalar }) const matAlgo03xDSf = createMatAlgo03xDSf({ typed }) const matAlgo07xSSf = createMatAlgo07xSSf({ typed, SparseMatrix }) const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Divide two matrices element wise. The function accepts both matrices and diff --git a/src/function/arithmetic/dotMultiply.js b/src/function/arithmetic/dotMultiply.js index d49287bc6b..5552be8460 100644 --- a/src/function/arithmetic/dotMultiply.js +++ b/src/function/arithmetic/dotMultiply.js @@ -9,15 +9,14 @@ const dependencies = [ 'typed', 'matrix', 'equalScalar', - 'multiplyScalar', - 'concat' + 'multiplyScalar' ] -export const createDotMultiply = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, multiplyScalar, concat }) => { +export const createDotMultiply = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, multiplyScalar }) => { const matAlgo02xDS0 = createMatAlgo02xDS0({ typed, equalScalar }) const matAlgo09xS0Sf = createMatAlgo09xS0Sf({ typed, equalScalar }) const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Multiply two matrices element wise. The function accepts both matrices and diff --git a/src/function/arithmetic/dotPow.js b/src/function/arithmetic/dotPow.js index a1c25f1522..53d62bfbaa 100644 --- a/src/function/arithmetic/dotPow.js +++ b/src/function/arithmetic/dotPow.js @@ -12,16 +12,15 @@ const dependencies = [ 'matrix', 'pow', 'DenseMatrix', - 'concat', 'SparseMatrix' ] -export const createDotPow = /* #__PURE__ */ factory(name, dependencies, ({ typed, equalScalar, matrix, pow, DenseMatrix, concat, SparseMatrix }) => { +export const createDotPow = /* #__PURE__ */ factory(name, dependencies, ({ typed, equalScalar, matrix, pow, DenseMatrix, SparseMatrix }) => { const matAlgo03xDSf = createMatAlgo03xDSf({ typed }) const matAlgo07xSSf = createMatAlgo07xSSf({ typed, SparseMatrix }) const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) const powScalarSignatures = {} for (const signature in pow.signatures) { diff --git a/src/function/arithmetic/gcd.js b/src/function/arithmetic/gcd.js index d370c498d6..ffb9c09142 100644 --- a/src/function/arithmetic/gcd.js +++ b/src/function/arithmetic/gcd.js @@ -32,7 +32,7 @@ export const createGcd = /* #__PURE__ */ factory(name, dependencies, ({ typed, m const matAlgo01xDSid = createMatAlgo01xDSid({ typed }) const matAlgo04xSidSid = createMatAlgo04xSidSid({ typed, equalScalar }) const matAlgo10xSids = createMatAlgo10xSids({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Calculate the greatest common divisor for two or more values or arrays. diff --git a/src/function/arithmetic/lcm.js b/src/function/arithmetic/lcm.js index d53dd3e799..8f16f0d54a 100644 --- a/src/function/arithmetic/lcm.js +++ b/src/function/arithmetic/lcm.js @@ -9,15 +9,14 @@ const name = 'lcm' const dependencies = [ 'typed', 'matrix', - 'equalScalar', - 'concat' + 'equalScalar' ] -export const createLcm = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, concat }) => { +export const createLcm = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar }) => { const matAlgo02xDS0 = createMatAlgo02xDS0({ typed, equalScalar }) const matAlgo06xS0S0 = createMatAlgo06xS0S0({ typed, equalScalar }) const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) const lcmTypes = 'number | BigNumber | Fraction | Matrix | Array' const lcmManySignature = {} diff --git a/src/function/arithmetic/mod.js b/src/function/arithmetic/mod.js index dee0b97e4a..40d8c09b0e 100644 --- a/src/function/arithmetic/mod.js +++ b/src/function/arithmetic/mod.js @@ -15,18 +15,17 @@ const dependencies = [ 'matrix', 'equalScalar', 'zeros', - 'DenseMatrix', - 'concat' + 'DenseMatrix' ] -export const createMod = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, round, matrix, equalScalar, zeros, DenseMatrix, concat }) => { +export const createMod = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, round, matrix, equalScalar, zeros, DenseMatrix }) => { const floor = createFloor({ typed, config, round, matrix, equalScalar, zeros, DenseMatrix }) const matAlgo02xDS0 = createMatAlgo02xDS0({ typed, equalScalar }) const matAlgo03xDSf = createMatAlgo03xDSf({ typed }) const matAlgo05xSfSf = createMatAlgo05xSfSf({ typed, equalScalar }) const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Calculates the modulus, the remainder of an integer division. diff --git a/src/function/arithmetic/nthRoot.js b/src/function/arithmetic/nthRoot.js index abcbaeaf3f..5887797a2c 100644 --- a/src/function/arithmetic/nthRoot.js +++ b/src/function/arithmetic/nthRoot.js @@ -11,16 +11,15 @@ const dependencies = [ 'typed', 'matrix', 'equalScalar', - 'BigNumber', - 'concat' + 'BigNumber' ] -export const createNthRoot = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, BigNumber, concat }) => { +export const createNthRoot = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, BigNumber }) => { const matAlgo01xDSid = createMatAlgo01xDSid({ typed }) const matAlgo02xDS0 = createMatAlgo02xDS0({ typed, equalScalar }) const matAlgo06xS0S0 = createMatAlgo06xS0S0({ typed, equalScalar }) const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Calculate the nth root of a value. diff --git a/src/function/arithmetic/subtract.js b/src/function/arithmetic/subtract.js index aa6732484b..b662dcf3c5 100644 --- a/src/function/arithmetic/subtract.js +++ b/src/function/arithmetic/subtract.js @@ -12,12 +12,10 @@ const dependencies = [ 'matrix', 'equalScalar', 'subtractScalar', - 'unaryMinus', - 'DenseMatrix', - 'concat' + 'DenseMatrix' ] -export const createSubtract = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, subtractScalar, unaryMinus, DenseMatrix, concat }) => { +export const createSubtract = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, subtractScalar, DenseMatrix }) => { // TODO: split function subtract in two: subtract and subtractScalar const matAlgo01xDSid = createMatAlgo01xDSid({ typed }) @@ -25,7 +23,7 @@ export const createSubtract = /* #__PURE__ */ factory(name, dependencies, ({ typ const matAlgo05xSfSf = createMatAlgo05xSfSf({ typed, equalScalar }) const matAlgo10xSids = createMatAlgo10xSids({ typed, DenseMatrix }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Subtract two values, `x - y`. diff --git a/src/function/bitwise/bitAnd.js b/src/function/bitwise/bitAnd.js index d6e169b09e..0669c659e2 100644 --- a/src/function/bitwise/bitAnd.js +++ b/src/function/bitwise/bitAnd.js @@ -10,15 +10,14 @@ const name = 'bitAnd' const dependencies = [ 'typed', 'matrix', - 'equalScalar', - 'concat' + 'equalScalar' ] -export const createBitAnd = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, concat }) => { +export const createBitAnd = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar }) => { const matAlgo02xDS0 = createMatAlgo02xDS0({ typed, equalScalar }) const matAlgo06xS0S0 = createMatAlgo06xS0S0({ typed, equalScalar }) const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Bitwise AND two values, `x & y`. diff --git a/src/function/bitwise/bitOr.js b/src/function/bitwise/bitOr.js index c0f7dea215..969fd8c218 100644 --- a/src/function/bitwise/bitOr.js +++ b/src/function/bitwise/bitOr.js @@ -11,15 +11,14 @@ const dependencies = [ 'typed', 'matrix', 'equalScalar', - 'DenseMatrix', - 'concat' + 'DenseMatrix' ] -export const createBitOr = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, DenseMatrix, concat }) => { +export const createBitOr = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, DenseMatrix }) => { const matAlgo01xDSid = createMatAlgo01xDSid({ typed }) const matAlgo04xSidSid = createMatAlgo04xSidSid({ typed, equalScalar }) const matAlgo10xSids = createMatAlgo10xSids({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Bitwise OR two values, `x | y`. diff --git a/src/function/bitwise/bitXor.js b/src/function/bitwise/bitXor.js index a46acacc8a..f9a6f47456 100644 --- a/src/function/bitwise/bitXor.js +++ b/src/function/bitwise/bitXor.js @@ -11,15 +11,14 @@ const dependencies = [ 'typed', 'matrix', 'DenseMatrix', - 'concat', 'SparseMatrix' ] -export const createBitXor = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, DenseMatrix, concat, SparseMatrix }) => { +export const createBitXor = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, DenseMatrix, SparseMatrix }) => { const matAlgo03xDSf = createMatAlgo03xDSf({ typed }) const matAlgo07xSSf = createMatAlgo07xSSf({ typed, SparseMatrix }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Bitwise XOR two values, `x ^ y`. diff --git a/src/function/bitwise/leftShift.js b/src/function/bitwise/leftShift.js index fa8761203f..01b46e640f 100644 --- a/src/function/bitwise/leftShift.js +++ b/src/function/bitwise/leftShift.js @@ -17,11 +17,10 @@ const dependencies = [ 'matrix', 'equalScalar', 'zeros', - 'DenseMatrix', - 'concat' + 'DenseMatrix' ] -export const createLeftShift = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, zeros, DenseMatrix, concat }) => { +export const createLeftShift = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, zeros, DenseMatrix }) => { const matAlgo01xDSid = createMatAlgo01xDSid({ typed }) const matAlgo02xDS0 = createMatAlgo02xDS0({ typed, equalScalar }) const matAlgo08xS0Sid = createMatAlgo08xS0Sid({ typed, equalScalar }) @@ -29,7 +28,7 @@ export const createLeftShift = /* #__PURE__ */ factory(name, dependencies, ({ ty const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) const matAlgo14xDs = createMatAlgo14xDs({ typed }) const matAlgo15xAs = createMatAlgo15xAs() - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Bitwise left logical shift of a value x by y number of bits, `x << y`. diff --git a/src/function/bitwise/rightArithShift.js b/src/function/bitwise/rightArithShift.js index ff71fbd546..3a299e262a 100644 --- a/src/function/bitwise/rightArithShift.js +++ b/src/function/bitwise/rightArithShift.js @@ -17,11 +17,10 @@ const dependencies = [ 'matrix', 'equalScalar', 'zeros', - 'DenseMatrix', - 'concat' + 'DenseMatrix' ] -export const createRightArithShift = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, zeros, DenseMatrix, concat }) => { +export const createRightArithShift = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, zeros, DenseMatrix }) => { const matAlgo01xDSid = createMatAlgo01xDSid({ typed }) const matAlgo02xDS0 = createMatAlgo02xDS0({ typed, equalScalar }) const matAlgo08xS0Sid = createMatAlgo08xS0Sid({ typed, equalScalar }) @@ -29,7 +28,7 @@ export const createRightArithShift = /* #__PURE__ */ factory(name, dependencies, const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) const matAlgo14xDs = createMatAlgo14xDs({ typed }) const matAlgo15xAs = createMatAlgo15xAs() - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Bitwise right arithmetic shift of a value x by y number of bits, `x >> y`. diff --git a/src/function/bitwise/rightLogShift.js b/src/function/bitwise/rightLogShift.js index f06abceef9..bbd66d5397 100644 --- a/src/function/bitwise/rightLogShift.js +++ b/src/function/bitwise/rightLogShift.js @@ -16,11 +16,10 @@ const dependencies = [ 'matrix', 'equalScalar', 'zeros', - 'DenseMatrix', - 'concat' + 'DenseMatrix' ] -export const createRightLogShift = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, zeros, DenseMatrix, concat }) => { +export const createRightLogShift = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, zeros, DenseMatrix }) => { const matAlgo01xDSid = createMatAlgo01xDSid({ typed }) const matAlgo02xDS0 = createMatAlgo02xDS0({ typed, equalScalar }) const matAlgo08xS0Sid = createMatAlgo08xS0Sid({ typed, equalScalar }) @@ -28,7 +27,7 @@ export const createRightLogShift = /* #__PURE__ */ factory(name, dependencies, ( const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) const matAlgo14xDs = createMatAlgo14xDs({ typed }) const matAlgo15xAs = createMatAlgo15xAs() - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Bitwise right logical shift of value x by y number of bits, `x >>> y`. diff --git a/src/function/logical/and.js b/src/function/logical/and.js index 827751d042..ce15688d38 100644 --- a/src/function/logical/and.js +++ b/src/function/logical/and.js @@ -12,16 +12,15 @@ const dependencies = [ 'matrix', 'equalScalar', 'zeros', - 'not', - 'concat' + 'not' ] -export const createAnd = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, zeros, not, concat }) => { +export const createAnd = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, zeros, not }) => { const matAlgo02xDS0 = createMatAlgo02xDS0({ typed, equalScalar }) const matAlgo06xS0S0 = createMatAlgo06xS0S0({ typed, equalScalar }) const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) const matAlgo14xDs = createMatAlgo14xDs({ typed }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Logical `and`. Test whether two values are both defined with a nonzero/nonempty value. diff --git a/src/function/logical/or.js b/src/function/logical/or.js index 12d6c5b48d..0a8c7ad426 100644 --- a/src/function/logical/or.js +++ b/src/function/logical/or.js @@ -10,15 +10,14 @@ const dependencies = [ 'typed', 'matrix', 'equalScalar', - 'DenseMatrix', - 'concat' + 'DenseMatrix' ] -export const createOr = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, DenseMatrix, concat }) => { +export const createOr = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, DenseMatrix }) => { const matAlgo03xDSf = createMatAlgo03xDSf({ typed }) const matAlgo05xSfSf = createMatAlgo05xSfSf({ typed, equalScalar }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Logical `or`. Test if at least one value is defined with a nonzero/nonempty value. diff --git a/src/function/logical/xor.js b/src/function/logical/xor.js index 1ae3a05f5b..20729e1fc1 100644 --- a/src/function/logical/xor.js +++ b/src/function/logical/xor.js @@ -10,15 +10,14 @@ const dependencies = [ 'typed', 'matrix', 'DenseMatrix', - 'concat', 'SparseMatrix' ] -export const createXor = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, DenseMatrix, concat, SparseMatrix }) => { +export const createXor = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, DenseMatrix, SparseMatrix }) => { const matAlgo03xDSf = createMatAlgo03xDSf({ typed }) const matAlgo07xSSf = createMatAlgo07xSSf({ typed, SparseMatrix }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Logical `xor`. Test whether one and only one value is defined with a nonzero/nonempty value. diff --git a/src/function/relational/compare.js b/src/function/relational/compare.js index 39886c3920..0b71f6c0e0 100644 --- a/src/function/relational/compare.js +++ b/src/function/relational/compare.js @@ -15,15 +15,14 @@ const dependencies = [ 'equalScalar', 'BigNumber', 'Fraction', - 'DenseMatrix', - 'concat' + 'DenseMatrix' ] -export const createCompare = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, equalScalar, matrix, BigNumber, Fraction, DenseMatrix, concat }) => { +export const createCompare = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, equalScalar, matrix, BigNumber, Fraction, DenseMatrix }) => { const matAlgo03xDSf = createMatAlgo03xDSf({ typed }) const matAlgo05xSfSf = createMatAlgo05xSfSf({ typed, equalScalar }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) const compareUnits = createCompareUnits({ typed }) /** diff --git a/src/function/relational/compareText.js b/src/function/relational/compareText.js index 310b55cd0e..754db4ec55 100644 --- a/src/function/relational/compareText.js +++ b/src/function/relational/compareText.js @@ -5,14 +5,13 @@ import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgori const name = 'compareText' const dependencies = [ 'typed', - 'matrix', - 'concat' + 'matrix' ] _compareText.signature = 'any, any' -export const createCompareText = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, concat }) => { - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) +export const createCompareText = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix }) => { + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Compare two strings lexically. Comparison is case sensitive. diff --git a/src/function/relational/equal.js b/src/function/relational/equal.js index a4e1031b68..6c1c983cf0 100644 --- a/src/function/relational/equal.js +++ b/src/function/relational/equal.js @@ -13,7 +13,7 @@ const dependencies = [ 'SparseMatrix' ] -export const createEqual = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, DenseMatrix, concat, SparseMatrix }) => { +export const createEqual = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, DenseMatrix, SparseMatrix }) => { const matAlgo03xDSf = createMatAlgo03xDSf({ typed }) const matAlgo07xSSf = createMatAlgo07xSSf({ typed, SparseMatrix }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) diff --git a/src/function/relational/larger.js b/src/function/relational/larger.js index 8507d21511..921ebee787 100644 --- a/src/function/relational/larger.js +++ b/src/function/relational/larger.js @@ -14,15 +14,14 @@ const dependencies = [ 'bignumber', 'matrix', 'DenseMatrix', - 'concat', 'SparseMatrix' ] -export const createLarger = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, bignumber, matrix, DenseMatrix, concat, SparseMatrix }) => { +export const createLarger = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, bignumber, matrix, DenseMatrix, SparseMatrix }) => { const matAlgo03xDSf = createMatAlgo03xDSf({ typed }) const matAlgo07xSSf = createMatAlgo07xSSf({ typed, SparseMatrix }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) const compareUnits = createCompareUnits({ typed }) /** diff --git a/src/function/relational/largerEq.js b/src/function/relational/largerEq.js index 6760df7f6c..66c3d3879e 100644 --- a/src/function/relational/largerEq.js +++ b/src/function/relational/largerEq.js @@ -13,15 +13,14 @@ const dependencies = [ 'config', 'matrix', 'DenseMatrix', - 'concat', 'SparseMatrix' ] -export const createLargerEq = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, matrix, DenseMatrix, concat, SparseMatrix }) => { +export const createLargerEq = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, matrix, DenseMatrix, SparseMatrix }) => { const matAlgo03xDSf = createMatAlgo03xDSf({ typed }) const matAlgo07xSSf = createMatAlgo07xSSf({ typed, SparseMatrix }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) const compareUnits = createCompareUnits({ typed }) /** diff --git a/src/function/relational/smaller.js b/src/function/relational/smaller.js index 87807f0240..96839708ab 100644 --- a/src/function/relational/smaller.js +++ b/src/function/relational/smaller.js @@ -14,15 +14,14 @@ const dependencies = [ 'bignumber', 'matrix', 'DenseMatrix', - 'concat', 'SparseMatrix' ] -export const createSmaller = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, bignumber, matrix, DenseMatrix, concat, SparseMatrix }) => { +export const createSmaller = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, bignumber, matrix, DenseMatrix, SparseMatrix }) => { const matAlgo03xDSf = createMatAlgo03xDSf({ typed }) const matAlgo07xSSf = createMatAlgo07xSSf({ typed, SparseMatrix }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) const compareUnits = createCompareUnits({ typed }) /** diff --git a/src/function/relational/smallerEq.js b/src/function/relational/smallerEq.js index b314418a4c..7494e2ea0e 100644 --- a/src/function/relational/smallerEq.js +++ b/src/function/relational/smallerEq.js @@ -13,15 +13,14 @@ const dependencies = [ 'config', 'matrix', 'DenseMatrix', - 'concat', 'SparseMatrix' ] -export const createSmallerEq = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, matrix, DenseMatrix, concat, SparseMatrix }) => { +export const createSmallerEq = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, matrix, DenseMatrix, SparseMatrix }) => { const matAlgo03xDSf = createMatAlgo03xDSf({ typed }) const matAlgo07xSSf = createMatAlgo07xSSf({ typed, SparseMatrix }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) const compareUnits = createCompareUnits({ typed }) /** diff --git a/src/function/relational/unequal.js b/src/function/relational/unequal.js index 1accaf846b..506d609713 100644 --- a/src/function/relational/unequal.js +++ b/src/function/relational/unequal.js @@ -7,19 +7,17 @@ import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgori const name = 'unequal' const dependencies = [ 'typed', - 'config', 'equalScalar', 'matrix', 'DenseMatrix', - 'concat', 'SparseMatrix' ] -export const createUnequal = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, equalScalar, matrix, DenseMatrix, concat, SparseMatrix }) => { +export const createUnequal = /* #__PURE__ */ factory(name, dependencies, ({ typed, equalScalar, matrix, DenseMatrix, SparseMatrix }) => { const matAlgo03xDSf = createMatAlgo03xDSf({ typed }) const matAlgo07xSSf = createMatAlgo07xSSf({ typed, SparseMatrix }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Test whether two values are unequal. diff --git a/src/function/trigonometry/atan2.js b/src/function/trigonometry/atan2.js index ec0eb544d3..3864b30ff8 100644 --- a/src/function/trigonometry/atan2.js +++ b/src/function/trigonometry/atan2.js @@ -12,17 +12,16 @@ const dependencies = [ 'matrix', 'equalScalar', 'BigNumber', - 'DenseMatrix', - 'concat' + 'DenseMatrix' ] -export const createAtan2 = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, BigNumber, DenseMatrix, concat }) => { +export const createAtan2 = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, BigNumber, DenseMatrix }) => { const matAlgo02xDS0 = createMatAlgo02xDS0({ typed, equalScalar }) const matAlgo03xDSf = createMatAlgo03xDSf({ typed }) const matAlgo09xS0Sf = createMatAlgo09xS0Sf({ typed, equalScalar }) const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar }) const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix }) - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Calculate the inverse tangent function with two arguments, y/x. diff --git a/src/function/unit/to.js b/src/function/unit/to.js index e0705a5bd1..4058847919 100644 --- a/src/function/unit/to.js +++ b/src/function/unit/to.js @@ -4,12 +4,11 @@ import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgori const name = 'to' const dependencies = [ 'typed', - 'matrix', - 'concat' + 'matrix' ] -export const createTo = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, concat }) => { - const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat }) +export const createTo = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix }) => { + const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }) /** * Change the unit of a value. From cbcb6915f44bfe17b03f829b4ff415eca06c0e53 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:00:44 -0600 Subject: [PATCH 13/46] Include history of `add` --- src/function/arithmetic/add.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/function/arithmetic/add.js b/src/function/arithmetic/add.js index f61ba636c3..d3023e5100 100644 --- a/src/function/arithmetic/add.js +++ b/src/function/arithmetic/add.js @@ -53,10 +53,13 @@ export const createAdd = /* #__PURE__ */ factory( * * History: * - * v13 Handle bigint arguments + * v0.21.1 Fix not adding strings and matrices element wise + * v3.8. Allow more than two arguments + * v3.16.5 Fix passing three or more arrays or matrices. + * v5.0.3 Fix matrices with a `datatype` defined * v11.6 Support matrix broadcasting - * v3.8 Allow more than two arguments - * v0.0.2 Created + * v12.4.2 Fix type definitions to allow more than two arguments + * v14.5.3 Refine type definitions to not allow zero or one argument * * @param {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} x First value to add * @param {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} y Second value to add From b409734aa5dcff2c2d94ca5822f12c223501f827 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:04:10 -0600 Subject: [PATCH 14/46] Added `dotDivide` history --- src/function/arithmetic/dotDivide.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/function/arithmetic/dotDivide.js b/src/function/arithmetic/dotDivide.js index f97a64e961..16984613ae 100644 --- a/src/function/arithmetic/dotDivide.js +++ b/src/function/arithmetic/dotDivide.js @@ -46,6 +46,13 @@ export const createDotDivide = /* #__PURE__ */ factory(name, dependencies, ({ ty * * divide, multiply, dotMultiply * + * History: + * + * v0.23 Renamed from `edivide` + * v11.5.1 Improve type definitions + * v11.6 Support matrix broadcasting + * v14.0.0 Return a sparse matrix for sparse inputs + * * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Numerator * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} y Denominator * @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} Quotient, `x ./ y` From dd37a16f97249944bf7c569f014b0cc5d9ef6dbb Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:05:39 -0600 Subject: [PATCH 15/46] Added `dotMultiply` history --- src/function/arithmetic/dotMultiply.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/function/arithmetic/dotMultiply.js b/src/function/arithmetic/dotMultiply.js index 5552be8460..1eef1af5a1 100644 --- a/src/function/arithmetic/dotMultiply.js +++ b/src/function/arithmetic/dotMultiply.js @@ -40,6 +40,12 @@ export const createDotMultiply = /* #__PURE__ */ factory(name, dependencies, ({ * * multiply, divide, dotDivide * + * History: + * + * v0.23 Renamed from `emultiply` + * v11.5.1 Improve type definitions + * v11.6 Support matrix broadcasting + * * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Left hand value * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} y Right hand value * @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} Multiplication of `x` and `y` From 2ba17c4e0ddf6b8eae8acf4c1226140ee205d03c Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:07:23 -0600 Subject: [PATCH 16/46] Added history of `dotPow` --- src/function/arithmetic/dotPow.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/function/arithmetic/dotPow.js b/src/function/arithmetic/dotPow.js index 53d62bfbaa..f44d8cd89a 100644 --- a/src/function/arithmetic/dotPow.js +++ b/src/function/arithmetic/dotPow.js @@ -51,6 +51,13 @@ export const createDotPow = /* #__PURE__ */ factory(name, dependencies, ({ typed * * pow, sqrt, multiply * + * History: + * + * v0.23 Renamed from `epow` + * v11.5.1 Improve type definitions + * v11.6 Support matrix broadcasting + * v14.0.0 Return a sparse matrix for sparse inputs + * * @param {number | BigNumber | Complex | Unit | Array | Matrix} x The base * @param {number | BigNumber | Complex | Unit | Array | Matrix} y The exponent * @return {number | BigNumber | Complex | Unit | Array | Matrix} The value of `x` to the power `y` From 7851c6ce5743bd97f5043c1a30a4bd67f072266e Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:11:26 -0600 Subject: [PATCH 17/46] Added history for `gcd` --- src/function/arithmetic/gcd.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/function/arithmetic/gcd.js b/src/function/arithmetic/gcd.js index ffb9c09142..0cf1cbf152 100644 --- a/src/function/arithmetic/gcd.js +++ b/src/function/arithmetic/gcd.js @@ -56,6 +56,14 @@ export const createGcd = /* #__PURE__ */ factory(name, dependencies, ({ typed, m * * lcm, xgcd * + * History: + * + * v11.8 Improve type definitions + * v11.7 Accept arrays as input + * v11.6 Support matrix broadcasting + * v0.26 Implement BigNumber support + * v0.6 Created + * * @param {... number | BigNumber | Fraction | Array | Matrix} args Two or more integer numbers * @return {number | BigNumber | Fraction | Array | Matrix} The greatest common divisor */ From eeab2953935bbb12960492fbfce84bd83af84124 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:14:04 -0600 Subject: [PATCH 18/46] Added history for `lcm` --- src/function/arithmetic/lcm.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/function/arithmetic/lcm.js b/src/function/arithmetic/lcm.js index 8f16f0d54a..99e5d2af02 100644 --- a/src/function/arithmetic/lcm.js +++ b/src/function/arithmetic/lcm.js @@ -55,6 +55,14 @@ export const createLcm = /* #__PURE__ */ factory(name, dependencies, ({ typed, m * * gcd, xgcd * + * History: + * + * v0.6 Created + * v0.13 Fixed some edge cases + * v0.26 Implement BigNumber support + * v2.3 Support Fractions + * v11.6 Support matrix broadcasting + * * @param {... number | BigNumber | Array | Matrix} args Two or more integer numbers * @return {number | BigNumber | Array | Matrix} The least common multiple */ From e353386cb538c07a1558d15061df0be8faec1c2c Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:19:27 -0600 Subject: [PATCH 19/46] Added history for `mod` --- src/function/arithmetic/mod.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/function/arithmetic/mod.js b/src/function/arithmetic/mod.js index 3228f3656d..39e0ccb88c 100644 --- a/src/function/arithmetic/mod.js +++ b/src/function/arithmetic/mod.js @@ -59,10 +59,14 @@ export const createMod = /* #__PURE__ */ factory(name, dependencies, ({ typed, c * * History: * - * v13 Handle bigints - * v11.6 Support matrix broadcasting - * v2 Handle Fractions - * v0.2 Created + * v13 Handle bigints + * v12.1 Support negative divisors for BigNumber and Fraction + * v11.11.1 Fix round-off issues for some inputs + * v11.6 Support matrix broadcasting + * v7.3 Fix negative dividend for BigNumber and Fraction + * v2 Handle Fractions + * v0.14 Fixed non working operator + * v0.2 Created * * @param {number | BigNumber | bigint | Fraction | Array | Matrix} x Dividend * @param {number | BigNumber | bigint | Fraction | Array | Matrix} y Divisor From a5c7d8f8240c6476ac87194f49656535238a7a1a Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:24:45 -0600 Subject: [PATCH 20/46] Added history for `nthRoot` --- src/function/arithmetic/nthRoot.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/function/arithmetic/nthRoot.js b/src/function/arithmetic/nthRoot.js index 956d519a98..5ed0053f91 100644 --- a/src/function/arithmetic/nthRoot.js +++ b/src/function/arithmetic/nthRoot.js @@ -47,9 +47,12 @@ export const createNthRoot = /* #__PURE__ */ factory(name, dependencies, ({ type * * History: * - * v11.6 Support matrix broadcasting - * v2 Handle Complex - * v1.1 Created + * v11.6 Support matrix broadcasting + * v5.0.0 Improve consistency with sqrt and pow + * v3.1.1 Fix negative roots of zero + * v2.4.1 Fix negative values like `nthRoot(-2, 3)` + * v2 Handle Complex + * v1.1 Created * * @param {number | BigNumber | Array | Matrix | Complex} a * Value for which to calculate the nth root From 471b9a0d9ad823cd421264b2be2038cb883d7351 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:25:07 -0600 Subject: [PATCH 21/46] Added history for `nthRoot` --- src/function/arithmetic/nthRoot.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/function/arithmetic/nthRoot.js b/src/function/arithmetic/nthRoot.js index 5ed0053f91..615851074a 100644 --- a/src/function/arithmetic/nthRoot.js +++ b/src/function/arithmetic/nthRoot.js @@ -48,6 +48,7 @@ export const createNthRoot = /* #__PURE__ */ factory(name, dependencies, ({ type * History: * * v11.6 Support matrix broadcasting + * v10.5.1 Improve type definitions * v5.0.0 Improve consistency with sqrt and pow * v3.1.1 Fix negative roots of zero * v2.4.1 Fix negative values like `nthRoot(-2, 3)` From 58fbad7e543cb0a006ae49b8f0fe373221795ccd Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:28:04 -0600 Subject: [PATCH 22/46] Added history for `subtract` --- src/function/arithmetic/subtract.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/function/arithmetic/subtract.js b/src/function/arithmetic/subtract.js index b662dcf3c5..59abdbcce2 100644 --- a/src/function/arithmetic/subtract.js +++ b/src/function/arithmetic/subtract.js @@ -51,6 +51,12 @@ export const createSubtract = /* #__PURE__ */ factory(name, dependencies, ({ typ * * add * + * History: + * + * v11.6 Support matrix broadcasting + * v5.0.3 Fix matrices with a `datatype` defined + * v0.8.2 Fixed a bug when subtracting a complex number from a real number + * * @param {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} x Initial value * @param {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} y Value to subtract from `x` * @return {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} Subtraction of `x` and `y` From 19b3bc2e6da21ae00f2d1715749c77cb3ee0c0ff Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:29:02 -0600 Subject: [PATCH 23/46] Added history for `bitAnd` --- src/function/bitwise/bitAnd.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/function/bitwise/bitAnd.js b/src/function/bitwise/bitAnd.js index 0669c659e2..aa79bf3834 100644 --- a/src/function/bitwise/bitAnd.js +++ b/src/function/bitwise/bitAnd.js @@ -37,6 +37,11 @@ export const createBitAnd = /* #__PURE__ */ factory(name, dependencies, ({ typed * * bitNot, bitOr, bitXor, leftShift, rightArithShift, rightLogShift * + * History: + * + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Array | Matrix} x First value to and * @param {number | BigNumber | bigint | Array | Matrix} y Second value to and * @return {number | BigNumber | bigint | Array | Matrix} AND of `x` and `y` From 6992600658c673ba9817c7f6ef284934d0a3e20f Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:30:12 -0600 Subject: [PATCH 24/46] Added history for `bitOr` and `bitXor` --- src/function/bitwise/bitOr.js | 5 +++++ src/function/bitwise/bitXor.js | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/function/bitwise/bitOr.js b/src/function/bitwise/bitOr.js index 969fd8c218..97fcf5d4f3 100644 --- a/src/function/bitwise/bitOr.js +++ b/src/function/bitwise/bitOr.js @@ -39,6 +39,11 @@ export const createBitOr = /* #__PURE__ */ factory(name, dependencies, ({ typed, * * bitAnd, bitNot, bitXor, leftShift, rightArithShift, rightLogShift * + * History: + * + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Array | Matrix} x First value to or * @param {number | BigNumber | bigint | Array | Matrix} y Second value to or * @return {number | BigNumber | bigint | Array | Matrix} OR of `x` and `y` diff --git a/src/function/bitwise/bitXor.js b/src/function/bitwise/bitXor.js index f9a6f47456..cae43dba0d 100644 --- a/src/function/bitwise/bitXor.js +++ b/src/function/bitwise/bitXor.js @@ -38,6 +38,12 @@ export const createBitXor = /* #__PURE__ */ factory(name, dependencies, ({ typed * * bitAnd, bitNot, bitOr, leftShift, rightArithShift, rightLogShift * + * History: + * + * v14.0.0 Return a sparse matrix for sparse inputs + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Array | Matrix} x First value to xor * @param {number | BigNumber | bigint | Array | Matrix} y Second value to xor * @return {number | BigNumber | bigint | Array | Matrix} XOR of `x` and `y` From f8a06597eb8293f166286b6d903fd57430861d0e Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:32:37 -0600 Subject: [PATCH 25/46] Added history to `leftShift`, `rightArithShift` and `rightLogShift` --- src/function/bitwise/leftShift.js | 5 +++++ src/function/bitwise/rightArithShift.js | 5 +++++ src/function/bitwise/rightLogShift.js | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/src/function/bitwise/leftShift.js b/src/function/bitwise/leftShift.js index 01b46e640f..c7c49030b8 100644 --- a/src/function/bitwise/leftShift.js +++ b/src/function/bitwise/leftShift.js @@ -49,6 +49,11 @@ export const createLeftShift = /* #__PURE__ */ factory(name, dependencies, ({ ty * * leftShift, bitNot, bitOr, bitXor, rightArithShift, rightLogShift * + * History: + * + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Array | Matrix} x Value to be shifted * @param {number | BigNumber | bigint} y Amount of shifts * @return {number | BigNumber | bigint | Array | Matrix} `x` shifted left `y` times diff --git a/src/function/bitwise/rightArithShift.js b/src/function/bitwise/rightArithShift.js index 3a299e262a..19df23b5a4 100644 --- a/src/function/bitwise/rightArithShift.js +++ b/src/function/bitwise/rightArithShift.js @@ -49,6 +49,11 @@ export const createRightArithShift = /* #__PURE__ */ factory(name, dependencies, * * bitAnd, bitNot, bitOr, bitXor, rightArithShift, rightLogShift * + * History: + * + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Array | Matrix} x Value to be shifted * @param {number | BigNumber | bigint} y Amount of shifts * @return {number | BigNumber | bigint | Array | Matrix} `x` zero-filled shifted right `y` times diff --git a/src/function/bitwise/rightLogShift.js b/src/function/bitwise/rightLogShift.js index bbd66d5397..2cfa3b915b 100644 --- a/src/function/bitwise/rightLogShift.js +++ b/src/function/bitwise/rightLogShift.js @@ -48,6 +48,11 @@ export const createRightLogShift = /* #__PURE__ */ factory(name, dependencies, ( * * bitAnd, bitNot, bitOr, bitXor, leftShift, rightLogShift * + * History: + * + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | Array | Matrix} x Value to be shifted * @param {number} y Amount of shifts * @return {number | Array | Matrix} `x` zero-filled shifted right `y` times From ac4bf47c44be10b7b9f395366b3d5fd998fdebc5 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:36:16 -0600 Subject: [PATCH 26/46] Added history for `and`, `or` and `xor` --- src/function/logical/and.js | 5 +++++ src/function/logical/or.js | 6 ++++++ src/function/logical/xor.js | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/src/function/logical/and.js b/src/function/logical/and.js index ce15688d38..841c54f751 100644 --- a/src/function/logical/and.js +++ b/src/function/logical/and.js @@ -45,6 +45,11 @@ export const createAnd = /* #__PURE__ */ factory(name, dependencies, ({ typed, m * * not, or, xor * + * History: + *. v12.2 Lazy evaluation + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Complex | Unit | Array | Matrix} x First value to check * @param {number | BigNumber | bigint | Complex | Unit | Array | Matrix} y Second value to check * @return {boolean | Array | Matrix} diff --git a/src/function/logical/or.js b/src/function/logical/or.js index 0a8c7ad426..e89cc92104 100644 --- a/src/function/logical/or.js +++ b/src/function/logical/or.js @@ -42,6 +42,12 @@ export const createOr = /* #__PURE__ */ factory(name, dependencies, ({ typed, ma * * and, not, xor * + * History: + * + * v12.2 Lazy evaluation + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Complex | Unit | Array | Matrix} x First value to check * @param {number | BigNumber | bigint | Complex | Unit | Array | Matrix} y Second value to check * @return {boolean | Array | Matrix} diff --git a/src/function/logical/xor.js b/src/function/logical/xor.js index 20729e1fc1..5f924a4eaa 100644 --- a/src/function/logical/xor.js +++ b/src/function/logical/xor.js @@ -42,6 +42,12 @@ export const createXor = /* #__PURE__ */ factory(name, dependencies, ({ typed, m * * and, not, or * + * History: + * + * v14.0.0 Return a sparse matrix for sparse inputs + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Complex | Unit | Array | Matrix} x First value to check * @param {number | BigNumber | bigint | Complex | Unit | Array | Matrix} y Second value to check * @return {boolean | Array | Matrix} From ffd1e727ce5c016ddf49aa01e22eaa7e245fb41c Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:42:10 -0600 Subject: [PATCH 27/46] Added history of `compare` --- src/function/relational/compare.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/function/relational/compare.js b/src/function/relational/compare.js index 41d8cc9fd8..70a5093b27 100644 --- a/src/function/relational/compare.js +++ b/src/function/relational/compare.js @@ -61,8 +61,9 @@ export const createCompare = /* #__PURE__ */ factory(name, dependencies, ({ type * * v0.19 Created * v4 Changed to compare strings by numerical value + * v11.6 Support matrix broadcasting * v13 Change to use separate relative and absolute tolerances - * + * * @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: From e565adab4efabb9e17736f4990160511190e9a9f Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:48:15 -0600 Subject: [PATCH 28/46] History for `equal` --- src/function/relational/equal.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/function/relational/equal.js b/src/function/relational/equal.js index 677c875bc0..08444743e5 100644 --- a/src/function/relational/equal.js +++ b/src/function/relational/equal.js @@ -64,9 +64,10 @@ export const createEqual = /* #__PURE__ */ factory(name, dependencies, ({ typed, * * History: * - * v13 Handle bigints + * v14 Return a sparse matrix for sparse inputs + * v13 Handle bigints and change to use separate relative and absolute tolerances * v11.6 Support matrix broadcasting - * v4 Compare strings by their numerical value + * v4 Compare strings by their numerical value and implemented nearly equal comparison * v0.24 Handle `null` and `undefined` * v0.23 Compare collections elementwise * v0.20 Compare floating-point numbers within epsilon, allowing roundoff From 76aab1a59131c316537f55d528122a19109ebca2 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:50:45 -0600 Subject: [PATCH 29/46] History for `larger` --- src/function/relational/larger.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/function/relational/larger.js b/src/function/relational/larger.js index 921ebee787..71b3439c17 100644 --- a/src/function/relational/larger.js +++ b/src/function/relational/larger.js @@ -51,6 +51,15 @@ export const createLarger = /* #__PURE__ */ factory(name, dependencies, ({ typed * * equal, unequal, smaller, smallerEq, largerEq, compare * + * History: + * + * v14.1 Support bigints + * v14 Return a sparse matrix for sparse inputs + * v11.6 Support matrix broadcasting + * v4 Compare strings by their numerical value and implemented nearly equal comparison + * v3 Use nearly-equal comparison for BigNumbers + * v0.15 Removed support for complex numbers + * * @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 From e71bb52e4655edc2eb8b6761ab09564fa357f2e5 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:59:06 -0600 Subject: [PATCH 30/46] History for `largerEq` --- src/function/relational/largerEq.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/function/relational/largerEq.js b/src/function/relational/largerEq.js index 66c3d3879e..b97ccbea49 100644 --- a/src/function/relational/largerEq.js +++ b/src/function/relational/largerEq.js @@ -46,6 +46,15 @@ export const createLargerEq = /* #__PURE__ */ factory(name, dependencies, ({ typ * * equal, unequal, smaller, smallerEq, larger, compare * + * History: + * + * v14.0.0 Return a sparse matrix for sparse inputs + * v11.6 Support matrix broadcasting + * v4 Compare strings by their numerical value and implemented nearly equal comparison + * v3 Use nearly-equal comparison for BigNumbers + * v0.15 Removed support for complex numbers + * v0.2 Created + * * @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 From 1fab22aa762e38f2d4aaefd248b4bb73a356fc93 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 19:59:22 -0600 Subject: [PATCH 31/46] history for `largerEq` --- src/function/relational/largerEq.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/function/relational/largerEq.js b/src/function/relational/largerEq.js index b97ccbea49..d31bbec737 100644 --- a/src/function/relational/largerEq.js +++ b/src/function/relational/largerEq.js @@ -52,6 +52,7 @@ export const createLargerEq = /* #__PURE__ */ factory(name, dependencies, ({ typ * v11.6 Support matrix broadcasting * v4 Compare strings by their numerical value and implemented nearly equal comparison * v3 Use nearly-equal comparison for BigNumbers + * 0.23 Renamed from `largereq`to `largerEq` * v0.15 Removed support for complex numbers * v0.2 Created * From 1e62b6c642e44e2557ce4de9e4a04172b6afc5ff Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 20:01:20 -0600 Subject: [PATCH 32/46] Add history to `smaller` --- src/function/relational/smaller.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/function/relational/smaller.js b/src/function/relational/smaller.js index 96839708ab..8dbf011211 100644 --- a/src/function/relational/smaller.js +++ b/src/function/relational/smaller.js @@ -51,6 +51,14 @@ export const createSmaller = /* #__PURE__ */ factory(name, dependencies, ({ type * * equal, unequal, smallerEq, smaller, smallerEq, compare * + * History: + * + * v14.1 Support bigints + * v14 Return a sparse matrix for sparse inputs + * v11.6 Support matrix broadcasting + * v4 Compare strings by their numerical value and implemented nearly equal comparison + * v3 Use nearly-equal comparison for BigNumbers + * * @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 From 4362b6e7d6f042dba187da5299b72cf6d68f27d3 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 20:03:25 -0600 Subject: [PATCH 33/46] History for `smallerEq` --- src/function/relational/smallerEq.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/function/relational/smallerEq.js b/src/function/relational/smallerEq.js index 7494e2ea0e..0cc5af0081 100644 --- a/src/function/relational/smallerEq.js +++ b/src/function/relational/smallerEq.js @@ -46,6 +46,14 @@ export const createSmallerEq = /* #__PURE__ */ factory(name, dependencies, ({ ty * * equal, unequal, smaller, larger, largerEq, compare * + * History: + * + * v14.0.0 Return a sparse matrix for sparse inputs + * v11.6 Support matrix broadcasting + * v4 Compare strings by their numerical value and implemented nearly equal comparison + * v0.23 Renamed from `smalleq`to `smallerEq` + * v0.15 Removed support for complex numbers + * * @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 From 7a58f8417673189d29103c1d9db1f844d0d36a36 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 20:04:15 -0600 Subject: [PATCH 34/46] History for `unequal` --- src/function/relational/unequal.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/function/relational/unequal.js b/src/function/relational/unequal.js index c084107ce7..9d3b2f6a1c 100644 --- a/src/function/relational/unequal.js +++ b/src/function/relational/unequal.js @@ -64,11 +64,12 @@ export const createUnequal = /* #__PURE__ */ factory(name, dependencies, ({ type * * History: * - * v13 Handle bigints - * v11.6 Support matrix broadcasting - * v4 Compare strings by their numeric values - * v0.24 Handle `null` and `undefined` - * v0.2 Created + * v14.0.0 Return a sparse matrix for sparse inputs + * v13 Handle bigints + * v11.6 Support matrix broadcasting + * v4 Compare strings by their numeric values + * v0.24 Handle `null` and `undefined` + * v0.2 Created * * @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 From c7119db233ac8ed617cc15e6d812ebde20903cd7 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 20:05:41 -0600 Subject: [PATCH 35/46] History for `atan2` --- src/function/trigonometry/atan2.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/function/trigonometry/atan2.js b/src/function/trigonometry/atan2.js index 3864b30ff8..899cc8de73 100644 --- a/src/function/trigonometry/atan2.js +++ b/src/function/trigonometry/atan2.js @@ -49,6 +49,11 @@ export const createAtan2 = /* #__PURE__ */ factory(name, dependencies, ({ typed, * * tan, atan, sin, cos * + * History: + * + * v11.6 Support matrix broadcasting + * v1.5 Support BigNumber arguments + * * @param {number | Array | Matrix} y Second dimension * @param {number | Array | Matrix} x First dimension * @return {number | Array | Matrix} Four-quadrant inverse tangent From f12705402ccd2a295b544576769d7901c8d4f9ad Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 20:07:16 -0600 Subject: [PATCH 36/46] History for `to` --- src/function/unit/to.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/function/unit/to.js b/src/function/unit/to.js index 4058847919..5990114963 100644 --- a/src/function/unit/to.js +++ b/src/function/unit/to.js @@ -29,6 +29,12 @@ export const createTo = /* #__PURE__ */ factory(name, dependencies, ({ typed, ma * * unit * + * History: + * + * v11.6 Support matrix broadcasting + * v2.2 Fix simplified unit conversions + * v0.18 Renamed from `in` to `to` + * * @param {Unit | Array | Matrix} x The unit to be converted. * @param {Unit | Array | Matrix} unit New unit. Can be a string like "cm" * or a unit without value. From 9c5e98be761d1837ec40f8ec2e749610504fb791 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 23 Feb 2026 20:10:15 -0600 Subject: [PATCH 37/46] Added some missing "`" --- HISTORY.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index e21b3e8bad..de1c9d6c01 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1679,7 +1679,7 @@ Breaking changes: - Dropped support for (non-primitive) instances of `Number`, `Boolean`, and `String` from functions `clone` and `typeof`. - Dropped official support for IE9 (probably still works, but it's not tested). -- Fixed #851: More consistent behavior of sqrt, nthRoot, and pow. +- Fixed #851: More consistent behavior of `sqrt`, `nthRoot`, and `pow`. Thanks @dakotablair. - Fixed #1103: Calling `toTex` on node that contains `derivative` causing an exception. Thanks @joelhoover. @@ -2512,7 +2512,7 @@ Non breaking changes: ## 2015-07-12, version 1.7.1 -- Fixed #397: Inaccuracies in nthRoot for very large values, and wrong results +- Fixed #397: Inaccuracies in `nthRoot` for very large values, and wrong results for very small values. (backported from v2) - Fixed #405: Parser throws error when defining a function in a multiline expression. @@ -3053,7 +3053,7 @@ Non breaking changes: - Extended the import function and some other minor improvements. - Fixed a bug in merging one dimensional vectors into a matrix. -- Fixed a bug in function subtract, when subtracting a complex number from a +- Fixed a bug in function `subtract`, when subtracting a complex number from a real number. ## 2013-05-10, version 0.8.1 From a07bfa47d63e1bc5b15d5fabe7fbf468638830fe Mon Sep 17 00:00:00 2001 From: David Contreras Date: Tue, 24 Feb 2026 14:13:13 +0000 Subject: [PATCH 38/46] Format --- package-lock.json | 17 +++++++++++++++++ src/function/relational/compare.js | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 2637b244f6..39af161ed7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -117,6 +117,7 @@ "integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.29.0", "@babel/generator": "^7.29.0", @@ -2302,6 +2303,7 @@ "integrity": "sha512-FXx2pKgId/WyYo2jXw63kk7/+TY7u7AziEJxJAnSFzHlqTAS3Ync6SvgYAN/k4/PQpnnVuzoMuVnByKK2qp0ag==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@types/estree": "*", "@types/json-schema": "*" @@ -2366,6 +2368,7 @@ "integrity": "sha512-ixiWrCSRi33uqBMRuICcKECW7rtgY43TbsHDpM2XK7lXispd48opW+0IXrBVxv9NMhaz/Ue9kyj6r3NTVyXm8A==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "undici-types": "~6.20.0" } @@ -2415,6 +2418,7 @@ "integrity": "sha512-4z2nCSBfVIMnbuu8uinj+f0o4qOeggYJLbjpPHka3KH1om7e+H9yLKTYgksTaHcGco+NClhhY2vyO3HsMH1RGw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.55.0", "@typescript-eslint/types": "8.55.0", @@ -2828,6 +2832,7 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -3812,6 +3817,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.9.0", "caniuse-lite": "^1.0.30001759", @@ -5262,6 +5268,7 @@ "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", @@ -5347,6 +5354,7 @@ "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", "dev": true, "license": "MIT", + "peer": true, "bin": { "eslint-config-prettier": "bin/cli.js" }, @@ -5462,6 +5470,7 @@ "integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@rtsao/scc": "^1.1.0", "array-includes": "^3.1.9", @@ -5577,6 +5586,7 @@ "integrity": "sha512-6TyDmZ1HXoFQXnhCTUjVFULReoBPOAjpuiKELMkeP40yffI/1ZRO+d9ug/VC6fqISo2WkuIBk3cvuRPALaWlOQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "builtins": "^5.0.1", @@ -5690,6 +5700,7 @@ "integrity": "sha512-57Zzfw8G6+Gq7axm2Pdo3gW/Rx3h9Yywgn61uE/3elTCOePEHVrn2i5CdfBwA1BLK0Q0WqctICIUSqXZW/VprQ==", "dev": true, "license": "ISC", + "peer": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, @@ -8366,6 +8377,7 @@ "integrity": "sha512-LrtUxbdvt1gOpo3gxG+VAJlJAEMhbWlM4YrFQgql98FwF7+K8K12LYO4hnDdUkNjeztYrOXEMqgTajSWgmtI/w==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@colors/colors": "1.5.0", "body-parser": "^1.19.0", @@ -10324,6 +10336,7 @@ "integrity": "sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "prettier": "bin/prettier.cjs" }, @@ -11018,6 +11031,7 @@ "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", @@ -12079,6 +12093,7 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -12420,6 +12435,7 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -12994,6 +13010,7 @@ "integrity": "sha512-gX/dMkRQc7QOMzgTe6KsYFM7DxeIONQSui1s0n/0xht36HvrgbxtM1xBlgx596NbpHuQU8P7QpKwrZYwUX48nw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@types/eslint-scope": "^3.7.7", "@types/estree": "^1.0.8", diff --git a/src/function/relational/compare.js b/src/function/relational/compare.js index 70a5093b27..300034674f 100644 --- a/src/function/relational/compare.js +++ b/src/function/relational/compare.js @@ -63,7 +63,7 @@ export const createCompare = /* #__PURE__ */ factory(name, dependencies, ({ type * v4 Changed to compare strings by numerical value * v11.6 Support matrix broadcasting * v13 Change to use separate relative and absolute tolerances - * + * * @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: From 493de05bf2556226880ee9bee61ad53c92132302 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Tue, 24 Feb 2026 17:26:32 +0000 Subject: [PATCH 39/46] Changed description from "Iterates" to "Deeply iterates" --- src/type/matrix/utils/matAlgo15xAs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/type/matrix/utils/matAlgo15xAs.js b/src/type/matrix/utils/matAlgo15xAs.js index 61c464b852..728822066e 100644 --- a/src/type/matrix/utils/matAlgo15xAs.js +++ b/src/type/matrix/utils/matAlgo15xAs.js @@ -6,7 +6,7 @@ const dependencies = [] export const createMatAlgo15xAs = /* #__PURE__ */ factory(name, dependencies, () => { /** - * Iterates over Array items and invokes the callback function f(Aij..z, b). + * Deeply iterates over Array items and invokes the callback function f(Aij..z, b). * Callback function invoked once for each item. * * C(i,j,...z) = f(Aij..z, b) From 0563b85a8d7653caef89e495fbbb040a3684658e Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Thu, 5 Mar 2026 19:03:23 +0100 Subject: [PATCH 40/46] chore: make History format consistent; add test per #3537. --- src/expression/parse.js | 24 ++++++++++----------- src/function/arithmetic/add.js | 8 ++----- src/function/arithmetic/dotDivide.js | 13 ++++++----- src/function/arithmetic/dotMultiply.js | 11 +++++----- src/function/arithmetic/dotPow.js | 13 ++++++----- src/function/arithmetic/gcd.js | 15 ++++++------- src/function/arithmetic/lcm.js | 15 ++++++------- src/function/arithmetic/mod.js | 13 +++++------ src/function/arithmetic/nthRoot.js | 13 ++++++----- src/function/arithmetic/subtract.js | 12 +++++------ src/function/bitwise/bitAnd.js | 10 ++++----- src/function/bitwise/bitOr.js | 10 ++++----- src/function/bitwise/bitXor.js | 12 +++++------ src/function/bitwise/leftShift.js | 10 ++++----- src/function/bitwise/rightArithShift.js | 10 ++++----- src/function/bitwise/rightLogShift.js | 10 ++++----- src/function/logical/and.js | 10 ++++----- src/function/logical/or.js | 12 +++++------ src/function/logical/xor.js | 12 +++++------ src/function/relational/compare.js | 6 +++--- src/function/relational/equal.js | 4 ++-- src/function/relational/larger.js | 18 ++++++++-------- src/function/relational/largerEq.js | 20 ++++++++--------- src/function/relational/smaller.js | 16 +++++++------- src/function/relational/smallerEq.js | 16 +++++++------- src/function/relational/unequal.js | 12 +++++------ src/function/unit/to.js | 12 +++++------ src/type/matrix/utils/matAlgo15xAs.js | 5 +++-- test/unit-tests/function/matrix/map.test.js | 7 ++++++ 29 files changed, 172 insertions(+), 177 deletions(-) diff --git a/src/expression/parse.js b/src/expression/parse.js index c300b8cf98..65de3eebba 100644 --- a/src/expression/parse.js +++ b/src/expression/parse.js @@ -82,20 +82,20 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({ * * History: * - * v0.9 Created - * v0.13 Switched to one-based indices - * v0.14 Added `[1,2;3,4]` notation for matrices - * v0.18 Dropped the `function` keyword - * v0.20 Added ternary conditional - * v0.27 Allow multi-line expressions; allow functions that receive - * unevaluated parameters (`rawArgs`) + * v15.1 Add optional chaining operator + * v14.8 Add nullish coalescing operator + * v12.4 Allow trailing commas in matrices + * v9.5 Support for calculations with percentages + * v7.3 Supported binary, octal, and hexadecimal notation * v3 Add object notation; allow assignments internal to other * expressions - * v7.3 Supported binary, octal, and hexadecimal notation - * v9.5 Support for calculations with percentages - * v12.4 Allow trailing commas in matrices - * v14.8 Add nullish coalescing operator - * v15.1 Add optional chaining operator + * v0.27 Allow multi-line expressions; allow functions that receive + * unevaluated parameters (`rawArgs`) + * v0.20 Added ternary conditional + * v0.18 Dropped the `function` keyword + * v0.14 Added `[1,2;3,4]` notation for matrices + * v0.13 Switched to one-based indices + * v0.9 Created * * @param {string | string[] | Matrix} expr Expression to be parsed * @param {{nodes: Object}} [options] Available options: diff --git a/src/function/arithmetic/add.js b/src/function/arithmetic/add.js index d3023e5100..c2c5fdbc53 100644 --- a/src/function/arithmetic/add.js +++ b/src/function/arithmetic/add.js @@ -53,13 +53,9 @@ export const createAdd = /* #__PURE__ */ factory( * * History: * - * v0.21.1 Fix not adding strings and matrices element wise - * v3.8. Allow more than two arguments - * v3.16.5 Fix passing three or more arrays or matrices. - * v5.0.3 Fix matrices with a `datatype` defined * v11.6 Support matrix broadcasting - * v12.4.2 Fix type definitions to allow more than two arguments - * v14.5.3 Refine type definitions to not allow zero or one argument + * v5.0.3 Support matrices with a `datatype` defined + * v3.8 Allow more than two arguments * * @param {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} x First value to add * @param {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} y Second value to add diff --git a/src/function/arithmetic/dotDivide.js b/src/function/arithmetic/dotDivide.js index 16984613ae..f071de70d7 100644 --- a/src/function/arithmetic/dotDivide.js +++ b/src/function/arithmetic/dotDivide.js @@ -46,13 +46,12 @@ export const createDotDivide = /* #__PURE__ */ factory(name, dependencies, ({ ty * * divide, multiply, dotMultiply * - * History: - * - * v0.23 Renamed from `edivide` - * v11.5.1 Improve type definitions - * v11.6 Support matrix broadcasting - * v14.0.0 Return a sparse matrix for sparse inputs - * + * History: + * + * v14.0.0 Return a sparse matrix for sparse inputs + * v11.6 Support matrix broadcasting + * v0.23 Renamed from `edivide` + * * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Numerator * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} y Denominator * @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} Quotient, `x ./ y` diff --git a/src/function/arithmetic/dotMultiply.js b/src/function/arithmetic/dotMultiply.js index 1eef1af5a1..6d6faa109d 100644 --- a/src/function/arithmetic/dotMultiply.js +++ b/src/function/arithmetic/dotMultiply.js @@ -40,12 +40,11 @@ export const createDotMultiply = /* #__PURE__ */ factory(name, dependencies, ({ * * multiply, divide, dotDivide * - * History: - * - * v0.23 Renamed from `emultiply` - * v11.5.1 Improve type definitions - * v11.6 Support matrix broadcasting - * + * History: + * + * v11.6 Support matrix broadcasting + * v0.23 Renamed from `emultiply` + * * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Left hand value * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} y Right hand value * @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} Multiplication of `x` and `y` diff --git a/src/function/arithmetic/dotPow.js b/src/function/arithmetic/dotPow.js index f44d8cd89a..91c7227ce8 100644 --- a/src/function/arithmetic/dotPow.js +++ b/src/function/arithmetic/dotPow.js @@ -51,13 +51,12 @@ export const createDotPow = /* #__PURE__ */ factory(name, dependencies, ({ typed * * pow, sqrt, multiply * - * History: - * - * v0.23 Renamed from `epow` - * v11.5.1 Improve type definitions - * v11.6 Support matrix broadcasting - * v14.0.0 Return a sparse matrix for sparse inputs - * + * History: + * + * v14.0.0 Return a sparse matrix for sparse inputs + * v11.6 Support matrix broadcasting + * v0.23 Renamed from `epow` + * * @param {number | BigNumber | Complex | Unit | Array | Matrix} x The base * @param {number | BigNumber | Complex | Unit | Array | Matrix} y The exponent * @return {number | BigNumber | Complex | Unit | Array | Matrix} The value of `x` to the power `y` diff --git a/src/function/arithmetic/gcd.js b/src/function/arithmetic/gcd.js index 0cf1cbf152..296ab6dc67 100644 --- a/src/function/arithmetic/gcd.js +++ b/src/function/arithmetic/gcd.js @@ -56,14 +56,13 @@ export const createGcd = /* #__PURE__ */ factory(name, dependencies, ({ typed, m * * lcm, xgcd * - * History: - * - * v11.8 Improve type definitions - * v11.7 Accept arrays as input - * v11.6 Support matrix broadcasting - * v0.26 Implement BigNumber support - * v0.6 Created - * + * History: + * + * v11.7 Accept arrays as input + * v11.6 Support matrix broadcasting + * v0.26 Implement BigNumber support + * v0.6 Created + * * @param {... number | BigNumber | Fraction | Array | Matrix} args Two or more integer numbers * @return {number | BigNumber | Fraction | Array | Matrix} The greatest common divisor */ diff --git a/src/function/arithmetic/lcm.js b/src/function/arithmetic/lcm.js index 99e5d2af02..9588dcdd98 100644 --- a/src/function/arithmetic/lcm.js +++ b/src/function/arithmetic/lcm.js @@ -55,14 +55,13 @@ export const createLcm = /* #__PURE__ */ factory(name, dependencies, ({ typed, m * * gcd, xgcd * - * History: - * - * v0.6 Created - * v0.13 Fixed some edge cases - * v0.26 Implement BigNumber support - * v2.3 Support Fractions - * v11.6 Support matrix broadcasting - * + * History: + * + * v11.6 Support matrix broadcasting + * v2.3 Support Fractions + * v0.26 Implement BigNumber support + * v0.6 Created + * * @param {... number | BigNumber | Array | Matrix} args Two or more integer numbers * @return {number | BigNumber | Array | Matrix} The least common multiple */ diff --git a/src/function/arithmetic/mod.js b/src/function/arithmetic/mod.js index 39e0ccb88c..c1801cfe7d 100644 --- a/src/function/arithmetic/mod.js +++ b/src/function/arithmetic/mod.js @@ -59,14 +59,11 @@ export const createMod = /* #__PURE__ */ factory(name, dependencies, ({ typed, c * * History: * - * v13 Handle bigints - * v12.1 Support negative divisors for BigNumber and Fraction - * v11.11.1 Fix round-off issues for some inputs - * v11.6 Support matrix broadcasting - * v7.3 Fix negative dividend for BigNumber and Fraction - * v2 Handle Fractions - * v0.14 Fixed non working operator - * v0.2 Created + * v13 Handle bigints + * v12.1 Support negative divisors for BigNumber and Fraction + * v11.6 Support matrix broadcasting + * v2 Handle Fractions + * v0.2 Created * * @param {number | BigNumber | bigint | Fraction | Array | Matrix} x Dividend * @param {number | BigNumber | bigint | Fraction | Array | Matrix} y Divisor diff --git a/src/function/arithmetic/nthRoot.js b/src/function/arithmetic/nthRoot.js index 615851074a..69426a0889 100644 --- a/src/function/arithmetic/nthRoot.js +++ b/src/function/arithmetic/nthRoot.js @@ -47,13 +47,12 @@ export const createNthRoot = /* #__PURE__ */ factory(name, dependencies, ({ type * * History: * - * v11.6 Support matrix broadcasting - * v10.5.1 Improve type definitions - * v5.0.0 Improve consistency with sqrt and pow - * v3.1.1 Fix negative roots of zero - * v2.4.1 Fix negative values like `nthRoot(-2, 3)` - * v2 Handle Complex - * v1.1 Created + * v11.6 Support matrix broadcasting + * v5.0.0 Improve consistency with sqrt and pow + * v3.1.1 Support negative roots of zero + * v2.4.1 Support negative values like `nthRoot(-2, 3)` + * v2 Support roots of Complex + * v1.1 Created * * @param {number | BigNumber | Array | Matrix | Complex} a * Value for which to calculate the nth root diff --git a/src/function/arithmetic/subtract.js b/src/function/arithmetic/subtract.js index 59abdbcce2..0ee9303bc1 100644 --- a/src/function/arithmetic/subtract.js +++ b/src/function/arithmetic/subtract.js @@ -51,12 +51,12 @@ export const createSubtract = /* #__PURE__ */ factory(name, dependencies, ({ typ * * add * - * History: - * - * v11.6 Support matrix broadcasting - * v5.0.3 Fix matrices with a `datatype` defined - * v0.8.2 Fixed a bug when subtracting a complex number from a real number - * + * History: + * + * v11.6 Support matrix broadcasting + * v5.0.3 Support matrices with a `datatype` defined + * v0.8.2 Support complex - real mixed subtraction + * * @param {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} x Initial value * @param {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} y Value to subtract from `x` * @return {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} Subtraction of `x` and `y` diff --git a/src/function/bitwise/bitAnd.js b/src/function/bitwise/bitAnd.js index aa79bf3834..6a07dfeef5 100644 --- a/src/function/bitwise/bitAnd.js +++ b/src/function/bitwise/bitAnd.js @@ -37,11 +37,11 @@ export const createBitAnd = /* #__PURE__ */ factory(name, dependencies, ({ typed * * bitNot, bitOr, bitXor, leftShift, rightArithShift, rightLogShift * - * History: - * - * v11.6 Support matrix broadcasting - * v1.2 Created - * + * History: + * + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Array | Matrix} x First value to and * @param {number | BigNumber | bigint | Array | Matrix} y Second value to and * @return {number | BigNumber | bigint | Array | Matrix} AND of `x` and `y` diff --git a/src/function/bitwise/bitOr.js b/src/function/bitwise/bitOr.js index 97fcf5d4f3..130abb207b 100644 --- a/src/function/bitwise/bitOr.js +++ b/src/function/bitwise/bitOr.js @@ -39,11 +39,11 @@ export const createBitOr = /* #__PURE__ */ factory(name, dependencies, ({ typed, * * bitAnd, bitNot, bitXor, leftShift, rightArithShift, rightLogShift * - * History: - * - * v11.6 Support matrix broadcasting - * v1.2 Created - * + * History: + * + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Array | Matrix} x First value to or * @param {number | BigNumber | bigint | Array | Matrix} y Second value to or * @return {number | BigNumber | bigint | Array | Matrix} OR of `x` and `y` diff --git a/src/function/bitwise/bitXor.js b/src/function/bitwise/bitXor.js index cae43dba0d..29aeb59c1a 100644 --- a/src/function/bitwise/bitXor.js +++ b/src/function/bitwise/bitXor.js @@ -38,12 +38,12 @@ export const createBitXor = /* #__PURE__ */ factory(name, dependencies, ({ typed * * bitAnd, bitNot, bitOr, leftShift, rightArithShift, rightLogShift * - * History: - * - * v14.0.0 Return a sparse matrix for sparse inputs - * v11.6 Support matrix broadcasting - * v1.2 Created - * + * History: + * + * v14.0.0 Return a sparse matrix for sparse inputs + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Array | Matrix} x First value to xor * @param {number | BigNumber | bigint | Array | Matrix} y Second value to xor * @return {number | BigNumber | bigint | Array | Matrix} XOR of `x` and `y` diff --git a/src/function/bitwise/leftShift.js b/src/function/bitwise/leftShift.js index c7c49030b8..6552d8ea8e 100644 --- a/src/function/bitwise/leftShift.js +++ b/src/function/bitwise/leftShift.js @@ -49,11 +49,11 @@ export const createLeftShift = /* #__PURE__ */ factory(name, dependencies, ({ ty * * leftShift, bitNot, bitOr, bitXor, rightArithShift, rightLogShift * - * History: - * - * v11.6 Support matrix broadcasting - * v1.2 Created - * + * History: + * + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Array | Matrix} x Value to be shifted * @param {number | BigNumber | bigint} y Amount of shifts * @return {number | BigNumber | bigint | Array | Matrix} `x` shifted left `y` times diff --git a/src/function/bitwise/rightArithShift.js b/src/function/bitwise/rightArithShift.js index 19df23b5a4..9242707fed 100644 --- a/src/function/bitwise/rightArithShift.js +++ b/src/function/bitwise/rightArithShift.js @@ -49,11 +49,11 @@ export const createRightArithShift = /* #__PURE__ */ factory(name, dependencies, * * bitAnd, bitNot, bitOr, bitXor, rightArithShift, rightLogShift * - * History: - * - * v11.6 Support matrix broadcasting - * v1.2 Created - * + * History: + * + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Array | Matrix} x Value to be shifted * @param {number | BigNumber | bigint} y Amount of shifts * @return {number | BigNumber | bigint | Array | Matrix} `x` zero-filled shifted right `y` times diff --git a/src/function/bitwise/rightLogShift.js b/src/function/bitwise/rightLogShift.js index 2cfa3b915b..c90ecfbbfe 100644 --- a/src/function/bitwise/rightLogShift.js +++ b/src/function/bitwise/rightLogShift.js @@ -48,11 +48,11 @@ export const createRightLogShift = /* #__PURE__ */ factory(name, dependencies, ( * * bitAnd, bitNot, bitOr, bitXor, leftShift, rightLogShift * - * History: - * - * v11.6 Support matrix broadcasting - * v1.2 Created - * + * History: + * + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | Array | Matrix} x Value to be shifted * @param {number} y Amount of shifts * @return {number | Array | Matrix} `x` zero-filled shifted right `y` times diff --git a/src/function/logical/and.js b/src/function/logical/and.js index 841c54f751..2d98109502 100644 --- a/src/function/logical/and.js +++ b/src/function/logical/and.js @@ -45,11 +45,11 @@ export const createAnd = /* #__PURE__ */ factory(name, dependencies, ({ typed, m * * not, or, xor * - * History: - *. v12.2 Lazy evaluation - * v11.6 Support matrix broadcasting - * v1.2 Created - * + * History: + * v12.2 Lazy evaluation + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Complex | Unit | Array | Matrix} x First value to check * @param {number | BigNumber | bigint | Complex | Unit | Array | Matrix} y Second value to check * @return {boolean | Array | Matrix} diff --git a/src/function/logical/or.js b/src/function/logical/or.js index e89cc92104..d8f369dfcb 100644 --- a/src/function/logical/or.js +++ b/src/function/logical/or.js @@ -42,12 +42,12 @@ export const createOr = /* #__PURE__ */ factory(name, dependencies, ({ typed, ma * * and, not, xor * - * History: - * - * v12.2 Lazy evaluation - * v11.6 Support matrix broadcasting - * v1.2 Created - * + * History: + * + * v12.2 Lazy evaluation + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Complex | Unit | Array | Matrix} x First value to check * @param {number | BigNumber | bigint | Complex | Unit | Array | Matrix} y Second value to check * @return {boolean | Array | Matrix} diff --git a/src/function/logical/xor.js b/src/function/logical/xor.js index 5f924a4eaa..659cbe2a1d 100644 --- a/src/function/logical/xor.js +++ b/src/function/logical/xor.js @@ -42,12 +42,12 @@ export const createXor = /* #__PURE__ */ factory(name, dependencies, ({ typed, m * * and, not, or * - * History: - * - * v14.0.0 Return a sparse matrix for sparse inputs - * v11.6 Support matrix broadcasting - * v1.2 Created - * + * History: + * + * v14.0.0 Return a sparse matrix for sparse inputs + * v11.6 Support matrix broadcasting + * v1.2 Created + * * @param {number | BigNumber | bigint | Complex | Unit | Array | Matrix} x First value to check * @param {number | BigNumber | bigint | Complex | Unit | Array | Matrix} y Second value to check * @return {boolean | Array | Matrix} diff --git a/src/function/relational/compare.js b/src/function/relational/compare.js index 300034674f..a96db151d2 100644 --- a/src/function/relational/compare.js +++ b/src/function/relational/compare.js @@ -59,10 +59,10 @@ export const createCompare = /* #__PURE__ */ factory(name, dependencies, ({ type * * History: * - * v0.19 Created - * v4 Changed to compare strings by numerical value - * v11.6 Support matrix broadcasting * v13 Change to use separate relative and absolute tolerances + * v11.6 Support matrix broadcasting + * v4 Changed to compare strings by numerical value + * v0.19 Created * * @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 diff --git a/src/function/relational/equal.js b/src/function/relational/equal.js index 08444743e5..1e88cfb597 100644 --- a/src/function/relational/equal.js +++ b/src/function/relational/equal.js @@ -65,9 +65,9 @@ export const createEqual = /* #__PURE__ */ factory(name, dependencies, ({ typed, * History: * * v14 Return a sparse matrix for sparse inputs - * v13 Handle bigints and change to use separate relative and absolute tolerances + * v13 Handle bigints; use separate relative and absolute tolerances * v11.6 Support matrix broadcasting - * v4 Compare strings by their numerical value and implemented nearly equal comparison + * v4 Compare strings by numerical, allow tolerance in comparison * v0.24 Handle `null` and `undefined` * v0.23 Compare collections elementwise * v0.20 Compare floating-point numbers within epsilon, allowing roundoff diff --git a/src/function/relational/larger.js b/src/function/relational/larger.js index 71b3439c17..bf0c484f56 100644 --- a/src/function/relational/larger.js +++ b/src/function/relational/larger.js @@ -51,15 +51,15 @@ export const createLarger = /* #__PURE__ */ factory(name, dependencies, ({ typed * * equal, unequal, smaller, smallerEq, largerEq, compare * - * History: - * - * v14.1 Support bigints - * v14 Return a sparse matrix for sparse inputs - * v11.6 Support matrix broadcasting - * v4 Compare strings by their numerical value and implemented nearly equal comparison - * v3 Use nearly-equal comparison for BigNumbers - * v0.15 Removed support for complex numbers - * + * History: + * + * v14.1 Support bigints + * v14 Return a sparse matrix for sparse inputs + * v11.6 Support matrix broadcasting + * v4 Compare strings by numerical value, allow tolerance in comparison + * v3 Use nearly-equal comparison for BigNumbers + * v0.15 Removed support for complex numbers + * * @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 diff --git a/src/function/relational/largerEq.js b/src/function/relational/largerEq.js index d31bbec737..0c24d86cad 100644 --- a/src/function/relational/largerEq.js +++ b/src/function/relational/largerEq.js @@ -46,16 +46,16 @@ export const createLargerEq = /* #__PURE__ */ factory(name, dependencies, ({ typ * * equal, unequal, smaller, smallerEq, larger, compare * - * History: - * - * v14.0.0 Return a sparse matrix for sparse inputs - * v11.6 Support matrix broadcasting - * v4 Compare strings by their numerical value and implemented nearly equal comparison - * v3 Use nearly-equal comparison for BigNumbers - * 0.23 Renamed from `largereq`to `largerEq` - * v0.15 Removed support for complex numbers - * v0.2 Created - * + * History: + * + * v14.0.0 Return a sparse matrix for sparse inputs + * v11.6 Support matrix broadcasting + * v4 Compare strings by numerical value, allow tolerance in comparison + * v3 Use nearly-equal comparison for BigNumbers + * 0.23 Renamed from `largereq`to `largerEq` + * v0.15 Removed support for complex numbers + * v0.2 Created + * * @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 diff --git a/src/function/relational/smaller.js b/src/function/relational/smaller.js index 8dbf011211..f53cb16bc8 100644 --- a/src/function/relational/smaller.js +++ b/src/function/relational/smaller.js @@ -51,14 +51,14 @@ export const createSmaller = /* #__PURE__ */ factory(name, dependencies, ({ type * * equal, unequal, smallerEq, smaller, smallerEq, compare * - * History: - * - * v14.1 Support bigints - * v14 Return a sparse matrix for sparse inputs - * v11.6 Support matrix broadcasting - * v4 Compare strings by their numerical value and implemented nearly equal comparison - * v3 Use nearly-equal comparison for BigNumbers - * + * History: + * + * v14.1 Support bigints + * v14 Return a sparse matrix for sparse inputs + * v11.6 Support matrix broadcasting + * v4 Compare strings by numerical value, allow tolerance in comparison + * v3 Use nearly-equal comparison for BigNumbers + * * @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 diff --git a/src/function/relational/smallerEq.js b/src/function/relational/smallerEq.js index 0cc5af0081..3a035c9225 100644 --- a/src/function/relational/smallerEq.js +++ b/src/function/relational/smallerEq.js @@ -46,14 +46,14 @@ export const createSmallerEq = /* #__PURE__ */ factory(name, dependencies, ({ ty * * equal, unequal, smaller, larger, largerEq, compare * - * History: - * - * v14.0.0 Return a sparse matrix for sparse inputs - * v11.6 Support matrix broadcasting - * v4 Compare strings by their numerical value and implemented nearly equal comparison - * v0.23 Renamed from `smalleq`to `smallerEq` - * v0.15 Removed support for complex numbers - * + * History: + * + * v14.0.0 Return a sparse matrix for sparse inputs + * v11.6 Support matrix broadcasting + * v4 Compare strings by numerical value, allow tolerance in comparison + * v0.23 Renamed from `smalleq`to `smallerEq` + * v0.15 Removed support for complex numbers + * * @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 diff --git a/src/function/relational/unequal.js b/src/function/relational/unequal.js index 9d3b2f6a1c..696b878c38 100644 --- a/src/function/relational/unequal.js +++ b/src/function/relational/unequal.js @@ -64,12 +64,12 @@ export const createUnequal = /* #__PURE__ */ factory(name, dependencies, ({ type * * History: * - * v14.0.0 Return a sparse matrix for sparse inputs - * v13 Handle bigints - * v11.6 Support matrix broadcasting - * v4 Compare strings by their numeric values - * v0.24 Handle `null` and `undefined` - * v0.2 Created + * v14.0.0 Return a sparse matrix for sparse inputs + * v13 Handle bigints + * v11.6 Support matrix broadcasting + * v4 Compare strings by their numeric values + * v0.24 Handle `null` and `undefined` + * v0.2 Created * * @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 diff --git a/src/function/unit/to.js b/src/function/unit/to.js index 5990114963..f362691b4c 100644 --- a/src/function/unit/to.js +++ b/src/function/unit/to.js @@ -29,12 +29,12 @@ export const createTo = /* #__PURE__ */ factory(name, dependencies, ({ typed, ma * * unit * - * History: - * - * v11.6 Support matrix broadcasting - * v2.2 Fix simplified unit conversions - * v0.18 Renamed from `in` to `to` - * + * History: + * + * v11.6 Support matrix broadcasting + * v2.2 Fix simplified unit conversions + * v0.18 Renamed from `in` to `to` + * * @param {Unit | Array | Matrix} x The unit to be converted. * @param {Unit | Array | Matrix} unit New unit. Can be a string like "cm" * or a unit without value. diff --git a/src/type/matrix/utils/matAlgo15xAs.js b/src/type/matrix/utils/matAlgo15xAs.js index 728822066e..163c1fad76 100644 --- a/src/type/matrix/utils/matAlgo15xAs.js +++ b/src/type/matrix/utils/matAlgo15xAs.js @@ -6,8 +6,9 @@ const dependencies = [] export const createMatAlgo15xAs = /* #__PURE__ */ factory(name, dependencies, () => { /** - * Deeply iterates over Array items and invokes the callback function f(Aij..z, b). - * Callback function invoked once for each item. + * Deeply iterates over Array items and invokes the callback function + * f(Aij..z, b) for each nested scalar. + * The callback function is invoked once for each item. * * C(i,j,...z) = f(Aij..z, b) * diff --git a/test/unit-tests/function/matrix/map.test.js b/test/unit-tests/function/matrix/map.test.js index 4a864c23b5..ea4d2b8f21 100644 --- a/test/unit-tests/function/matrix/map.test.js +++ b/test/unit-tests/function/matrix/map.test.js @@ -16,6 +16,13 @@ describe('map', function () { assert.ok(Array.isArray(arr2)) }) + it('should map jagged arrays', function () { + const map = math.map + const sqrt = math.square + assert.deepStrictEqual(map([[2], []], sqrt), [[4], []]) + assert.deepStrictEqual(map([[], [2]], sqrt), [[], [4]]) + }) + it('should map two arrays', function () { const arrA = [[1, 2, 3], [4, 5, 6]] const arrB = [[10, 20, 30], [40, 50, 60]] From 903dbdc9c20d17abc32f6de5f4d6f4674f5e52ee Mon Sep 17 00:00:00 2001 From: David Contreras Date: Sat, 21 Mar 2026 03:18:56 +0000 Subject: [PATCH 41/46] Add test for `optimizeCallbak`. Included unary info for `map` --- src/function/matrix/map.js | 12 ++++++------ src/utils/optimizeCallback.js | 31 ++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/function/matrix/map.js b/src/function/matrix/map.js index fb48340e02..624b9025dc 100644 --- a/src/function/matrix/map.js +++ b/src/function/matrix/map.js @@ -58,10 +58,10 @@ export const createMap = /* #__PURE__ */ factory(name, dependencies, ({ typed }) * Transformed map of x; always has the same type and shape as x */ return typed(name, { - 'Array, function': _mapArray, + 'Array, function': function (x, callback) { return _mapArray(x, callback, true) }, 'Matrix, function': function (x, callback) { - return x.map(callback) + return x.map(callback, false, true) }, 'Array|Matrix, Array|Matrix, ...Array|Matrix|function': (A, B, rest) => @@ -124,9 +124,9 @@ export const createMap = /* #__PURE__ */ factory(name, dependencies, ({ typed }) idx) if (firstArrayIsMatrix) { - return broadcastedArrays[0].map(broadcastedArraysCallback) + return broadcastedArrays[0].map(broadcastedArraysCallback, false) } else { - return _mapArray(broadcastedArrays[0], broadcastedArraysCallback) + return _mapArray(broadcastedArrays[0], broadcastedArraysCallback, false) } } @@ -251,8 +251,8 @@ export const createMap = /* #__PURE__ */ factory(name, dependencies, ({ typed }) * @return {Array} * @private */ - function _mapArray (array, callback) { - const fastCallback = optimizeCallback(callback, array, name) + function _mapArray (array, callback, isUnary) { + const fastCallback = optimizeCallback(callback, array, name, isUnary) return deepMap(array, fastCallback.fn, fastCallback.isUnary) } }) diff --git a/src/utils/optimizeCallback.js b/src/utils/optimizeCallback.js index 5e6a0b94fb..3fc9b6a94f 100644 --- a/src/utils/optimizeCallback.js +++ b/src/utils/optimizeCallback.js @@ -1,5 +1,4 @@ import typed from 'typed-function' -import { get, arraySize } from './array.js' import { typeOf as _typeOf } from './is.js' /** @@ -12,23 +11,22 @@ import { typeOf as _typeOf } from './is.js' * @returns {Function} Returns a simplified version of the callback function. */ export function optimizeCallback (callback, array, name, isUnary) { + const isMatrix = array && array.isMatrix if (typed.isTypedFunction(callback)) { let numberOfArguments if (isUnary) { numberOfArguments = 1 } else { - const size = array.isMatrix ? array.size() : arraySize(array) - + const firstIndex = isMatrix ? array.size().map(() => 0) : [0] // it only needs to be an array to be recognized + const firstValue = _findFirst(isMatrix ? array._data : array) + const isEmpty = isMatrix ? array.size().at(-1) === 0 : array.length === 0 // Check the size of the last dimension to see if the array/matrix is empty - const isEmpty = size.length ? size[size.length - 1] === 0 : true - if (isEmpty) { + if (isEmpty || firstValue === undefined) { // don't optimize callbacks for empty arrays/matrix, as they will never be called // and in fact will throw an exception when we try to access the first element below return { isUnary, fn: callback } } - const firstIndex = size.map(() => 0) - const firstValue = array.isMatrix ? array.get(firstIndex) : get(array, firstIndex) numberOfArguments = _findNumberOfArgumentsTyped(callback, firstValue, firstIndex, array) } let fastCallback @@ -53,6 +51,25 @@ export function optimizeCallback (callback, array, name, isUnary) { } } +function _findFirst (array) { + if (array && array.isMatrix) { + const size = array.size() + const firstIndex = size.map(() => 0) + return array.get(firstIndex) + } else { + return traverse(array) + } + function traverse (value) { + if (Array.isArray(value)) { + for (let i = 0; i < value.length; i++) { + return traverse(value[i]) + } + } else { + return value + } + } +} + function _findSingleSignatureWithArity (callback, arity) { const matchingFunctions = [] Object.entries(callback.signatures).forEach(([signature, func]) => { From daf597e1260374beb70629b92b191f8dbb16a5cc Mon Sep 17 00:00:00 2001 From: David Contreras Date: Sat, 21 Mar 2026 03:20:01 +0000 Subject: [PATCH 42/46] added test for `optimizeCallback --- .../unit-tests/utils/optimizeCallback.test.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/unit-tests/utils/optimizeCallback.test.js diff --git a/test/unit-tests/utils/optimizeCallback.test.js b/test/unit-tests/utils/optimizeCallback.test.js new file mode 100644 index 0000000000..e7cfad4230 --- /dev/null +++ b/test/unit-tests/utils/optimizeCallback.test.js @@ -0,0 +1,49 @@ +import assert from 'assert' +import math from '../../../src/defaultInstance.js' +import { optimizeCallback } from '../../../src/utils/optimizeCallback.js' + +describe('optimizeCallback', function () { + function unaryCallback (a) { + a + 1 + } + const typedUnaryCallback = math.typed('unaryCallback', { + number: unaryCallback + }) + + function ternaryCallback (a, b, c) { + return a + b + c + 1 + } + const typedTernaryCallback = math.typed('ternaryCallback', { + 'number, number, number': ternaryCallback + }) + + const arrayOfNumbers = [1, 2, 3] + const name = 'myFunction' + + it('should find the right number of arguments for a function', function () { + const optimizedUnary = optimizeCallback(unaryCallback, arrayOfNumbers, name, false) + assert.strictEqual(optimizedUnary.isUnary, true) + const optimizedTernary = optimizeCallback(ternaryCallback, arrayOfNumbers, name, false) + assert.strictEqual(optimizedTernary.isUnary, false) + }) + + it('should find the right number of arguments for a typed function', function () { + const optimizedTypedUnary = optimizeCallback(typedUnaryCallback, arrayOfNumbers, name, false) + assert.strictEqual(optimizedTypedUnary.isUnary, true) + const optimizedTypedTernary = optimizeCallback(typedTernaryCallback, arrayOfNumbers, name, false) + assert.strictEqual(optimizedTypedTernary.isUnary, false) + }) + + it('should return unary functions as unary when isUnary is set to true', function () { + const optimizedUnary = optimizeCallback(unaryCallback, arrayOfNumbers, name, true) + assert.strictEqual(optimizedUnary.isUnary, true) + const optimizedTernary = optimizeCallback(ternaryCallback, arrayOfNumbers, name, true) + assert.strictEqual(optimizedTernary.isUnary, true) + const optimizedTypedUnary = optimizeCallback(typedUnaryCallback, arrayOfNumbers, name, true) + assert.strictEqual(optimizedTypedUnary.isUnary, true) + const optimizedTypedTernary = optimizeCallback(typedTernaryCallback, arrayOfNumbers, name, true) + assert.strictEqual(optimizedTypedTernary.isUnary, true) + }) + +} +) From 88e1aa79f1ac02ed062faf77334a7f4defa21215 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Sat, 21 Mar 2026 03:27:26 +0000 Subject: [PATCH 43/46] added more tests to `optimizeCallback` --- .../unit-tests/utils/optimizeCallback.test.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/unit-tests/utils/optimizeCallback.test.js b/test/unit-tests/utils/optimizeCallback.test.js index e7cfad4230..50e6279e53 100644 --- a/test/unit-tests/utils/optimizeCallback.test.js +++ b/test/unit-tests/utils/optimizeCallback.test.js @@ -18,6 +18,8 @@ describe('optimizeCallback', function () { }) const arrayOfNumbers = [1, 2, 3] + const matrixOfNumbers = math.matrix(arrayOfNumbers) + const sparseMatrixOfNumbers = math.matrix(arrayOfNumbers, 'sparse') const name = 'myFunction' it('should find the right number of arguments for a function', function () { @@ -25,6 +27,14 @@ describe('optimizeCallback', function () { assert.strictEqual(optimizedUnary.isUnary, true) const optimizedTernary = optimizeCallback(ternaryCallback, arrayOfNumbers, name, false) assert.strictEqual(optimizedTernary.isUnary, false) + const optimizedUnaryMatrix = optimizeCallback(unaryCallback, matrixOfNumbers, name, false) + assert.strictEqual(optimizedUnaryMatrix.isUnary, true) + const optimizedTernaryMatrix = optimizeCallback(ternaryCallback, matrixOfNumbers, name, false) + assert.strictEqual(optimizedTernaryMatrix.isUnary, false) + const optimizedUnarySparseMatrix = optimizeCallback(unaryCallback, sparseMatrixOfNumbers, name, false) + assert.strictEqual(optimizedUnarySparseMatrix.isUnary, true) + const optimizedTernarySparseMatrix = optimizeCallback(ternaryCallback, sparseMatrixOfNumbers, name, false) + assert.strictEqual(optimizedTernarySparseMatrix.isUnary, false) }) it('should find the right number of arguments for a typed function', function () { @@ -32,6 +42,14 @@ describe('optimizeCallback', function () { assert.strictEqual(optimizedTypedUnary.isUnary, true) const optimizedTypedTernary = optimizeCallback(typedTernaryCallback, arrayOfNumbers, name, false) assert.strictEqual(optimizedTypedTernary.isUnary, false) + const optimizedTypedUnaryMatrix = optimizeCallback(typedUnaryCallback, matrixOfNumbers, name, false) + assert.strictEqual(optimizedTypedUnaryMatrix.isUnary, true) + const optimizedTypedTernaryMatrix = optimizeCallback(typedTernaryCallback, matrixOfNumbers, name, false) + assert.strictEqual(optimizedTypedTernaryMatrix.isUnary, false) + const optimizedTypedUnarySparseMatrix = optimizeCallback(typedUnaryCallback, sparseMatrixOfNumbers, name, false) + assert.strictEqual(optimizedTypedUnarySparseMatrix.isUnary, true) + const optimizedTypedTernarySparseMatrix = optimizeCallback(typedTernaryCallback, sparseMatrixOfNumbers, name, false) + assert.strictEqual(optimizedTypedTernarySparseMatrix.isUnary, false) }) it('should return unary functions as unary when isUnary is set to true', function () { @@ -45,5 +63,28 @@ describe('optimizeCallback', function () { assert.strictEqual(optimizedTypedTernary.isUnary, true) }) + it('should run the optimized callback', function () { + const optimizedUnary = optimizeCallback(unaryCallback, arrayOfNumbers, name, false) + assert.strictEqual(optimizedUnary.fn(1), 2) + const optimizedTernary = optimizeCallback(ternaryCallback, arrayOfNumbers, name, false) + assert.strictEqual(optimizedTernary.fn(1, 2, 3), 7) + const optimizedTypedUnary = optimizeCallback(typedUnaryCallback, arrayOfNumbers, name, false) + assert.strictEqual(optimizedTypedUnary.fn(1), 2) + const optimizedTypedTernary = optimizeCallback(typedTernaryCallback, arrayOfNumbers, name, false) + assert.strictEqual(optimizedTypedTernary.fn(1, 2, 3), 7) + const optimizedUnaryMatrix = optimizeCallback(unaryCallback, matrixOfNumbers, name, false) + assert.strictEqual(optimizedUnaryMatrix.fn(1), 2) + const optimizedTernaryMatrix = optimizeCallback(ternaryCallback, matrixOfNumbers, name, false) + assert.strictEqual(optimizedTernaryMatrix.fn(1, 2, 3), 7) + const optimizedTypedUnaryMatrix = optimizeCallback(typedUnaryCallback, matrixOfNumbers, name, false) + assert.strictEqual(optimizedTypedUnaryMatrix.fn(1), 2) + const optimizedTypedTernaryMatrix = optimizeCallback(typedTernaryCallback, matrixOfNumbers, name, false) + assert.strictEqual(optimizedTypedTernaryMatrix.fn(1, 2, 3), 7) + const optimizedUnarySparseMatrix = optimizeCallback(unaryCallback, sparseMatrixOfNumbers, name, false) + assert.strictEqual(optimizedUnarySparseMatrix.fn(1), 2) + const optimizedTernarySparseMatrix = optimizeCallback(ternaryCallback, sparseMatrixOfNumbers, name, false) + assert.strictEqual(optimizedTernarySparseMatrix.fn(1, 2, 3), 7) +}) + } ) From b520031dd19f32e11e1e094ce5e2f878536e747b Mon Sep 17 00:00:00 2001 From: David Contreras Date: Sun, 29 Mar 2026 11:38:59 -0600 Subject: [PATCH 44/46] Restored capability to map non unary functions. --- src/function/matrix/map.js | 14 +++++++------- src/utils/optimizeCallback.js | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/function/matrix/map.js b/src/function/matrix/map.js index 624b9025dc..427326071a 100644 --- a/src/function/matrix/map.js +++ b/src/function/matrix/map.js @@ -58,10 +58,10 @@ export const createMap = /* #__PURE__ */ factory(name, dependencies, ({ typed }) * Transformed map of x; always has the same type and shape as x */ return typed(name, { - 'Array, function': function (x, callback) { return _mapArray(x, callback, true) }, + 'Array, function': _mapArray, 'Matrix, function': function (x, callback) { - return x.map(callback, false, true) + return x.map(callback) }, 'Array|Matrix, Array|Matrix, ...Array|Matrix|function': (A, B, rest) => @@ -124,9 +124,9 @@ export const createMap = /* #__PURE__ */ factory(name, dependencies, ({ typed }) idx) if (firstArrayIsMatrix) { - return broadcastedArrays[0].map(broadcastedArraysCallback, false) + return broadcastedArrays[0].map(broadcastedArraysCallback) } else { - return _mapArray(broadcastedArrays[0], broadcastedArraysCallback, false) + return _mapArray(broadcastedArrays[0], broadcastedArraysCallback) } } @@ -251,8 +251,8 @@ export const createMap = /* #__PURE__ */ factory(name, dependencies, ({ typed }) * @return {Array} * @private */ - function _mapArray (array, callback, isUnary) { - const fastCallback = optimizeCallback(callback, array, name, isUnary) + function _mapArray (array, callback) { + const fastCallback = optimizeCallback(callback, array, name) return deepMap(array, fastCallback.fn, fastCallback.isUnary) } -}) +}) \ No newline at end of file diff --git a/src/utils/optimizeCallback.js b/src/utils/optimizeCallback.js index 3fc9b6a94f..894f6dd8bb 100644 --- a/src/utils/optimizeCallback.js +++ b/src/utils/optimizeCallback.js @@ -30,7 +30,7 @@ export function optimizeCallback (callback, array, name, isUnary) { numberOfArguments = _findNumberOfArgumentsTyped(callback, firstValue, firstIndex, array) } let fastCallback - if (array.isMatrix && (array.dataType !== 'mixed' && array.dataType !== undefined)) { + if (isMatrix && (array.dataType !== 'mixed' && array.dataType !== undefined)) { const singleSignature = _findSingleSignatureWithArity(callback, numberOfArguments) fastCallback = (singleSignature !== undefined) ? singleSignature : callback } else { @@ -157,4 +157,4 @@ function _createCallbackError (err, args, mappingFnName, callbackName) { throw new TypeError(`Function ${mappingFnName} cannot apply callback arguments ` + `to function ${callbackName}: ${err.message}`) } -} +} \ No newline at end of file From f260f3c22390786f843d81f1c88b4748cbd63e8d Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 30 Mar 2026 13:41:18 -0600 Subject: [PATCH 45/46] Added tests to optimize callback findFirst --- src/utils/optimizeCallback.js | 14 ++++++--- .../unit-tests/utils/optimizeCallback.test.js | 30 ++++++++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/utils/optimizeCallback.js b/src/utils/optimizeCallback.js index 894f6dd8bb..41ff18bc4e 100644 --- a/src/utils/optimizeCallback.js +++ b/src/utils/optimizeCallback.js @@ -18,7 +18,7 @@ export function optimizeCallback (callback, array, name, isUnary) { numberOfArguments = 1 } else { const firstIndex = isMatrix ? array.size().map(() => 0) : [0] // it only needs to be an array to be recognized - const firstValue = _findFirst(isMatrix ? array._data : array) + const firstValue = findFirst(array) const isEmpty = isMatrix ? array.size().at(-1) === 0 : array.length === 0 // Check the size of the last dimension to see if the array/matrix is empty if (isEmpty || firstValue === undefined) { @@ -51,8 +51,11 @@ export function optimizeCallback (callback, array, name, isUnary) { } } -function _findFirst (array) { +export function findFirst (array) { if (array && array.isMatrix) { + if(array.size().at(-1) === 0) { + return undefined + } const size = array.size() const firstIndex = size.map(() => 0) return array.get(firstIndex) @@ -62,7 +65,10 @@ function _findFirst (array) { function traverse (value) { if (Array.isArray(value)) { for (let i = 0; i < value.length; i++) { - return traverse(value[i]) + const found = traverse(value[i]) + if (found !== undefined) { + return found + } } } else { return value @@ -157,4 +163,4 @@ function _createCallbackError (err, args, mappingFnName, callbackName) { throw new TypeError(`Function ${mappingFnName} cannot apply callback arguments ` + `to function ${callbackName}: ${err.message}`) } -} \ No newline at end of file +} diff --git a/test/unit-tests/utils/optimizeCallback.test.js b/test/unit-tests/utils/optimizeCallback.test.js index 50e6279e53..324399f7b9 100644 --- a/test/unit-tests/utils/optimizeCallback.test.js +++ b/test/unit-tests/utils/optimizeCallback.test.js @@ -1,6 +1,6 @@ import assert from 'assert' import math from '../../../src/defaultInstance.js' -import { optimizeCallback } from '../../../src/utils/optimizeCallback.js' +import { optimizeCallback, findFirst } from '../../../src/utils/optimizeCallback.js' describe('optimizeCallback', function () { function unaryCallback (a) { @@ -62,7 +62,7 @@ describe('optimizeCallback', function () { const optimizedTypedTernary = optimizeCallback(typedTernaryCallback, arrayOfNumbers, name, true) assert.strictEqual(optimizedTypedTernary.isUnary, true) }) - + it('should run the optimized callback', function () { const optimizedUnary = optimizeCallback(unaryCallback, arrayOfNumbers, name, false) assert.strictEqual(optimizedUnary.fn(1), 2) @@ -84,7 +84,29 @@ describe('optimizeCallback', function () { assert.strictEqual(optimizedUnarySparseMatrix.fn(1), 2) const optimizedTernarySparseMatrix = optimizeCallback(ternaryCallback, sparseMatrixOfNumbers, name, false) assert.strictEqual(optimizedTernarySparseMatrix.fn(1, 2, 3), 7) -}) - + }) } ) + +describe('findFirst', function () { + it('should find the first value in a nested array', function () { + assert.strictEqual(findFirst([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]), 1) + assert.strictEqual(findFirst([[[[1], [2]], [[3], [4]]], [[[5], [6]], [[7], [8]]]]), 1) + assert.strictEqual(findFirst([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]]), 1) + }) + + it('should find the first value in a matrix', function () { + assert.strictEqual(findFirst(math.matrix([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])), 1) + assert.strictEqual(findFirst(math.matrix([[[[1], [2]], [[3], [4]]], [[[5], [6]], [[7], [8]]]])), 1) + assert.strictEqual(findFirst(math.matrix([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]])), 1) + }) + it('should return undefined for an empty array or matrix', function () { + assert.strictEqual(findFirst([]), undefined) + assert.strictEqual(findFirst(math.matrix([])), undefined) + }) + it('should find the first value in a jagged array if the first element is empty', function () { + assert.strictEqual(findFirst([[], [1, 2], [3, 4]]), 1) + assert.strictEqual(findFirst([[], [[1], [2]], [[3], [4]]]), 1) + assert.strictEqual(findFirst([[], [[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]]), 1) + }) +}) From c25a0efe88cc1572fa82885a9a46958597e928d6 Mon Sep 17 00:00:00 2001 From: David Contreras Date: Mon, 30 Mar 2026 15:36:33 -0600 Subject: [PATCH 46/46] Fix tests for optimize callback --- src/function/matrix/map.js | 2 +- src/utils/optimizeCallback.js | 12 +- .../unit-tests/utils/optimizeCallback.test.js | 208 +++++++++--------- 3 files changed, 117 insertions(+), 105 deletions(-) diff --git a/src/function/matrix/map.js b/src/function/matrix/map.js index 427326071a..fb48340e02 100644 --- a/src/function/matrix/map.js +++ b/src/function/matrix/map.js @@ -255,4 +255,4 @@ export const createMap = /* #__PURE__ */ factory(name, dependencies, ({ typed }) const fastCallback = optimizeCallback(callback, array, name) return deepMap(array, fastCallback.fn, fastCallback.isUnary) } -}) \ No newline at end of file +}) diff --git a/src/utils/optimizeCallback.js b/src/utils/optimizeCallback.js index 41ff18bc4e..04a6938977 100644 --- a/src/utils/optimizeCallback.js +++ b/src/utils/optimizeCallback.js @@ -2,13 +2,13 @@ import typed from 'typed-function' import { typeOf as _typeOf } from './is.js' /** - * Simplifies a callback function by reducing its complexity and potentially improving its performance. + * Simplifies a callback function to be used in mapping functions like `map`, `forEach`, etc. It determines if the callback is unary and optimizes it accordingly. * * @param {Function} callback The original callback function to simplify. * @param {Array|Matrix} array The array that will be used with the callback function. * @param {string} name The name of the function that is using the callback. * @param {boolean} isUnary If true, the callback function is unary and will be optimized as such. - * @returns {Function} Returns a simplified version of the callback function. + * @returns {Object} Returns an object with properties `isUnary` and `fn`. */ export function optimizeCallback (callback, array, name, isUnary) { const isMatrix = array && array.isMatrix @@ -44,16 +44,16 @@ export function optimizeCallback (callback, array, name, isUnary) { } return { isUnary: false, fn: (...args) => _tryFunctionWithArgs(fastCallback, args, name, callback.name) } } - if (isUnary === undefined) { - return { isUnary: _findIfCallbackIsUnary(callback), fn: callback } - } else { + if (isUnary) { return { isUnary, fn: callback } + } else { + return { isUnary: _findIfCallbackIsUnary(callback), fn: callback } } } export function findFirst (array) { if (array && array.isMatrix) { - if(array.size().at(-1) === 0) { + if (array.size().at(-1) === 0) { return undefined } const size = array.size() diff --git a/test/unit-tests/utils/optimizeCallback.test.js b/test/unit-tests/utils/optimizeCallback.test.js index 324399f7b9..4e65679807 100644 --- a/test/unit-tests/utils/optimizeCallback.test.js +++ b/test/unit-tests/utils/optimizeCallback.test.js @@ -2,111 +2,123 @@ import assert from 'assert' import math from '../../../src/defaultInstance.js' import { optimizeCallback, findFirst } from '../../../src/utils/optimizeCallback.js' -describe('optimizeCallback', function () { - function unaryCallback (a) { - a + 1 - } - const typedUnaryCallback = math.typed('unaryCallback', { - number: unaryCallback - }) +describe('utils.optimizeCallback', function () { + describe('optimizeCallback', function () { + function unaryCallback (a) { + return a + 1 + } + const typedUnaryCallback = math.typed('unaryCallback', { + number: unaryCallback + }) - function ternaryCallback (a, b, c) { - return a + b + c + 1 - } - const typedTernaryCallback = math.typed('ternaryCallback', { - 'number, number, number': ternaryCallback - }) + function ternaryCallback (a, index, c) { + return a + index[0] + c[0] + } + const typedTernaryCallback = math.typed('ternaryCallback', { + 'number, Array, Array': ternaryCallback + }) - const arrayOfNumbers = [1, 2, 3] - const matrixOfNumbers = math.matrix(arrayOfNumbers) - const sparseMatrixOfNumbers = math.matrix(arrayOfNumbers, 'sparse') - const name = 'myFunction' + const arrayOfNumbers = [1, 2, 3] + const matrixOfNumbers = math.matrix(arrayOfNumbers) + const sparseMatrixOfNumbers = math.matrix(arrayOfNumbers, 'sparse') + const name = 'myFunction' - it('should find the right number of arguments for a function', function () { - const optimizedUnary = optimizeCallback(unaryCallback, arrayOfNumbers, name, false) - assert.strictEqual(optimizedUnary.isUnary, true) - const optimizedTernary = optimizeCallback(ternaryCallback, arrayOfNumbers, name, false) - assert.strictEqual(optimizedTernary.isUnary, false) - const optimizedUnaryMatrix = optimizeCallback(unaryCallback, matrixOfNumbers, name, false) - assert.strictEqual(optimizedUnaryMatrix.isUnary, true) - const optimizedTernaryMatrix = optimizeCallback(ternaryCallback, matrixOfNumbers, name, false) - assert.strictEqual(optimizedTernaryMatrix.isUnary, false) - const optimizedUnarySparseMatrix = optimizeCallback(unaryCallback, sparseMatrixOfNumbers, name, false) - assert.strictEqual(optimizedUnarySparseMatrix.isUnary, true) - const optimizedTernarySparseMatrix = optimizeCallback(ternaryCallback, sparseMatrixOfNumbers, name, false) - assert.strictEqual(optimizedTernarySparseMatrix.isUnary, false) - }) + it('should find the right number of arguments for a function', function () { + const optimizedUnary = optimizeCallback(unaryCallback, arrayOfNumbers, name) + assert.strictEqual(optimizedUnary.isUnary, true) + const optimizedTernary = optimizeCallback(ternaryCallback, arrayOfNumbers, name) + assert.strictEqual(optimizedTernary.isUnary, false) + const optimizedUnaryMatrix = optimizeCallback(unaryCallback, matrixOfNumbers, name) + assert.strictEqual(optimizedUnaryMatrix.isUnary, true) + const optimizedTernaryMatrix = optimizeCallback(ternaryCallback, matrixOfNumbers, name) + assert.strictEqual(optimizedTernaryMatrix.isUnary, false) + const optimizedUnarySparseMatrix = optimizeCallback(unaryCallback, sparseMatrixOfNumbers, name) + assert.strictEqual(optimizedUnarySparseMatrix.isUnary, true) + const optimizedTernarySparseMatrix = optimizeCallback(ternaryCallback, sparseMatrixOfNumbers, name) + assert.strictEqual(optimizedTernarySparseMatrix.isUnary, false) + }) - it('should find the right number of arguments for a typed function', function () { - const optimizedTypedUnary = optimizeCallback(typedUnaryCallback, arrayOfNumbers, name, false) - assert.strictEqual(optimizedTypedUnary.isUnary, true) - const optimizedTypedTernary = optimizeCallback(typedTernaryCallback, arrayOfNumbers, name, false) - assert.strictEqual(optimizedTypedTernary.isUnary, false) - const optimizedTypedUnaryMatrix = optimizeCallback(typedUnaryCallback, matrixOfNumbers, name, false) - assert.strictEqual(optimizedTypedUnaryMatrix.isUnary, true) - const optimizedTypedTernaryMatrix = optimizeCallback(typedTernaryCallback, matrixOfNumbers, name, false) - assert.strictEqual(optimizedTypedTernaryMatrix.isUnary, false) - const optimizedTypedUnarySparseMatrix = optimizeCallback(typedUnaryCallback, sparseMatrixOfNumbers, name, false) - assert.strictEqual(optimizedTypedUnarySparseMatrix.isUnary, true) - const optimizedTypedTernarySparseMatrix = optimizeCallback(typedTernaryCallback, sparseMatrixOfNumbers, name, false) - assert.strictEqual(optimizedTypedTernarySparseMatrix.isUnary, false) - }) + it('should find the right number of arguments for a typed function', function () { + const optimizedTypedUnary = optimizeCallback(typedUnaryCallback, arrayOfNumbers, name) + assert.strictEqual(optimizedTypedUnary.isUnary, true) + const optimizedTypedTernary = optimizeCallback(typedTernaryCallback, arrayOfNumbers, name) + assert.strictEqual(optimizedTypedTernary.isUnary, false) + const optimizedTypedUnaryMatrix = optimizeCallback(typedUnaryCallback, matrixOfNumbers, name) + assert.strictEqual(optimizedTypedUnaryMatrix.isUnary, true) + const optimizedTypedTernaryMatrix = optimizeCallback(typedTernaryCallback, matrixOfNumbers, name) + assert.strictEqual(optimizedTypedTernaryMatrix.isUnary, false) + const optimizedTypedUnarySparseMatrix = optimizeCallback(typedUnaryCallback, sparseMatrixOfNumbers, name) + assert.strictEqual(optimizedTypedUnarySparseMatrix.isUnary, true) + const optimizedTypedTernarySparseMatrix = optimizeCallback(typedTernaryCallback, sparseMatrixOfNumbers, name) + assert.strictEqual(optimizedTypedTernarySparseMatrix.isUnary, false) + }) - it('should return unary functions as unary when isUnary is set to true', function () { - const optimizedUnary = optimizeCallback(unaryCallback, arrayOfNumbers, name, true) - assert.strictEqual(optimizedUnary.isUnary, true) - const optimizedTernary = optimizeCallback(ternaryCallback, arrayOfNumbers, name, true) - assert.strictEqual(optimizedTernary.isUnary, true) - const optimizedTypedUnary = optimizeCallback(typedUnaryCallback, arrayOfNumbers, name, true) - assert.strictEqual(optimizedTypedUnary.isUnary, true) - const optimizedTypedTernary = optimizeCallback(typedTernaryCallback, arrayOfNumbers, name, true) - assert.strictEqual(optimizedTypedTernary.isUnary, true) - }) + it('should return unary functions as unary when isUnary is set to true', function () { + const optimizedUnary = optimizeCallback(unaryCallback, arrayOfNumbers, name, true) + assert.strictEqual(optimizedUnary.isUnary, true) + const optimizedTernary = optimizeCallback(ternaryCallback, arrayOfNumbers, name, true) + assert.strictEqual(optimizedTernary.isUnary, true) + const optimizedTypedUnary = optimizeCallback(typedUnaryCallback, arrayOfNumbers, name, true) + assert.strictEqual(optimizedTypedUnary.isUnary, true) + const optimizedTypedTernary = optimizeCallback(typedTernaryCallback, arrayOfNumbers, name, true) + assert.strictEqual(optimizedTypedTernary.isUnary, true) + }) - it('should run the optimized callback', function () { - const optimizedUnary = optimizeCallback(unaryCallback, arrayOfNumbers, name, false) - assert.strictEqual(optimizedUnary.fn(1), 2) - const optimizedTernary = optimizeCallback(ternaryCallback, arrayOfNumbers, name, false) - assert.strictEqual(optimizedTernary.fn(1, 2, 3), 7) - const optimizedTypedUnary = optimizeCallback(typedUnaryCallback, arrayOfNumbers, name, false) - assert.strictEqual(optimizedTypedUnary.fn(1), 2) - const optimizedTypedTernary = optimizeCallback(typedTernaryCallback, arrayOfNumbers, name, false) - assert.strictEqual(optimizedTypedTernary.fn(1, 2, 3), 7) - const optimizedUnaryMatrix = optimizeCallback(unaryCallback, matrixOfNumbers, name, false) - assert.strictEqual(optimizedUnaryMatrix.fn(1), 2) - const optimizedTernaryMatrix = optimizeCallback(ternaryCallback, matrixOfNumbers, name, false) - assert.strictEqual(optimizedTernaryMatrix.fn(1, 2, 3), 7) - const optimizedTypedUnaryMatrix = optimizeCallback(typedUnaryCallback, matrixOfNumbers, name, false) - assert.strictEqual(optimizedTypedUnaryMatrix.fn(1), 2) - const optimizedTypedTernaryMatrix = optimizeCallback(typedTernaryCallback, matrixOfNumbers, name, false) - assert.strictEqual(optimizedTypedTernaryMatrix.fn(1, 2, 3), 7) - const optimizedUnarySparseMatrix = optimizeCallback(unaryCallback, sparseMatrixOfNumbers, name, false) - assert.strictEqual(optimizedUnarySparseMatrix.fn(1), 2) - const optimizedTernarySparseMatrix = optimizeCallback(ternaryCallback, sparseMatrixOfNumbers, name, false) - assert.strictEqual(optimizedTernarySparseMatrix.fn(1, 2, 3), 7) - }) -} -) + it('should run the optimized callback', function () { + const optimizedUnary = optimizeCallback(unaryCallback, arrayOfNumbers, name) + const args = [1, [2, 2], [3]] + assert.strictEqual(unaryCallback(1), 2) + assert.strictEqual(optimizedUnary.fn(1), 2) + const optimizedTernary = optimizeCallback(ternaryCallback, arrayOfNumbers, name) + assert.strictEqual(optimizedTernary.fn(...args), 6) + const optimizedTypedUnary = optimizeCallback(typedUnaryCallback, arrayOfNumbers, name) + assert.strictEqual(optimizedTypedUnary.fn(1), 2) + const optimizedTypedTernary = optimizeCallback(typedTernaryCallback, arrayOfNumbers, name) + assert.strictEqual(optimizedTypedTernary.fn(...args), 6) + const optimizedUnaryMatrix = optimizeCallback(unaryCallback, matrixOfNumbers, name) + assert.strictEqual(optimizedUnaryMatrix.fn(1), 2) + const optimizedTernaryMatrix = optimizeCallback(ternaryCallback, matrixOfNumbers, name) + assert.strictEqual(optimizedTernaryMatrix.fn(...args), 6) + const optimizedTypedUnaryMatrix = optimizeCallback(typedUnaryCallback, matrixOfNumbers, name) + assert.strictEqual(optimizedTypedUnaryMatrix.fn(1), 2) + const optimizedTypedTernaryMatrix = optimizeCallback(typedTernaryCallback, matrixOfNumbers, name) + assert.strictEqual(optimizedTypedTernaryMatrix.fn(...args), 6) + const optimizedUnarySparseMatrix = optimizeCallback(unaryCallback, sparseMatrixOfNumbers, name) + assert.strictEqual(optimizedUnarySparseMatrix.fn(1), 2) + const optimizedTernarySparseMatrix = optimizeCallback(ternaryCallback, sparseMatrixOfNumbers, name) + assert.strictEqual(optimizedTernarySparseMatrix.fn(...args), 6) + }) + } + ) -describe('findFirst', function () { - it('should find the first value in a nested array', function () { - assert.strictEqual(findFirst([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]), 1) - assert.strictEqual(findFirst([[[[1], [2]], [[3], [4]]], [[[5], [6]], [[7], [8]]]]), 1) - assert.strictEqual(findFirst([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]]), 1) - }) + describe('findFirst', function () { + it('should find the first value in a nested array', function () { + assert.strictEqual(findFirst([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]), 1) + assert.strictEqual(findFirst([[[[1], [2]], [[3], [4]]], [[[5], [6]], [[7], [8]]]]), 1) + assert.strictEqual(findFirst([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]]), 1) + }) - it('should find the first value in a matrix', function () { - assert.strictEqual(findFirst(math.matrix([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])), 1) - assert.strictEqual(findFirst(math.matrix([[[[1], [2]], [[3], [4]]], [[[5], [6]], [[7], [8]]]])), 1) - assert.strictEqual(findFirst(math.matrix([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]])), 1) - }) - it('should return undefined for an empty array or matrix', function () { - assert.strictEqual(findFirst([]), undefined) - assert.strictEqual(findFirst(math.matrix([])), undefined) - }) - it('should find the first value in a jagged array if the first element is empty', function () { - assert.strictEqual(findFirst([[], [1, 2], [3, 4]]), 1) - assert.strictEqual(findFirst([[], [[1], [2]], [[3], [4]]]), 1) - assert.strictEqual(findFirst([[], [[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]]), 1) + it('should find the first value in a matrix', function () { + assert.strictEqual(findFirst(math.matrix([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])), 1) + assert.strictEqual(findFirst(math.matrix([[[[1], [2]], [[3], [4]]], [[[5], [6]], [[7], [8]]]])), 1) + assert.strictEqual(findFirst(math.matrix([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]])), 1) + }) + + it('should find the first value in a sparse matrix', function () { + assert.strictEqual(findFirst(math.matrix([[1, 2], [3, 4]], 'sparse')), 1) + assert.strictEqual(findFirst(math.matrix([[1], [2]], 'sparse')), 1) + assert.strictEqual(findFirst(math.matrix([[1, 2], [3, 4], [5, 6]], 'sparse')), 1) + }) + + it('should return undefined for an empty array or matrix', function () { + assert.strictEqual(findFirst([]), undefined) + assert.strictEqual(findFirst(math.matrix([])), undefined) + }) + + it('should find the first value in a jagged array if the first element is empty', function () { + assert.strictEqual(findFirst([[], [1, 2], [3, 4]]), 1) + assert.strictEqual(findFirst([[], [[1], [2]], [[3], [4]]]), 1) + assert.strictEqual(findFirst([[], [[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]]), 1) + }) }) })