Skip to content

Commit

Permalink
sqrtm - throw an error for matrices with dimension greater than two (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradLinkowski committed Sep 30, 2020
1 parent f3c4a90 commit becab40
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/function/matrix/sqrtm.js
Expand Up @@ -87,6 +87,10 @@ export const createSqrtm = /* #__PURE__ */ factory(name, dependencies, ({ typed,
'(size: ' + format(size) + ')')
}
}
default:
// Multi dimensional array
throw new RangeError('Matrix must be at most two dimensional ' +
'(size: ' + format(size) + ')')
}
}
})
Expand Down
7 changes: 7 additions & 0 deletions test/unit-tests/function/matrix/sqrtm.test.js
Expand Up @@ -52,6 +52,13 @@ describe('sqrtm', function () {
assert.throws(function () { math.sqrtm([[1, 2, 3], [4, 5, 6]]) }, /Matrix must be square/)
})

it('should throw an error in case of matrices with dimension greater than two', function () {
const errorRegex = /Matrix must be at most two dimensional/
assert.throws(function () { math.sqrtm(math.zeros(1, 1, 1)) }, errorRegex)
assert.throws(function () { math.sqrtm(math.zeros(2, 2, 2)) }, errorRegex)
assert.throws(function () { math.sqrtm(math.zeros(3, 3, 3, 3)) }, errorRegex)
})

it('should LaTeX sqrtm', function () {
const expression = math.parse('sqrtm([[33, 24], [48, 57]])')
assert.strictEqual(expression.toTex(), '{\\begin{bmatrix}33&24\\\\48&57\\\\\\end{bmatrix}}^{\\frac{1}{2}}')
Expand Down

0 comments on commit becab40

Please sign in to comment.