Skip to content

Commit ec11388

Browse files
committed
Merge branch 'fix/numeric_bigint' of github.com:gwhitney/mathjs into fix/numeric_bigint
2 parents e419d50 + 0891ef5 commit ec11388

File tree

8 files changed

+251
-335
lines changed

8 files changed

+251
-335
lines changed

HISTORY.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# History
22

3+
# unpublished changes since 14.2.1
4+
5+
- Feat: improved performance of function `flatten` (#3354). Thanks @dvd101x.
6+
7+
# 2024-02-05, 14.2.1
8+
9+
- Fix: #3377 remove redundant dependency `@lambdatest/node-tunnel`.
10+
311
# 2024-01-30, 14.2.0
412

513
- Feat: #3041, #3340 rename `apply` to `mapSlices` (#3357). Function

package-lock.json

Lines changed: 201 additions & 292 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mathjs",
3-
"version": "14.2.0",
3+
"version": "14.2.1",
44
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
55
"author": "Jos de Jong <[email protected]> (https://github.com/josdejong)",
66
"homepage": "https://mathjs.org",
@@ -26,7 +26,6 @@
2626
],
2727
"dependencies": {
2828
"@babel/runtime": "^7.25.7",
29-
"@lambdatest/node-tunnel": "^4.0.8",
3029
"complex.js": "^2.2.5",
3130
"decimal.js": "^10.4.3",
3231
"escape-latex": "^1.2.0",
@@ -37,16 +36,16 @@
3736
"typed-function": "^4.2.1"
3837
},
3938
"devDependencies": {
40-
"@babel/core": "7.26.0",
39+
"@babel/core": "7.26.7",
4140
"@babel/plugin-transform-object-assign": "7.25.9",
4241
"@babel/plugin-transform-optional-catch-binding": "7.25.9",
4342
"@babel/plugin-transform-runtime": "7.25.9",
44-
"@babel/preset-env": "7.26.0",
43+
"@babel/preset-env": "7.26.7",
4544
"@babel/register": "7.25.9",
4645
"@types/assert": "1.5.11",
4746
"@types/mocha": "10.0.10",
48-
"@typescript-eslint/eslint-plugin": "8.21.0",
49-
"@typescript-eslint/parser": "8.21.0",
47+
"@typescript-eslint/eslint-plugin": "8.23.0",
48+
"@typescript-eslint/parser": "8.23.0",
5049
"assert": "2.1.0",
5150
"babel-loader": "9.2.1",
5251
"c8": "10.1.3",
@@ -91,7 +90,7 @@
9190
"process": "0.11.10",
9291
"sinon": "19.0.2",
9392
"sylvester": "0.0.21",
94-
"tinybench": "3.1.0",
93+
"tinybench": "3.1.1",
9594
"ts-node": "10.9.2",
9695
"typescript": "5.7.3",
9796
"webpack": "5.97.1",

src/expression/embeddedDocs/function/matrix/mapSlices.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const mapSlicesDocs = {
88
examples: [
99
'A = [[1, 2], [3, 4]]',
1010
'mapSlices(A, 1, sum)', // returns [4, 6]
11-
'mapSlices(A, 2, product)' // returns [2, 12]
11+
'mapSlices(A, 2, prod)' // returns [2, 12]
1212
],
1313
seealso: ['map', 'forEach']
1414
}

src/function/matrix/flatten.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const createFlatten = /* #__PURE__ */ factory(name, dependencies, ({ type
3232
Matrix: function (x) {
3333
// Return the same matrix type as x (Dense or Sparse Matrix)
3434
// Return the same data type as x
35-
return x.create(flattenArray(x.toArray()), x.datatype())
35+
return x.create(flattenArray(x.valueOf()), x.datatype())
3636
}
3737
})
3838
})

src/utils/array.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { deepStrictEqual } from './object.js'
1010
* This function checks the size of the first entry, it does not validate
1111
* whether all dimensions match. (use function `validate` for that)
1212
* @param {Array} x
13-
* @Return {Number[]} size
13+
* @return {number[]} size
1414
*/
1515
export function arraySize (x) {
1616
const s = []
@@ -28,7 +28,7 @@ export function arraySize (x) {
2828
* has a size corresponding to the provided size array.
2929
* @param {Array} array Array to be validated
3030
* @param {number[]} size Array with the size of each dimension
31-
* @param {number} dim Current dimension
31+
* @param {number} dim Current dimension
3232
* @throws DimensionError
3333
* @private
3434
*/
@@ -51,7 +51,7 @@ function _validate (array, size, dim) {
5151
_validate(array[i], size, dimNext)
5252
}
5353
} else {
54-
// last dimension. none of the childs may be an array
54+
// last dimension. none of the children may be an array
5555
for (i = 0; i < len; i++) {
5656
if (Array.isArray(array[i])) {
5757
throw new DimensionError(size.length + 1, size.length, '>')
@@ -82,7 +82,7 @@ export function validate (array, size) {
8282

8383
/**
8484
* Validate whether the source of the index matches the size of the Array
85-
* @param {Array | Matrix} array Array to be validated
85+
* @param {Array | Matrix} value Array to be validated
8686
* @param {Index} index Index with the source information to validate
8787
* @throws DimensionError
8888
*/
@@ -113,8 +113,8 @@ export function validateIndex (index, length) {
113113
}
114114

115115
/**
116-
* Test if and index has empty values
117-
* @param {number} index Zero-based index
116+
* Test if an index has empty values
117+
* @param {Index} index Zero-based index
118118
*/
119119
export function isEmptyIndex (index) {
120120
for (let i = 0; i < index._dimensions.length; ++i) {
@@ -140,7 +140,7 @@ export function isEmptyIndex (index) {
140140
* Resize a multi dimensional array. The resized array is returned.
141141
* @param {Array | number} array Array to be resized
142142
* @param {number[]} size Array with the size of each dimension
143-
* @param {*} [defaultValue=0] Value to be filled in in new entries,
143+
* @param {*} [defaultValue=0] Value to be filled in new entries,
144144
* zero by default. Specify for example `null`,
145145
* to clearly see entries that are not explicitly
146146
* set.
@@ -180,7 +180,7 @@ export function resize (array, size, defaultValue) {
180180
* @param {Array} array Array to be resized
181181
* @param {number[]} size Array with the size of each dimension
182182
* @param {number} dim Current dimension
183-
* @param {*} [defaultValue] Value to be filled in in new entries,
183+
* @param {*} [defaultValue] Value to be filled in new entries,
184184
* undefined by default.
185185
* @private
186186
*/
@@ -283,7 +283,7 @@ export function reshape (array, sizes) {
283283

284284
/**
285285
* Replaces the wildcard -1 in the sizes array.
286-
* @param {number[]} sizes List of sizes for each dimension. At most on wildcard.
286+
* @param {number[]} sizes List of sizes for each dimension. At most one wildcard.
287287
* @param {number} currentLength Number of elements in the array.
288288
* @throws {Error} If more than one wildcard or unable to replace it.
289289
* @returns {number[]} The sizes array with wildcard replaced.
@@ -333,7 +333,7 @@ function _reshape (array, sizes) {
333333
// testing if there are enough elements for the requested shape
334334
let tmpArray = array
335335
let tmpArray2
336-
// for each dimensions starting by the last one and ignoring the first one
336+
// for each dimension starting by the last one and ignoring the first one
337337
for (let sizeIndex = sizes.length - 1; sizeIndex > 0; sizeIndex--) {
338338
const size = sizes[sizeIndex]
339339
tmpArray2 = []
@@ -408,7 +408,7 @@ function _squeeze (array, dims, dim) {
408408
/**
409409
* Unsqueeze a multi dimensional array: add dimensions when missing
410410
*
411-
* Paramter `size` will be mutated to match the new, unqueezed matrix size.
411+
* Parameter `size` will be mutated to match the new, unsqueezed matrix size.
412412
*
413413
* @param {Array} array
414414
* @param {number} dims Desired number of dimensions of the array
@@ -442,7 +442,7 @@ export function unsqueeze (array, dims, outer, size) {
442442
* @param {Array} array
443443
* @param {number} dims Required number of dimensions
444444
* @param {number} dim Current dimension
445-
* @returns {Array | *} Returns the squeezed array
445+
* @returns {Array | *} Returns the unsqueezed array
446446
* @private
447447
*/
448448
function _unsqueeze (array, dims, dim) {
@@ -517,7 +517,7 @@ export function filter (array, callback) {
517517
}
518518

519519
/**
520-
* Filter values in a callback given a regular expression
520+
* Filter values in an array given a regular expression
521521
* @param {Array} array
522522
* @param {RegExp} regexp
523523
* @return {Array} Returns the filtered array
@@ -634,7 +634,7 @@ export function getArrayDataType (array, typeOf) {
634634

635635
/**
636636
* Return the last item from an array
637-
* @param {array}
637+
* @param {Array} array
638638
* @returns {*}
639639
*/
640640
export function last (array) {
@@ -643,16 +643,16 @@ export function last (array) {
643643

644644
/**
645645
* Get all but the last element of array.
646-
* @param {array}
647-
* @returns {*}
646+
* @param {Array} array
647+
* @returns {Array}
648648
*/
649649
export function initial (array) {
650650
return array.slice(0, array.length - 1)
651651
}
652652

653653
/**
654654
* Recursively concatenate two matrices.
655-
* The contents of the matrices is not cloned.
655+
* The contents of the matrices are not cloned.
656656
* @param {Array} a Multi dimensional array
657657
* @param {Array} b Multi dimensional array
658658
* @param {number} concatDim The dimension on which to concatenate (zero-based)
@@ -682,8 +682,8 @@ function concatRecursive (a, b, concatDim, dim) {
682682
* Concatenates many arrays in the specified direction
683683
* @param {...Array} arrays All the arrays to concatenate
684684
* @param {number} concatDim The dimension on which to concatenate (zero-based)
685-
* @returns
686-
*/
685+
* @returns {Array}
686+
*/
687687
export function concat () {
688688
const arrays = Array.prototype.slice.call(arguments, 0, -1)
689689
const concatDim = Array.prototype.slice.call(arguments, -1)
@@ -699,9 +699,9 @@ export function concat () {
699699
}
700700

701701
/**
702-
* Receives two or more sizes and get's the broadcasted size for both.
702+
* Receives two or more sizes and gets the broadcasted size for both.
703703
* @param {...number[]} sizes Sizes to broadcast together
704-
* @returns
704+
* @returns {number[]} The broadcasted size
705705
*/
706706
export function broadcastSizes (...sizes) {
707707
const dimensions = sizes.map((s) => s.length)
@@ -736,17 +736,17 @@ export function checkBroadcastingRules (size, toSize) {
736736
const n = N - dim + j
737737
if ((size[j] < toSize[n] && size[j] > 1) || (size[j] > toSize[n])) {
738738
throw new Error(
739-
`shape missmatch: missmatch is found in arg with shape (${size}) not possible to broadcast dimension ${dim} with size ${size[j]} to size ${toSize[n]}`
739+
`shape mismatch: mismatch is found in arg with shape (${size}) not possible to broadcast dimension ${dim} with size ${size[j]} to size ${toSize[n]}`
740740
)
741741
}
742742
}
743743
}
744744

745745
/**
746746
* Broadcasts a single array to a certain size
747-
* @param {array} array Array to be broadcasted
747+
* @param {Array} array Array to be broadcasted
748748
* @param {number[]} toSize Size to broadcast the array
749-
* @returns The broadcasted array
749+
* @returns {Array} The broadcasted array
750750
*/
751751
export function broadcastTo (array, toSize) {
752752
let Asize = arraySize(array)
@@ -778,11 +778,11 @@ export function broadcastTo (array, toSize) {
778778
/**
779779
* Broadcasts arrays and returns the broadcasted arrays in an array
780780
* @param {...Array | any} arrays
781-
* @returns
781+
* @returns {Array[]} The broadcasted arrays
782782
*/
783783
export function broadcastArrays (...arrays) {
784784
if (arrays.length === 0) {
785-
throw new Error('Insuficient number of argumnets in function broadcastArrays')
785+
throw new Error('Insufficient number of arguments in function broadcastArrays')
786786
}
787787
if (arrays.length === 1) {
788788
return arrays[0]
@@ -795,11 +795,11 @@ export function broadcastArrays (...arrays) {
795795
}
796796

797797
/**
798-
* stretches a matrix up to a certain size in a certain dimension
798+
* Stretches a matrix up to a certain size in a certain dimension
799799
* @param {Array} arrayToStretch
800800
* @param {number[]} sizeToStretch
801801
* @param {number} dimToStretch
802-
* @returns
802+
* @returns {Array} The stretched array
803803
*/
804804
export function stretch (arrayToStretch, sizeToStretch, dimToStretch) {
805805
return concat(...Array(sizeToStretch).fill(arrayToStretch), dimToStretch)
@@ -809,13 +809,13 @@ export function stretch (arrayToStretch, sizeToStretch, dimToStretch) {
809809
* Retrieves a single element from an array given an index.
810810
*
811811
* @param {Array} array - The array from which to retrieve the value.
812-
* @param {Array<number>} idx - An array of indices specifying the position of the desired element in each dimension.
812+
* @param {Array<number>} index - An array of indices specifying the position of the desired element in each dimension.
813813
* @returns {*} - The value at the specified position in the array.
814814
*
815815
* @example
816816
* const arr = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]];
817817
* const index = [1, 0, 1];
818-
* console.log(getValue(arr, index)); // 6
818+
* console.log(get(arr, index)); // 6
819819
*/
820820
export function get (array, index) {
821821
if (!Array.isArray(array)) { throw new Error('Array expected') }
@@ -849,7 +849,7 @@ export function recurse (value, index, array, callback) {
849849
/**
850850
* Deep clones a multidimensional array
851851
* @param {Array} array
852-
* @returns cloned array
852+
* @returns {Array} cloned array
853853
*/
854854
export function clone (array) {
855855
return Object.assign([], array)

src/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const version = '14.2.0'
1+
export const version = '14.2.1'
22
// Note: This file is automatically generated when building math.js.
33
// Changes made in this file will be overwritten.

test/unit-tests/utils/array.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ describe('util.array', function () {
195195
[0, 0],
196196
[0, 0]
197197
])
198-
// TODO: would be nicer if this returns uninit everwhere and not undefined on some places
198+
// TODO: would be nicer if this returns uninit everywhere and not undefined in some places
199199
})
200200

201201
it('should resize a 2 dimensional array to 1 dimensional', function () {
@@ -604,7 +604,7 @@ describe('util.array', function () {
604604
})
605605

606606
it('should throw an error when the broadcasting rules are not followed', function () {
607-
assert.throws(function () { broadcastSizes([2, 2], [3, 2]) }, /Error: shape missmatch: missmatch is found in arg with shape.*/)
607+
assert.throws(function () { broadcastSizes([2, 2], [3, 2]) }, /Error: shape mismatch: mismatch is found in arg with shape.*/)
608608
})
609609
})
610610

0 commit comments

Comments
 (0)