Commit c29b9fd6 authored by Davis King's avatar Davis King

This commit adds the requirement that matrices being multiplied together

aren't empty.  Previously this was technically allowed and worked but was
weird.  The optimization I checked a few hours ago also breaks when empty
matrices are multiplied together so I'm just adding this new requirement.

I also had to fix a part of the LU decomposition because it was doing an
empty matrix multiplication at one point.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403104
parent d27be323
...@@ -331,7 +331,7 @@ namespace dlib ...@@ -331,7 +331,7 @@ namespace dlib
// You are trying to multiply two incompatible matrices together. The number of columns // You are trying to multiply two incompatible matrices together. The number of columns
// in the matrix on the left must match the number of rows in the matrix on the right. // in the matrix on the left must match the number of rows in the matrix on the right.
COMPILE_TIME_ASSERT(LHS::NC == RHS::NR || LHS::NC*RHS::NR == 0); COMPILE_TIME_ASSERT(LHS::NC == RHS::NR || LHS::NC*RHS::NR == 0);
DLIB_ASSERT(lhs.nc() == rhs.nr(), DLIB_ASSERT(lhs.nc() == rhs.nr() && lhs.size() > 0 && rhs.size() > 0,
"\tconst matrix_exp operator*(const matrix_exp& lhs, const matrix_exp& rhs)" "\tconst matrix_exp operator*(const matrix_exp& lhs, const matrix_exp& rhs)"
<< "\n\tYou are trying to multiply two incompatible matrices together" << "\n\tYou are trying to multiply two incompatible matrices together"
<< "\n\tlhs.nr(): " << lhs.nr() << "\n\tlhs.nr(): " << lhs.nr()
......
...@@ -196,6 +196,8 @@ namespace dlib ...@@ -196,6 +196,8 @@ namespace dlib
/*! /*!
requires requires
- m1.nc() == m2.nr() - m1.nc() == m2.nr()
- m1.size() > 0 && m2.size() > 0
(you can't multiply any sort of empty matrices together)
- m1 and m2 both contain elements of the same type - m1 and m2 both contain elements of the same type
ensures ensures
- returns the result of doing the matrix multiplication m1*m2. The resulting - returns the result of doing the matrix multiplication m1*m2. The resulting
......
...@@ -128,7 +128,11 @@ namespace dlib ...@@ -128,7 +128,11 @@ namespace dlib
{ {
// Most of the time is spent in the following dot product. // Most of the time is spent in the following dot product.
const long kmax = std::min(i,j); const long kmax = std::min(i,j);
const type s = rowm(LU,i, kmax)*colm(LUcolj,0,kmax); type s;
if (kmax > 0)
s = rowm(LU,i, kmax)*colm(LUcolj,0,kmax);
else
s = 0;
LU(i,j) = LUcolj(i) -= s; LU(i,j) = LUcolj(i) -= s;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment