* 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_)
| 13 | * @return {Boolean} Returns true if `A_` is a valid Moore–Penrose inverse of `A` |
| 14 | */ |
| 15 | function 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 | |
| 34 | describe('pinv', function () { |
| 35 | function check (A, A_, strict = false) { |
no test coverage detected
searching dependent graphs…