diff --git a/ChangeLog b/ChangeLog index 30436b2..2258cf8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,112 +1,158 @@ +2017-01-09 16:07 + + * [r24] COPYING, ChangeLog, INSTALL, src/matrix.hxx, + test/matricxx.cxx: + fix bug in sign comparision + +2017-01-08 08:54 + + * [r23] bootstrap.sh, debian/changelog.in: + rebuilt debian/changelog.in + +2017-01-07 13:31 + + * [r22] ChangeLog, ax_init_standard_project.m4, bootstrap.sh, + build-in-docker.conf, build-in-docker.sh, debian/control.in, + doc/plantuml.jar[ADD], resolve-debbuilddeps.sh, + resolve-rpmbuilddeps.sh: + build system updated + +2016-09-02 08:44 + + * [r21] configure.ac: + fixed project url + 2016-08-28 07:58 - * COPYING, ChangeLog, INSTALL, ax_init_standard_project.m4, - bootstrap.sh: documentation fixed + * [r20] COPYING, ChangeLog, INSTALL, ax_init_standard_project.m4, + bootstrap.sh: + documentation fixed 2016-08-26 14:10 - * COPYING, INSTALL, ax_init_standard_project.m4, bootstrap.sh, - doc/doxyfile.in: updated documentation build + * [r19] COPYING, INSTALL, ax_init_standard_project.m4, + bootstrap.sh, doc/doxyfile.in: + updated documentation build 2016-08-25 19:53 - * configure.ac, debian/control.in, src/matrix.hxx, test/basic.cxx, - test/makefile.am, test/matricxx.cxx: documentation updated + * [r18] configure.ac, debian/control.in, src/matrix.hxx, + test/basic.cxx[DEL], test/makefile.am, test/matricxx.cxx[CPY]: + documentation updated 2016-08-25 18:56 - * README, ax_init_standard_project.m4, bootstrap.sh, configure.ac, - doc/header.html.in, doc/style.css: documentation anhanced + * [r17] README, ax_init_standard_project.m4, bootstrap.sh, + configure.ac, doc/header.html.in, doc/style.css: + documentation anhanced 2016-08-25 18:02 - * COPYING, ChangeLog, INSTALL, README, ax_init_standard_project.m4, - doc/doxyfile.in, doc/footer.html.in, doc/header.html.in, - doc/style.css, test/matricxx.cxx: documentation anhanced + * [r16] COPYING, ChangeLog, INSTALL, README, + ax_init_standard_project.m4, doc/doxyfile.in, + doc/footer.html.in[ADD], doc/header.html.in[ADD], + doc/style.css[ADD], test/matricxx.cxx[ADD]: + documentation anhanced 2016-08-25 15:00 - * README, ax_init_standard_project.m4, bootstrap.sh, - doc/doxyfile.in, src/matrix.hxx: improved doxygen + * [r15] README, ax_init_standard_project.m4, bootstrap.sh, + doc/doxyfile.in, src/matrix.hxx: + improved doxygen 2016-08-24 09:42 - * src/libmatricxx.pc.in: PKG_REQUIREMENTS is undefined + * [r14] src/libmatricxx.pc.in: + PKG_REQUIREMENTS is undefined 2016-08-23 13:58 - * debian/control.in, src/makefile.am, src/matrix.hxx, - test/basic.cxx, test/makefile.am: stream any size of matrix + * [r13] debian/control.in, src/makefile.am, src/matrix.hxx, + test/basic.cxx, test/makefile.am: + stream any size of matrix 2016-08-23 13:09 - * configure.ac, src/matrix.hxx, test/basic.cxx: works perfectly, - fully tested + * [r12] configure.ac, src/matrix.hxx, test/basic.cxx: + works perfectly, fully tested 2016-08-22 15:04 - * COPYING, INSTALL, src/matrix.hxx, test/basic.cxx: inverse tested + * [r11] COPYING, INSTALL, src/matrix.hxx, test/basic.cxx: + inverse tested 2016-08-22 07:07 - * ChangeLog, src/matrix.hxx, test/basic.cxx: inverse does not work - yet + * [r10] ChangeLog, src/matrix.hxx, test/basic.cxx: + inverse does not work yet 2016-08-19 16:07 - * COPYING, ChangeLog, INSTALL, ax_cxx_compile_stdcxx_11.m4, - ax_init_standard_project.m4, makefile_test.inc.am: fix C++11 - detection + * [r9] COPYING, ChangeLog, INSTALL, ax_cxx_compile_stdcxx_11.m4, + ax_init_standard_project.m4, makefile_test.inc.am: + fix C++11 detection 2016-08-19 14:52 - * COPYING, INSTALL, ax_cxx_compile_stdcxx_11.m4, - ax_init_standard_project.m4, bootstrap.sh, makefile_test.inc.am, - src/matrix.hxx, test/basic.cxx: more operators more tests + * [r8] COPYING, INSTALL, ax_cxx_compile_stdcxx_11.m4, + ax_init_standard_project.m4, bootstrap.sh, + makefile_test.inc.am[ADD], src/matrix.hxx, test/basic.cxx: + more operators more tests 2016-08-18 22:03 - * COPYING, ChangeLog, INSTALL, src/matrix.hxx: more operators + * [r7] COPYING, ChangeLog, INSTALL, src/matrix.hxx: + more operators 2016-08-17 07:26 - * configure.ac: only requires c++11 + * [r6] configure.ac: + only requires c++11 2016-08-16 14:41 - * COPYING, INSTALL, ax_init_standard_project.m4, configure.ac, - src/matrix.hxx, test/basic.cxx: remove redundancy, collect common - functionality in base class + * [r5] COPYING, INSTALL, ax_init_standard_project.m4, configure.ac, + src/matrix.hxx, test/basic.cxx: + remove redundancy, collect common functionality in base class 2016-08-08 20:03 - * src/matrix.hxx, test/basic.cxx: more operator, more checks passed + * [r4] src/matrix.hxx, test/basic.cxx: + more operator, more checks passed 2016-08-03 18:43 - * configure.ac, test/makefile.am: all tests passed + * [r3] configure.ac, test/makefile.am: + all tests passed 2016-08-03 18:39 - * COPYING, ChangeLog, INSTALL, ax_cxx_compile_stdcxx_11.m4, - ax_init_standard_project.m4, configure.ac, examples/makefile.am, - examples/matrix-sample.cxx, src/makefile.am, src/matrix.hxx, - test/basic.cxx, test/makefile.am: first approach including first - tests + * [r2] COPYING[ADD], ChangeLog, INSTALL[ADD], + ax_cxx_compile_stdcxx_11.m4, ax_init_standard_project.m4, + configure.ac, examples/makefile.am, + examples/matrix-sample.cxx[ADD], src/makefile.am, + src/matrix.hxx[ADD], test/basic.cxx[ADD], test/makefile.am: + first approach including first tests 2016-07-30 08:50 - * ., AUTHORS, ChangeLog, NEWS, README, autogen.sh, ax_check_qt.m4, - ax_cxx_compile_stdcxx_11.m4, ax_init_standard_project.m4, - bootstrap.sh, build-in-docker.conf, build-in-docker.sh, - build-resource-file.sh, configure.ac, debian, - debian/changelog.in, debian/compat, debian/control.in, - debian/docs, debian/libmatricxx-dev.install, - debian/libmatricxx.install, debian/rules, doc, doc/doxyfile.in, - doc/makefile.am, examples, examples/makefile.am, - libmatricxx.desktop.in, libmatricxx.spec.in, - mac-create-app-bundle.sh, makefile.am, resolve-debbuilddeps.sh, - resolve-rpmbuilddeps.sh, sql-to-dot.sed, src, - src/libmatricxx.pc.in, src/makefile.am, src/version.cxx, - src/version.hxx, test, test/makefile.am: initial project + * [r1] .[ADD], AUTHORS[ADD], ChangeLog[ADD], NEWS[ADD], + README[ADD], autogen.sh[ADD], ax_check_qt.m4[ADD], + ax_cxx_compile_stdcxx_11.m4[ADD], + ax_init_standard_project.m4[ADD], bootstrap.sh[ADD], + build-in-docker.conf[ADD], build-in-docker.sh[ADD], + build-resource-file.sh[ADD], configure.ac[ADD], debian[ADD], + debian/changelog.in[ADD], debian/compat[ADD], + debian/control.in[ADD], debian/docs[ADD], + debian/libmatricxx-dev.install[ADD], + debian/libmatricxx.install[ADD], debian/rules[ADD], doc[ADD], + doc/doxyfile.in[ADD], doc/makefile.am[ADD], examples[ADD], + examples/makefile.am[ADD], libmatricxx.desktop.in[ADD], + libmatricxx.spec.in[ADD], mac-create-app-bundle.sh[ADD], + makefile.am[ADD], resolve-debbuilddeps.sh[ADD], + resolve-rpmbuilddeps.sh[ADD], sql-to-dot.sed[ADD], src[ADD], + src/libmatricxx.pc.in[ADD], src/makefile.am[ADD], + src/version.cxx[ADD], src/version.hxx[ADD], test[ADD], + test/makefile.am[ADD]: + initial project diff --git a/src/matrix.hxx b/src/matrix.hxx index 2ddff95..9f93a7b 100644 --- a/src/matrix.hxx +++ b/src/matrix.hxx @@ -282,6 +282,26 @@ template class MatrixBase { return *this; } + /// Matrix P-Norm + /** Matrix p-norm is defined as: + + @f[ + \Vert A \Vert_p = \left( \sum_{i=1}^m \sum_{j=1}^n |a_{ij}|^p \right)^{1/p} + @f] + + For a vector, norm(2) is equal to the length of the vector. + + @see https://en.wikipedia.org/wiki/Matrix_norm */ + long double norm(long double p=2) const { + long double res(0); + for (const TYPE *v((const TYPE*)(_c)+SIZE); v>(const TYPE*)(_c);) { + std::cout<<"res="< o(m); CPPUNIT_ASSERT_EQUAL((T)3*o, m.apply([](T& t){t*=3;})); } + template + void norm() { + Matrix m1(1, -1, 1, + -1, 1, -1, + 1, 1, -1); + Matrix m2(-1, 3, 2, + -2, 0, -3, + 2, 1, -2); + Matrix m3(0, 3, 0, + -1, 0, 2, + 0, -3, 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, m1.norm(), 0.00001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(6.0, m2.norm(), 0.00001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0, m3.norm(3), 0.00001); + } template void gauss() { Matrix m(2, -2, 4, @@ -332,92 +347,113 @@ class TemplateMatrixTest: public CppUnit::TestFixture { CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray1); + CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); + CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray3); CPPUNIT_TEST(initFromArray3); CPPUNIT_TEST(initFromArray3); CPPUNIT_TEST(initFromArray3); CPPUNIT_TEST(initFromArray3); CPPUNIT_TEST(initFromArray3); + CPPUNIT_TEST(initFromArray3); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); + CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); + CPPUNIT_TEST(access); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); + CPPUNIT_TEST(equality); CPPUNIT_TEST(operator_plus); CPPUNIT_TEST(operator_plus); CPPUNIT_TEST(operator_plus); CPPUNIT_TEST(operator_plus); CPPUNIT_TEST(operator_plus); CPPUNIT_TEST(operator_plus); + CPPUNIT_TEST(operator_plus); CPPUNIT_TEST(operator_minus); CPPUNIT_TEST(operator_minus); CPPUNIT_TEST(operator_minus); CPPUNIT_TEST(operator_minus); CPPUNIT_TEST(operator_minus); CPPUNIT_TEST(operator_minus); + CPPUNIT_TEST(operator_minus); CPPUNIT_TEST(scalar_mult); CPPUNIT_TEST(scalar_mult); CPPUNIT_TEST(scalar_mult); CPPUNIT_TEST(scalar_mult); CPPUNIT_TEST(scalar_mult); CPPUNIT_TEST(scalar_mult); + CPPUNIT_TEST(scalar_mult); CPPUNIT_TEST(scalar_div); CPPUNIT_TEST(scalar_div); CPPUNIT_TEST(scalar_div); CPPUNIT_TEST(scalar_div); CPPUNIT_TEST(scalar_div); CPPUNIT_TEST(scalar_div); + CPPUNIT_TEST(scalar_div); CPPUNIT_TEST(matrix_mult); CPPUNIT_TEST(matrix_mult); CPPUNIT_TEST(matrix_mult); CPPUNIT_TEST(matrix_mult); CPPUNIT_TEST(matrix_mult); CPPUNIT_TEST(matrix_mult); + CPPUNIT_TEST(matrix_mult); CPPUNIT_TEST(transpose); CPPUNIT_TEST(transpose); CPPUNIT_TEST(transpose); CPPUNIT_TEST(transpose); CPPUNIT_TEST(transpose); CPPUNIT_TEST(transpose); + CPPUNIT_TEST(transpose); CPPUNIT_TEST(apply); CPPUNIT_TEST(apply); CPPUNIT_TEST(apply); CPPUNIT_TEST(apply); CPPUNIT_TEST(apply); CPPUNIT_TEST(apply); + CPPUNIT_TEST(apply); + CPPUNIT_TEST(norm); + CPPUNIT_TEST(norm); + CPPUNIT_TEST(norm); + CPPUNIT_TEST(norm); + CPPUNIT_TEST(norm); CPPUNIT_TEST(gauss); CPPUNIT_TEST(gauss); CPPUNIT_TEST(gauss); CPPUNIT_TEST(gauss); + CPPUNIT_TEST(gauss); CPPUNIT_TEST(det); CPPUNIT_TEST(det); CPPUNIT_TEST(det); CPPUNIT_TEST(det); + CPPUNIT_TEST(det); CPPUNIT_TEST(i); CPPUNIT_TEST(i); CPPUNIT_TEST(i); CPPUNIT_TEST(i); CPPUNIT_TEST(i); CPPUNIT_TEST(i); + CPPUNIT_TEST(i); CPPUNIT_TEST(inv); CPPUNIT_TEST(inv); CPPUNIT_TEST(inv); @@ -427,6 +463,7 @@ class TemplateMatrixTest: public CppUnit::TestFixture { CPPUNIT_TEST(stream); CPPUNIT_TEST(stream); CPPUNIT_TEST(stream); + CPPUNIT_TEST(stream); CPPUNIT_TEST_SUITE_END(); }; CPPUNIT_TEST_SUITE_REGISTRATION(TemplateMatrixTest); @@ -626,6 +663,24 @@ class VariableMatrixTest: public CppUnit::TestFixture { Matrix o(m); CPPUNIT_ASSERT_EQUAL((T)3*o, m.apply([](T& t){t*=3;})); } + template + void norm() { + Matrix m1(3, 3, + 1, -1, 1, + -1, 1, -1, + 1, 1, -1); + Matrix m2(3, 3, + -1, 3, 2, + -2, 0, -3, + 2, 1, -2); + Matrix m3(3, 3, + 0, 3, 0, + -1, 0, 2, + 0, -3, 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, m1.norm(), 0.00001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(6.0, m2.norm(), 0.00001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0, m3.norm(3), 0.00001); + } template void gauss() { Matrix m(3, 3, @@ -763,48 +818,56 @@ class VariableMatrixTest: public CppUnit::TestFixture { CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray1); + CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); + CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); + CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); + CPPUNIT_TEST(access); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); + CPPUNIT_TEST(equality); CPPUNIT_TEST(operator_plus); CPPUNIT_TEST(operator_plus); CPPUNIT_TEST(operator_plus); CPPUNIT_TEST(operator_plus); CPPUNIT_TEST(operator_plus); CPPUNIT_TEST(operator_plus); + CPPUNIT_TEST(operator_plus); CPPUNIT_TEST(operator_minus); CPPUNIT_TEST(operator_minus); CPPUNIT_TEST(operator_minus); CPPUNIT_TEST(operator_minus); CPPUNIT_TEST(operator_minus); CPPUNIT_TEST(operator_minus); + CPPUNIT_TEST(operator_minus); CPPUNIT_TEST(scalar_mult); CPPUNIT_TEST(scalar_mult); CPPUNIT_TEST(scalar_mult); CPPUNIT_TEST(scalar_mult); CPPUNIT_TEST(scalar_mult); CPPUNIT_TEST(scalar_mult); + CPPUNIT_TEST(scalar_mult); CPPUNIT_TEST(scalar_mult); CPPUNIT_TEST(scalar_div); CPPUNIT_TEST(scalar_div); @@ -812,38 +875,50 @@ class VariableMatrixTest: public CppUnit::TestFixture { CPPUNIT_TEST(scalar_div); CPPUNIT_TEST(scalar_div); CPPUNIT_TEST(scalar_div); + CPPUNIT_TEST(scalar_div); CPPUNIT_TEST(matrix_mult); CPPUNIT_TEST(matrix_mult); CPPUNIT_TEST(matrix_mult); CPPUNIT_TEST(matrix_mult); CPPUNIT_TEST(matrix_mult); CPPUNIT_TEST(matrix_mult); + CPPUNIT_TEST(matrix_mult); CPPUNIT_TEST(transpose); CPPUNIT_TEST(transpose); CPPUNIT_TEST(transpose); CPPUNIT_TEST(transpose); CPPUNIT_TEST(transpose); CPPUNIT_TEST(transpose); + CPPUNIT_TEST(transpose); CPPUNIT_TEST(apply); CPPUNIT_TEST(apply); CPPUNIT_TEST(apply); CPPUNIT_TEST(apply); CPPUNIT_TEST(apply); CPPUNIT_TEST(apply); + CPPUNIT_TEST(apply); + CPPUNIT_TEST(norm); + CPPUNIT_TEST(norm); + CPPUNIT_TEST(norm); + CPPUNIT_TEST(norm); + CPPUNIT_TEST(norm); CPPUNIT_TEST(gauss); CPPUNIT_TEST(gauss); CPPUNIT_TEST(gauss); CPPUNIT_TEST(gauss); + CPPUNIT_TEST(gauss); CPPUNIT_TEST(det); CPPUNIT_TEST(det); CPPUNIT_TEST(det); CPPUNIT_TEST(det); + CPPUNIT_TEST(det); CPPUNIT_TEST(i); CPPUNIT_TEST(i); CPPUNIT_TEST(i); CPPUNIT_TEST(i); CPPUNIT_TEST(i); CPPUNIT_TEST(i); + CPPUNIT_TEST(i); CPPUNIT_TEST(inv); CPPUNIT_TEST(inv); CPPUNIT_TEST(inv); @@ -853,6 +928,7 @@ class VariableMatrixTest: public CppUnit::TestFixture { CPPUNIT_TEST(stream); CPPUNIT_TEST(stream); CPPUNIT_TEST(stream); + CPPUNIT_TEST(stream); CPPUNIT_TEST_SUITE_END(); }; CPPUNIT_TEST_SUITE_REGISTRATION(VariableMatrixTest);