Skip to content

Commit edd789f

Browse files
Merge branch 'develop' of github.com:josdejong/mathjs into develop
2 parents 739387e + 68b4b50 commit edd789f

File tree

8 files changed

+41
-6
lines changed

8 files changed

+41
-6
lines changed

HISTORY.md

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

3+
# unpublished changes since 11.5.1
4+
5+
- Fix #2888: update type definitions of function `unit` to allow creating a
6+
unit from a fraction or complex number.
7+
- Fix #2892: an error in the examples of the embedded help of function `sort`.
8+
- Fix #2891: functions `column` and `row` sometimes returning a scalar number.
9+
310
# 2023-01-31, 11.5.1
411

512
- Add type definitions for function `rotationMatrix` (#2860).

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const sortDocs = {
88
description: 'Sort the items in a matrix. Compare can be a string "asc", "desc", "natural", or a custom sort function.',
99
examples: [
1010
'sort([5, 10, 1])',
11-
'sort(["C", "B", "A", "D"])',
11+
'sort(["C", "B", "A", "D"], "natural")',
1212
'sortByLength(a, b) = size(a)[1] - size(b)[1]',
1313
'sort(["Langdon", "Tom", "Sara"], sortByLength)',
1414
'sort(["10", "1", "2"], "natural")'

src/function/matrix/column.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { factory } from '../../utils/factory.js'
2+
import { isMatrix } from '../../utils/is.js'
23
import { clone } from '../../utils/object.js'
34
import { validateIndex } from '../../utils/array.js'
45

@@ -51,6 +52,9 @@ export const createColumn = /* #__PURE__ */ factory(name, dependencies, ({ typed
5152

5253
const rowRange = range(0, value.size()[0])
5354
const index = new Index(rowRange, column)
54-
return value.subset(index)
55+
const result = value.subset(index)
56+
return isMatrix(result)
57+
? result
58+
: matrix([[result]])
5559
}
5660
})

src/function/matrix/row.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { factory } from '../../utils/factory.js'
2+
import { isMatrix } from '../../utils/is.js'
23
import { clone } from '../../utils/object.js'
34
import { validateIndex } from '../../utils/array.js'
45

@@ -51,6 +52,9 @@ export const createRow = /* #__PURE__ */ factory(name, dependencies, ({ typed, I
5152

5253
const columnRange = range(0, value.size()[1])
5354
const index = new Index(row, columnRange)
54-
return value.subset(index)
55+
const result = value.subset(index)
56+
return isMatrix(result)
57+
? result
58+
: matrix([[result]])
5559
}
5660
})

test/typescript-tests/testTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ Math types examples: Type results after multiplying 'MathTypes' with matrices
13621362

13631363
// Unit
13641364
const a = math.unit(45, 'cm') // 450 mm
1365-
const b = math.unit(45, 'cm') // 450 mm
1365+
const b = math.unit(math.fraction(90, 2), 'cm') // 450 mm
13661366
const _r2 = math.multiply(a, b)
13671367

13681368
// 1D JS Array

test/unit-tests/function/matrix/column.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ describe('column', function () {
8484
)
8585
})
8686

87+
it('should return the column of an 1x1 array', function () {
88+
assert.deepStrictEqual(column([[5]], 0), [[5]])
89+
assert.deepStrictEqual(column([[5, 6, 7]], 0), [[5]])
90+
})
91+
92+
it('should return the column of an 1x1 matrix', function () {
93+
assert.deepStrictEqual(column(matrix([[5]]), 0), matrix([[5]]))
94+
assert.deepStrictEqual(column(matrix([[5, 6, 7]]), 0), matrix([[5]]))
95+
})
96+
8797
it('should return an empty matrix column', function () {
8898
const c = column(m, 2)
8999
assert.deepStrictEqual(

test/unit-tests/function/matrix/row.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ describe('row', function () {
8484
)
8585
})
8686

87+
it('should return the row of an 1x1 array', function () {
88+
assert.deepStrictEqual(row([[5]], 0), [[5]])
89+
assert.deepStrictEqual(row([[5], [6], [7]], 0), [[5]])
90+
})
91+
92+
it('should return the row of an 1x1 matrix', function () {
93+
assert.deepStrictEqual(row(matrix([[5]]), 0), matrix([[5]]))
94+
assert.deepStrictEqual(row(matrix([[5], [6], [7]]), 0), matrix([[5]]))
95+
})
96+
8797
it('should return an empty matrix row', function () {
8898
const r = row(m, 2)
8999
assert.deepStrictEqual(

types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ declare namespace math {
781781
* @param unit The unit to be created
782782
* @returns The created unit
783783
*/
784-
unit(value: number | BigNumber, unit: string): Unit
784+
unit(value: number | BigNumber | Fraction | Complex, unit: string): Unit
785785
unit(value: MathCollection, unit: string): Unit[]
786786

787787
/*************************************************************************
@@ -4402,7 +4402,7 @@ declare namespace math {
44024402
unit(this: MathJsChain<string>, unit?: string): MathJsChain<Unit>
44034403
unit(this: MathJsChain<Unit>, unit?: string): MathJsChain<Unit>
44044404
unit(
4405-
this: MathJsChain<number | BigNumber>,
4405+
this: MathJsChain<number | BigNumber | Fraction | Complex>,
44064406
unit?: string
44074407
): MathJsChain<Unit>
44084408
unit(this: MathJsChain<MathCollection>, unit?: string): MathJsChain<Unit[]>

0 commit comments

Comments
 (0)