comparison UnitTestsSources/UnitTestsMain.cpp @ 164:432b1f812d14 wasm

inversion of general matrices
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 14 Feb 2018 16:49:43 +0100
parents 8c5b24892ed2
children 8d50e6be565d
comparison
equal deleted inserted replaced
163:8c5b24892ed2 164:432b1f812d14
439 439
440 TEST(Matrix, Inverse1) 440 TEST(Matrix, Inverse1)
441 { 441 {
442 OrthancStone::Matrix a, b; 442 OrthancStone::Matrix a, b;
443 443
444 ASSERT_THROW(OrthancStone::LinearAlgebra::InvertMatrix(b, a), Orthanc::OrthancException); 444 a.resize(0, 0);
445 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
446 ASSERT_EQ(0u, b.size1());
447 ASSERT_EQ(0u, b.size2());
445 448
446 a.resize(2, 3); 449 a.resize(2, 3);
447 ASSERT_THROW(OrthancStone::LinearAlgebra::InvertMatrix(b, a), Orthanc::OrthancException); 450 ASSERT_THROW(OrthancStone::LinearAlgebra::InvertMatrix(b, a), Orthanc::OrthancException);
448 451
449 a.resize(1, 1); 452 a.resize(1, 1);
550 ASSERT_DOUBLE_EQ(0, b(2, 1)); 553 ASSERT_DOUBLE_EQ(0, b(2, 1));
551 ASSERT_DOUBLE_EQ(-1, b(2, 2)); 554 ASSERT_DOUBLE_EQ(-1, b(2, 2));
552 } 555 }
553 556
554 557
558 TEST(Matrix, Inverse4)
559 {
560 OrthancStone::Matrix a, b;
561 a.resize(4, 4);
562 a(0, 0) = 2;
563 a(0, 1) = 1;
564 a(0, 2) = 2;
565 a(0, 3) = -3;
566 a(1, 0) = -2;
567 a(1, 1) = 2;
568 a(1, 2) = -1;
569 a(1, 3) = -1;
570 a(2, 0) = 2;
571 a(2, 1) = 2;
572 a(2, 2) = -3;
573 a(2, 3) = -1;
574 a(3, 0) = 3;
575 a(3, 1) = -2;
576 a(3, 2) = -3;
577 a(3, 3) = -1;
578
579 OrthancStone::LinearAlgebra::InvertMatrix(b, a);
580 ASSERT_EQ(4u, b.size1());
581 ASSERT_EQ(4u, b.size2());
582
583 b *= 134.0; // This is the determinant
584
585 ASSERT_DOUBLE_EQ(8, b(0, 0));
586 ASSERT_DOUBLE_EQ(-44, b(0, 1));
587 ASSERT_DOUBLE_EQ(30, b(0, 2));
588 ASSERT_DOUBLE_EQ(-10, b(0, 3));
589 ASSERT_DOUBLE_EQ(2, b(1, 0));
590 ASSERT_DOUBLE_EQ(-11, b(1, 1));
591 ASSERT_DOUBLE_EQ(41, b(1, 2));
592 ASSERT_DOUBLE_EQ(-36, b(1, 3));
593 ASSERT_DOUBLE_EQ(16, b(2, 0));
594 ASSERT_DOUBLE_EQ(-21, b(2, 1));
595 ASSERT_DOUBLE_EQ(-7, b(2, 2));
596 ASSERT_DOUBLE_EQ(-20, b(2, 3));
597 ASSERT_DOUBLE_EQ(-28, b(3, 0));
598 ASSERT_DOUBLE_EQ(-47, b(3, 1));
599 ASSERT_DOUBLE_EQ(29, b(3, 2));
600 ASSERT_DOUBLE_EQ(-32, b(3, 3));
601 }
602
603
555 int main(int argc, char **argv) 604 int main(int argc, char **argv)
556 { 605 {
557 Orthanc::Logging::Initialize(); 606 Orthanc::Logging::Initialize();
558 Orthanc::Logging::EnableInfoLevel(true); 607 Orthanc::Logging::EnableInfoLevel(true);
559 608