fix(pinv): write a typescript definition and test (#2804)

* fix(pinv): write a typescript definition

* fix(pinv): write a typescript test

* fix(pinv): format types/index.ts

* fix(pinv): format types/index.ts

* fix(pinv): format types/index.d.ts

* fix(pinv): format types/index.ts

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
This commit is contained in:
Hanchai Nonprasart 2022-10-11 16:14:58 +07:00 committed by GitHub
parent 5754478f16
commit 822ea2a1c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

7
types/index.d.ts vendored
View File

@ -1898,6 +1898,13 @@ declare namespace math {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): any
/**
* Calculate the MoorePenrose inverse of a matrix.
* @param x Matrix to be inversed
* @return The inverse of `x`.
*/
pinv<T extends MathType>(x: T): T
/**
* Create an array from a range. By default, the range end is excluded.
* This can be customized by providing an extra parameter includeEnd.

View File

@ -1293,6 +1293,37 @@ Matrices examples
)
)
}
// MoorePenrose inverse
{
assert.ok(
math.deepEqual(
math.pinv([
[1, 2],
[3, 4],
]),
[
[-2, 1],
[1.5, -0.5],
]
)
)
assert.ok(
math.deepEqual(
math.pinv(
math.matrix([
[1, 2],
[3, 4],
])
),
math.matrix([
[-2, 1],
[1.5, -0.5],
])
)
)
assert.ok(math.deepEqual(math.pinv(4), 0.25))
}
}
/*