mirror of
https://github.com/Relintai/pmlpp.git
synced 2024-12-22 15:06:47 +01:00
Optimized MLPPMatrix::det a little.
This commit is contained in:
parent
1594cc9c0b
commit
dd179e10d6
@ -1546,10 +1546,6 @@ real_t MLPPMatrix::detb(const Ref<MLPPMatrix> &A, int d) const {
|
||||
ERR_FAIL_COND_V(!A.is_valid(), 0);
|
||||
|
||||
real_t deter = 0;
|
||||
Ref<MLPPMatrix> B;
|
||||
B.instance();
|
||||
B->resize(Size2i(d, d));
|
||||
B->fill(0);
|
||||
|
||||
/* This is the base case in which the input is a 2x2 square matrix.
|
||||
Recursion is performed unless and until we reach this base case,
|
||||
@ -1557,6 +1553,11 @@ real_t MLPPMatrix::detb(const Ref<MLPPMatrix> &A, int d) const {
|
||||
if (d == 2) {
|
||||
return A->element_get(0, 0) * A->element_get(1, 1) - A->element_get(0, 1) * A->element_get(1, 0);
|
||||
} else {
|
||||
Ref<MLPPMatrix> B;
|
||||
B.instance();
|
||||
B->resize(Size2i(d, d));
|
||||
B->fill(0);
|
||||
|
||||
for (int i = 0; i < d; i++) {
|
||||
int sub_i = 0;
|
||||
for (int j = 1; j < d; j++) {
|
||||
@ -1667,9 +1668,13 @@ Ref<MLPPMatrix> MLPPMatrix::adjoint() const {
|
||||
Ref<MLPPMatrix> cof = cofactor(_size.y, i, j);
|
||||
// 1 if even, -1 if odd
|
||||
int sign = (i + j) % 2 == 0 ? 1 : -1;
|
||||
adj->element_set(j, i, sign * cof->det(int(_size.y) - 1));
|
||||
|
||||
real_t d = cof->det(int(_size.y) - 1);
|
||||
|
||||
adj->element_set(j, i, sign * d);
|
||||
}
|
||||
}
|
||||
|
||||
return adj;
|
||||
}
|
||||
void MLPPMatrix::adjointo(Ref<MLPPMatrix> out) const {
|
||||
|
Loading…
Reference in New Issue
Block a user