Commit c0bb7952 authored by Davis King's avatar Davis King

Fixed a bug in the matrix class. Expressions of the form mat *= mat(0) would

evaluate incorrectly because the *= operator took the right hand side by reference
and thus experienced an aliasing problem.  The other op= operators had similar
problems and have also been fixed.
parent 2b3ba0bc
...@@ -1475,7 +1475,7 @@ namespace dlib ...@@ -1475,7 +1475,7 @@ namespace dlib
} }
matrix& operator += ( matrix& operator += (
const T& val const T val
) )
{ {
const long size = nr()*nc(); const long size = nr()*nc();
...@@ -1486,7 +1486,7 @@ namespace dlib ...@@ -1486,7 +1486,7 @@ namespace dlib
} }
matrix& operator -= ( matrix& operator -= (
const T& val const T val
) )
{ {
const long size = nr()*nc(); const long size = nr()*nc();
...@@ -1497,7 +1497,7 @@ namespace dlib ...@@ -1497,7 +1497,7 @@ namespace dlib
} }
matrix& operator *= ( matrix& operator *= (
const T& a const T a
) )
{ {
const long size = data.nr()*data.nc(); const long size = data.nr()*data.nc();
...@@ -1507,7 +1507,7 @@ namespace dlib ...@@ -1507,7 +1507,7 @@ namespace dlib
} }
matrix& operator /= ( matrix& operator /= (
const T& a const T a
) )
{ {
const long size = data.nr()*data.nc(); const long size = data.nr()*data.nc();
......
...@@ -1212,6 +1212,43 @@ namespace ...@@ -1212,6 +1212,43 @@ namespace
m2 = 1; m2 = 1;
m1 = subm(m2,0,0,3,3)*m1; m1 = subm(m2,0,0,3,3)*m1;
} }
{
matrix<int> m(2,1);
m = 3,3;
m /= m(0);
DLIB_TEST(m(0) == 1);
DLIB_TEST(m(1) == 1);
}
{
matrix<int> m(2,1);
m = 3,3;
m *= m(0);
DLIB_TEST(m(0) == 9);
DLIB_TEST(m(1) == 9);
}
{
matrix<int> m(2,1);
m = 3,3;
m -= m(0);
DLIB_TEST(m(0) == 0);
DLIB_TEST(m(1) == 0);
}
{
matrix<int> m(2,1);
m = 3,3;
m += m(0);
DLIB_TEST(m(0) == 6);
DLIB_TEST(m(1) == 6);
}
} }
......
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