From fafa738f618fe9a63ff4d89ab071d4d10644132e Mon Sep 17 00:00:00 2001 From: Davis King Date: Fri, 31 Oct 2008 17:19:04 +0000 Subject: [PATCH] Fixed a compile time bug in the pinv() function. It didn't compile when used on statically sized matrices when they weren't square. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402620 --- dlib/matrix/matrix_utilities.h | 2 +- dlib/matrix/matrix_utilities_abstract.h | 4 ++-- dlib/test/matrix.cpp | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/dlib/matrix/matrix_utilities.h b/dlib/matrix/matrix_utilities.h index 61d41b6eb..9f93a0b01 100644 --- a/dlib/matrix/matrix_utilities.h +++ b/dlib/matrix/matrix_utilities.h @@ -2429,7 +2429,7 @@ namespace dlib template < typename EXP > - inline const typename matrix_exp::matrix_type pinv ( + inline const matrix pinv ( const matrix_exp& m ) { diff --git a/dlib/matrix/matrix_utilities_abstract.h b/dlib/matrix/matrix_utilities_abstract.h index ef5615ed1..d7debeaa2 100644 --- a/dlib/matrix/matrix_utilities_abstract.h +++ b/dlib/matrix/matrix_utilities_abstract.h @@ -707,13 +707,13 @@ namespace dlib // ---------------------------------------------------------------------------------------- - const matrix_exp::matrix_type pinv ( + const matrix pinv ( const matrix_exp& m ); /*! ensures - returns the Moore-Penrose pseudoinverse of m. - - The returned matrix has m.nr() columns and m.nc() rows. + - The returned matrix has m.nc() rows and m.nr() columns. !*/ // ---------------------------------------------------------------------------------------- diff --git a/dlib/test/matrix.cpp b/dlib/test/matrix.cpp index 467c98786..a90b2c3c6 100644 --- a/dlib/test/matrix.cpp +++ b/dlib/test/matrix.cpp @@ -910,6 +910,26 @@ namespace } + { + matrix m; + + for (long r = 0; r < m.nr(); ++r) + { + for (long c = 0; c < m.nc(); ++c) + { + m(r,c) = r*c; + } + } + + m = cos(exp(m)); + + + matrix mi = pinv(m ); + DLIB_CASSERT(mi.nr() == m.nc(),""); + DLIB_CASSERT(mi.nc() == m.nr(),""); + DLIB_CASSERT((equal(round_zeros(mi*m,0.000001) , identity_matrix())),""); + } + { matrix m(5,2);