Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0f834fb
Refactor matAlgo14xDs
dvd101x Dec 9, 2025
c9d57a1
Included an algorithm for Array and scalars
dvd101x Dec 9, 2025
d273182
fixed name of the exporter function
dvd101x Dec 9, 2025
fb35b55
Merge branch 'develop' into jagged-arrays
dvd101x Dec 9, 2025
af646a8
Fixed missing variable
dvd101x Dec 12, 2025
57c4cb2
Added tests and removed useMatrixForArrayScalar.js
dvd101x Dec 14, 2025
8e58d2b
added more tests
dvd101x Dec 14, 2025
cdceb79
Added documentation
dvd101x Dec 15, 2025
d67b73d
Added benchmarks
dvd101x Dec 17, 2025
a720b66
Fixed comment to allow for non-rectangular arrays
dvd101x Dec 17, 2025
4a215ed
Define terminology used for nested arrays.
dvd101x Dec 20, 2025
4bdb5ca
Documentation fixes for non-rectangular arrays
dvd101x Dec 20, 2025
8c6c47d
Removed concat and other dependancies from factory functions
dvd101x Dec 20, 2025
47fc7aa
Merge branch 'develop' into jagged-arrays
dvd101x Dec 20, 2025
2130ba6
Merge branch 'develop' into jagged-arrays
dvd101x Jan 8, 2026
0c08fd0
Merge branch 'develop' into jagged-arrays
dvd101x Jan 21, 2026
996a5e7
Merge branch 'develop' into jagged-arrays
dvd101x Feb 18, 2026
cbcb691
Include history of `add`
dvd101x Feb 24, 2026
b409734
Added `dotDivide` history
dvd101x Feb 24, 2026
dd37a16
Added `dotMultiply` history
dvd101x Feb 24, 2026
2ba17c4
Added history of `dotPow`
dvd101x Feb 24, 2026
7851c6c
Added history for `gcd`
dvd101x Feb 24, 2026
eeab295
Added history for `lcm`
dvd101x Feb 24, 2026
e353386
Added history for `mod`
dvd101x Feb 24, 2026
a5c7d8f
Added history for `nthRoot`
dvd101x Feb 24, 2026
471b9a0
Added history for `nthRoot`
dvd101x Feb 24, 2026
58fbad7
Added history for `subtract`
dvd101x Feb 24, 2026
19b3bc2
Added history for `bitAnd`
dvd101x Feb 24, 2026
6992600
Added history for `bitOr` and `bitXor`
dvd101x Feb 24, 2026
f8a0659
Added history to `leftShift`, `rightArithShift` and `rightLogShift`
dvd101x Feb 24, 2026
ac4bf47
Added history for `and`, `or` and `xor`
dvd101x Feb 24, 2026
ffd1e72
Added history of `compare`
dvd101x Feb 24, 2026
e565ada
History for `equal`
dvd101x Feb 24, 2026
76aab1a
History for `larger`
dvd101x Feb 24, 2026
e71bb52
History for `largerEq`
dvd101x Feb 24, 2026
1fab22a
history for `largerEq`
dvd101x Feb 24, 2026
1e62b6c
Add history to `smaller`
dvd101x Feb 24, 2026
4362b6e
History for `smallerEq`
dvd101x Feb 24, 2026
7a58f84
History for `unequal`
dvd101x Feb 24, 2026
c7119db
History for `atan2`
dvd101x Feb 24, 2026
f127054
History for `to`
dvd101x Feb 24, 2026
9c5e98b
Added some missing "`"
dvd101x Feb 24, 2026
a07bfa4
Format
dvd101x Feb 24, 2026
493de05
Changed description from "Iterates" to "Deeply iterates"
dvd101x Feb 24, 2026
0d4a91a
Merge branch 'develop' into jagged-arrays
gwhitney Mar 5, 2026
0563b85
chore: make History format consistent; add test per #3537.
gwhitney Mar 5, 2026
d3d6f0e
Merge branch 'develop' into jagged-arrays
dvd101x Mar 19, 2026
903dbdc
Add test for `optimizeCallbak`. Included unary info for `map`
dvd101x Mar 21, 2026
daf597e
added test for `optimizeCallback
dvd101x Mar 21, 2026
88e1aa7
added more tests to `optimizeCallback`
dvd101x Mar 21, 2026
b520031
Restored capability to map non unary functions.
dvd101x Mar 29, 2026
f260f3c
Added tests to optimize callback findFirst
dvd101x Mar 30, 2026
c25a0ef
Fix tests for optimize callback
dvd101x Mar 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,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.
Expand Down Expand Up @@ -2520,7 +2520,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.
Expand Down Expand Up @@ -3061,7 +3061,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
Expand Down
28 changes: 26 additions & 2 deletions docs/datatypes/matrices.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +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.
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
Expand Down Expand Up @@ -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).

## Non-rectangular arrays

Comment thread
gwhitney marked this conversation as resolved.
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, 4, 5]] // jagged
[[1, 2], 3] // heterogeneous
```

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))
```
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 is mandatory to create a `Matrix`, thus there might be a performance benefit of not converting an `Array` to a `Matrix`.

## Resizing

Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions src/expression/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Node>}} [options] Available options:
Expand Down
11 changes: 4 additions & 7 deletions src/function/arithmetic/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -55,10 +53,9 @@ export const createAdd = /* #__PURE__ */ factory(
*
* History:
*
* v13 Handle bigint arguments
* v11.6 Support matrix broadcasting
* v5.0.3 Support matrices with a `datatype` defined
* v3.8 Allow more than two arguments
* v0.0.2 Created
*
* @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
Expand Down
11 changes: 8 additions & 3 deletions src/function/arithmetic/dotDivide.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,6 +46,12 @@ export const createDotDivide = /* #__PURE__ */ factory(name, dependencies, ({ ty
*
* divide, multiply, dotMultiply
*
* 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`
Expand Down
12 changes: 8 additions & 4 deletions src/function/arithmetic/dotMultiply.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,6 +40,11 @@ export const createDotMultiply = /* #__PURE__ */ factory(name, dependencies, ({
*
* multiply, divide, dotDivide
*
* 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`
Expand Down
11 changes: 8 additions & 3 deletions src/function/arithmetic/dotPow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -52,6 +51,12 @@ export const createDotPow = /* #__PURE__ */ factory(name, dependencies, ({ typed
*
* pow, sqrt, multiply
*
* 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`
Expand Down
9 changes: 8 additions & 1 deletion src/function/arithmetic/gcd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -56,6 +56,13 @@ export const createGcd = /* #__PURE__ */ factory(name, dependencies, ({ typed, m
*
* lcm, xgcd
*
* 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
*/
Expand Down
Loading
Loading