MCPcopy
hub / github.com/josdejong/mathjs / assertValidPinv

Function assertValidPinv

test/unit-tests/function/matrix/pinv.test.js:15–32  ·  view source on GitHub ↗

* Tests whether `A_` is Moore–Penrose inverse of `A`. * * @param {Matrix | Array} A A two dimensional matrix or array. * @param {Matrix | Array} A_ A two dimensional matrix or array. * * @return {Boolean} Returns true if `A_` is a valid Moore–Penrose inverse of `A`

(A, A_)

Source from the content-addressed store, hash-verified

13 * @return {Boolean} Returns true if `A_` is a valid Moore–Penrose inverse of `A`
14 */
15function assertValidPinv (A, A_) {
16 const Asize = math.size(A).valueOf()
17
18 const rows = Asize[0]
19 const cols = Asize[1]
20
21 // sizes match
22 assert.deepStrictEqual(math.size(A_).valueOf(), [cols, rows])
23
24 // A A_ A = A
25 approxDeepEqual(math.add(math.multiply(A, math.multiply(A_, A)), math.Complex(1, 1)).valueOf(), math.add(A, math.Complex(1, 1)).valueOf())
26 // A_ A A_ = A_
27 approxDeepEqual(math.add(math.multiply(A_, math.multiply(A, A_)), math.Complex(1, 1)).valueOf(), math.add(A_, math.Complex(1, 1)).valueOf())
28 // (A A_)* = A A_
29 approxDeepEqual(math.add(math.ctranspose(math.multiply(A, A_)), math.Complex(1, 1)).valueOf(), math.add(math.multiply(A, A_), math.Complex(1, 1)).valueOf())
30 // (A_ A)* = A_ A
31 approxDeepEqual(math.add(math.ctranspose(math.multiply(A_, A)), math.Complex(1, 1)).valueOf(), math.add(math.multiply(A_, A), math.Complex(1, 1)).valueOf())
32}
33
34describe('pinv', function () {
35 function check (A, A_, strict = false) {

Callers 1

checkFunction · 0.85

Calls 6

approxDeepEqualFunction · 0.90
valueOfMethod · 0.65
sizeMethod · 0.65
addMethod · 0.65
multiplyMethod · 0.65
ctransposeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…