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
This commit is contained in:
Davis King 2009-06-26 15:22:12 +00:00
parent d27be3233d
commit c29b9fd678
3 changed files with 8 additions and 2 deletions

View File

@ -331,7 +331,7 @@ namespace dlib
// 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.
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)"
<< "\n\tYou are trying to multiply two incompatible matrices together"
<< "\n\tlhs.nr(): " << lhs.nr()

View File

@ -196,6 +196,8 @@ namespace dlib
/*!
requires
- 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
ensures
- returns the result of doing the matrix multiplication m1*m2. The resulting

View File

@ -128,7 +128,11 @@ namespace dlib
{
// Most of the time is spent in the following dot product.
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;
}