mirror of https://github.com/davisking/dlib.git
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.
This commit is contained in:
parent
2b3ba0bc48
commit
c0bb7952bf
|
@ -1475,7 +1475,7 @@ namespace dlib
|
|||
}
|
||||
|
||||
matrix& operator += (
|
||||
const T& val
|
||||
const T val
|
||||
)
|
||||
{
|
||||
const long size = nr()*nc();
|
||||
|
@ -1486,7 +1486,7 @@ namespace dlib
|
|||
}
|
||||
|
||||
matrix& operator -= (
|
||||
const T& val
|
||||
const T val
|
||||
)
|
||||
{
|
||||
const long size = nr()*nc();
|
||||
|
@ -1497,7 +1497,7 @@ namespace dlib
|
|||
}
|
||||
|
||||
matrix& operator *= (
|
||||
const T& a
|
||||
const T a
|
||||
)
|
||||
{
|
||||
const long size = data.nr()*data.nc();
|
||||
|
@ -1507,7 +1507,7 @@ namespace dlib
|
|||
}
|
||||
|
||||
matrix& operator /= (
|
||||
const T& a
|
||||
const T a
|
||||
)
|
||||
{
|
||||
const long size = data.nr()*data.nc();
|
||||
|
|
|
@ -1212,6 +1212,43 @@ namespace
|
|||
m2 = 1;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue