From 391677f9e0c7cdb39e7511eb48e082a8174cf708 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Thu, 2 Feb 2023 10:32:06 +0100 Subject: [PATCH 1/4] fix #2888: update type definitions of function unit to allow creating a unit from a fraction or complex number --- test/typescript-tests/testTypes.ts | 2 +- types/index.d.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/typescript-tests/testTypes.ts b/test/typescript-tests/testTypes.ts index afa286e4da..f8acd7fc42 100644 --- a/test/typescript-tests/testTypes.ts +++ b/test/typescript-tests/testTypes.ts @@ -1362,7 +1362,7 @@ Math types examples: Type results after multiplying 'MathTypes' with matrices // Unit const a = math.unit(45, 'cm') // 450 mm - const b = math.unit(45, 'cm') // 450 mm + const b = math.unit(math.fraction(90, 2), 'cm') // 450 mm const _r2 = math.multiply(a, b) // 1D JS Array diff --git a/types/index.d.ts b/types/index.d.ts index ce4ba7510c..94b27ef373 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -776,7 +776,7 @@ declare namespace math { * @param unit The unit to be created * @returns The created unit */ - unit(value: number | BigNumber, unit: string): Unit + unit(value: number | BigNumber | Fraction | Complex, unit: string): Unit unit(value: MathCollection, unit: string): Unit[] /************************************************************************* @@ -4397,7 +4397,7 @@ declare namespace math { unit(this: MathJsChain, unit?: string): MathJsChain unit(this: MathJsChain, unit?: string): MathJsChain unit( - this: MathJsChain, + this: MathJsChain, unit?: string ): MathJsChain unit(this: MathJsChain, unit?: string): MathJsChain From 77934348aaac04ed91414eb691420d36d6dffebd Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Thu, 2 Feb 2023 10:33:44 +0100 Subject: [PATCH 2/4] chore: update HISTORY.md --- HISTORY.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 1c8efeeb01..dc0d977330 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,10 @@ # History +# unpublished changes since 11.5.1 + +- Fix #2888: update type definitions of function `unit` to allow creating a + unit from a fraction or complex number. + # 2023-01-31, 11.5.1 - Add type definitions for function `rotationMatrix` (#2860). From 3a77a6fedef52d4633cdd252ce09ac3fc80e7217 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Thu, 2 Feb 2023 12:08:07 +0100 Subject: [PATCH 3/4] Fix #2892: an error in the examples of the embedded help of function `sort` --- HISTORY.md | 1 + src/expression/embeddedDocs/function/matrix/sort.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index dc0d977330..7666c60c2f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,7 @@ - Fix #2888: update type definitions of function `unit` to allow creating a unit from a fraction or complex number. +- Fix #2892: an error in the examples of the embedded help of function `sort`. # 2023-01-31, 11.5.1 diff --git a/src/expression/embeddedDocs/function/matrix/sort.js b/src/expression/embeddedDocs/function/matrix/sort.js index 84b5f4fb86..85447f7265 100644 --- a/src/expression/embeddedDocs/function/matrix/sort.js +++ b/src/expression/embeddedDocs/function/matrix/sort.js @@ -8,7 +8,7 @@ export const sortDocs = { description: 'Sort the items in a matrix. Compare can be a string "asc", "desc", "natural", or a custom sort function.', examples: [ 'sort([5, 10, 1])', - 'sort(["C", "B", "A", "D"])', + 'sort(["C", "B", "A", "D"], "natural")', 'sortByLength(a, b) = size(a)[1] - size(b)[1]', 'sort(["Langdon", "Tom", "Sara"], sortByLength)', 'sort(["10", "1", "2"], "natural")' From 68b4b503f75a554d17e476cdd9205c37aeb4b1b6 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Thu, 2 Feb 2023 12:29:52 +0100 Subject: [PATCH 4/4] Fix #2891: functions `column` and `row` sometimes returning a scalar number --- HISTORY.md | 1 + src/function/matrix/column.js | 6 +++++- src/function/matrix/row.js | 6 +++++- test/unit-tests/function/matrix/column.test.js | 10 ++++++++++ test/unit-tests/function/matrix/row.test.js | 10 ++++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 7666c60c2f..70620c0ffd 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,6 +5,7 @@ - Fix #2888: update type definitions of function `unit` to allow creating a unit from a fraction or complex number. - Fix #2892: an error in the examples of the embedded help of function `sort`. +- Fix #2891: functions `column` and `row` sometimes returning a scalar number. # 2023-01-31, 11.5.1 diff --git a/src/function/matrix/column.js b/src/function/matrix/column.js index bb4f219872..971463729b 100644 --- a/src/function/matrix/column.js +++ b/src/function/matrix/column.js @@ -1,4 +1,5 @@ import { factory } from '../../utils/factory.js' +import { isMatrix } from '../../utils/is.js' import { clone } from '../../utils/object.js' import { validateIndex } from '../../utils/array.js' @@ -51,6 +52,9 @@ export const createColumn = /* #__PURE__ */ factory(name, dependencies, ({ typed const rowRange = range(0, value.size()[0]) const index = new Index(rowRange, column) - return value.subset(index) + const result = value.subset(index) + return isMatrix(result) + ? result + : matrix([[result]]) } }) diff --git a/src/function/matrix/row.js b/src/function/matrix/row.js index 33c3f1b442..e4a25738b5 100644 --- a/src/function/matrix/row.js +++ b/src/function/matrix/row.js @@ -1,4 +1,5 @@ import { factory } from '../../utils/factory.js' +import { isMatrix } from '../../utils/is.js' import { clone } from '../../utils/object.js' import { validateIndex } from '../../utils/array.js' @@ -51,6 +52,9 @@ export const createRow = /* #__PURE__ */ factory(name, dependencies, ({ typed, I const columnRange = range(0, value.size()[1]) const index = new Index(row, columnRange) - return value.subset(index) + const result = value.subset(index) + return isMatrix(result) + ? result + : matrix([[result]]) } }) diff --git a/test/unit-tests/function/matrix/column.test.js b/test/unit-tests/function/matrix/column.test.js index 949bcdc482..d1e11d5725 100644 --- a/test/unit-tests/function/matrix/column.test.js +++ b/test/unit-tests/function/matrix/column.test.js @@ -84,6 +84,16 @@ describe('column', function () { ) }) + it('should return the column of an 1x1 array', function () { + assert.deepStrictEqual(column([[5]], 0), [[5]]) + assert.deepStrictEqual(column([[5, 6, 7]], 0), [[5]]) + }) + + it('should return the column of an 1x1 matrix', function () { + assert.deepStrictEqual(column(matrix([[5]]), 0), matrix([[5]])) + assert.deepStrictEqual(column(matrix([[5, 6, 7]]), 0), matrix([[5]])) + }) + it('should return an empty matrix column', function () { const c = column(m, 2) assert.deepStrictEqual( diff --git a/test/unit-tests/function/matrix/row.test.js b/test/unit-tests/function/matrix/row.test.js index 5ff1faa1c5..c864981ef0 100644 --- a/test/unit-tests/function/matrix/row.test.js +++ b/test/unit-tests/function/matrix/row.test.js @@ -84,6 +84,16 @@ describe('row', function () { ) }) + it('should return the row of an 1x1 array', function () { + assert.deepStrictEqual(row([[5]], 0), [[5]]) + assert.deepStrictEqual(row([[5], [6], [7]], 0), [[5]]) + }) + + it('should return the row of an 1x1 matrix', function () { + assert.deepStrictEqual(row(matrix([[5]]), 0), matrix([[5]])) + assert.deepStrictEqual(row(matrix([[5], [6], [7]]), 0), matrix([[5]])) + }) + it('should return an empty matrix row', function () { const r = row(m, 2) assert.deepStrictEqual(