From 6a8b0e745d3a16cf4d59152a76bf4df0f8240fd3 Mon Sep 17 00:00:00 2001
From: Davis King <davis@dlib.net>
Date: Fri, 23 May 2014 21:52:01 -0400
Subject: [PATCH] Relaxed some excessively restrictive requires clauses.

---
 dlib/matrix/matrix_utilities.h          | 26 ++++++++++++++-----------
 dlib/matrix/matrix_utilities_abstract.h | 14 ++++++-------
 2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/dlib/matrix/matrix_utilities.h b/dlib/matrix/matrix_utilities.h
index e023a213..e9c328e0 100644
--- a/dlib/matrix/matrix_utilities.h
+++ b/dlib/matrix/matrix_utilities.h
@@ -1677,7 +1677,7 @@ namespace dlib
         const T& val
     )
     {
-        DLIB_ASSERT(nr > 0 && nc > 0, 
+        DLIB_ASSERT(nr >= 0 && nc >= 0, 
             "\tconst matrix_exp uniform_matrix<T>(nr, nc, val)"
             << "\n\tnr and nc have to be bigger than 0"
             << "\n\tnr: " << nr
@@ -1697,9 +1697,9 @@ namespace dlib
         long nc
     )
     {
-        DLIB_ASSERT(nr > 0 && nc > 0, 
+        DLIB_ASSERT(nr >= 0 && nc >= 0, 
             "\tconst matrix_exp zeros_matrix<T>(nr, nc)"
-            << "\n\tnr and nc have to be bigger than 0"
+            << "\n\tnr and nc have to be >= 0"
             << "\n\tnr: " << nr
             << "\n\tnc: " << nc
             );
@@ -1716,9 +1716,9 @@ namespace dlib
         const matrix_exp<EXP>& mat
     )
     {
-        DLIB_ASSERT(mat.nr() > 0 && mat.nc() > 0, 
+        DLIB_ASSERT(mat.nr() >= 0 && mat.nc() >= 0, 
             "\tconst matrix_exp zeros_matrix(mat)"
-            << "\n\t nr and nc have to be bigger than 0"
+            << "\n\t nr and nc have to be >= 0"
             << "\n\t mat.nr(): " << mat.nr()
             << "\n\t mat.nc(): " << mat.nc()
             );
@@ -1737,9 +1737,9 @@ namespace dlib
         long nc
     )
     {
-        DLIB_ASSERT(nr > 0 && nc > 0, 
+        DLIB_ASSERT(nr >= 0 && nc >= 0, 
             "\tconst matrix_exp ones_matrix<T>(nr, nc)"
-            << "\n\tnr and nc have to be bigger than 0"
+            << "\n\tnr and nc have to be >= 0"
             << "\n\tnr: " << nr
             << "\n\tnc: " << nc
             );
@@ -1756,9 +1756,9 @@ namespace dlib
         const matrix_exp<EXP>& mat
     )
     {
-        DLIB_ASSERT(mat.nr() > 0 && mat.nc() > 0, 
+        DLIB_ASSERT(mat.nr() >= 0 && mat.nc() >= 0, 
             "\tconst matrix_exp ones_matrix(mat)"
-            << "\n\t nr and nc have to be bigger than 0"
+            << "\n\t nr and nc have to be >= 0"
             << "\n\t mat.nr(): " << mat.nr()
             << "\n\t mat.nc(): " << mat.nc()
             );
@@ -4007,11 +4007,13 @@ namespace dlib
         // don't have the same number of rows
         COMPILE_TIME_ASSERT(EXP1::NR == EXP2::NR || (EXP1::NR*EXP2::NR == 0));
 
-        DLIB_ASSERT(a.nr() == b.nr(),
+        DLIB_ASSERT(a.nr() == b.nr() || a.size() == 0 || b.size() == 0,
             "\tconst matrix_exp join_rows(const matrix_exp& a, const matrix_exp& b)"
             << "\n\tYou can only use join_rows() if both matrices have the same number of rows"
             << "\n\ta.nr(): " << a.nr()
             << "\n\tb.nr(): " << b.nr()
+            << "\n\ta.nc(): " << a.nc()
+            << "\n\tb.nc(): " << b.nc()
             );
 
         typedef op_join_rows<EXP1,EXP2> op;
@@ -4081,9 +4083,11 @@ namespace dlib
         // don't have the same number of columns 
         COMPILE_TIME_ASSERT(EXP1::NC == EXP2::NC || (EXP1::NC*EXP2::NC == 0));
 
-        DLIB_ASSERT(a.nc() == b.nc(),
+        DLIB_ASSERT(a.nc() == b.nc() || a.size() == 0 || b.size() == 0,
             "\tconst matrix_exp join_cols(const matrix_exp& a, const matrix_exp& b)"
             << "\n\tYou can only use join_cols() if both matrices have the same number of columns"
+            << "\n\ta.nr(): " << a.nr()
+            << "\n\tb.nr(): " << b.nr()
             << "\n\ta.nc(): " << a.nc()
             << "\n\tb.nc(): " << b.nc()
             );
diff --git a/dlib/matrix/matrix_utilities_abstract.h b/dlib/matrix/matrix_utilities_abstract.h
index 7221b627..cd02c03d 100644
--- a/dlib/matrix/matrix_utilities_abstract.h
+++ b/dlib/matrix/matrix_utilities_abstract.h
@@ -241,7 +241,7 @@ namespace dlib
     );
     /*!
         requires
-            - nr > 0 && nc > 0
+            - nr >= 0 && nc >= 0
         ensures
             - returns an nr by nc matrix with elements of type T and all set to val.
     !*/
@@ -253,7 +253,7 @@ namespace dlib
     );
     /*!
         requires
-            - mat.nr() > 0 && mat.nc() > 0
+            - mat.nr() >= 0 && mat.nc() >= 0
         ensures
             - Let T denote the type of element in mat. Then this function
               returns uniform_matrix<T>(mat.nr(), mat.nc(), 1)
@@ -270,7 +270,7 @@ namespace dlib
     );
     /*!
         requires
-            - nr > 0 && nc > 0
+            - nr >= 0 && nc >= 0
         ensures
             - returns uniform_matrix<T>(nr, nc, 1)
     !*/
@@ -282,7 +282,7 @@ namespace dlib
     );
     /*!
         requires
-            - mat.nr() > 0 && mat.nc() > 0
+            - mat.nr() >= 0 && mat.nc() >= 0
         ensures
             - Let T denote the type of element in mat. Then this function
               returns uniform_matrix<T>(mat.nr(), mat.nc(), 0)
@@ -299,7 +299,7 @@ namespace dlib
     );
     /*!
         requires
-            - nr > 0 && nc > 0
+            - nr >= 0 && nc >= 0
         ensures
             - returns uniform_matrix<T>(nr, nc, 0)
     !*/
@@ -797,7 +797,7 @@ namespace dlib
     );
     /*!
         requires
-            - a.nr() == b.nr()
+            - a.nr() == b.nr() || a.size() == 0 || b.size() == 0
             - a and b both contain the same type of element
         ensures
             - This function joins two matrices together by concatenating their rows.
@@ -820,7 +820,7 @@ namespace dlib
     );
     /*!
         requires
-            - a.nc() == b.nc()
+            - a.nc() == b.nc() || a.size() == 0 || b.size() == 0
             - a and b both contain the same type of element
         ensures
             - This function joins two matrices together by concatenating their columns.
-- 
2.18.0