mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Removed a bug in the sum() and variance() functions that
caused them to seg fault when they were used on certain matrix of matrix objects. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402405
This commit is contained in:
parent
184f0ce398
commit
197b36eb1a
@ -2813,7 +2813,10 @@ namespace dlib
|
||||
typedef typename matrix_exp<EXP>::type type;
|
||||
|
||||
type val;
|
||||
if (m.size() > 0)
|
||||
val.set_size(m(0,0).nr(),m(0,0).nc());
|
||||
set_all_elements(val,0);
|
||||
|
||||
for (long r = 0; r < m.nr(); ++r)
|
||||
{
|
||||
for (long c = 0; c < m.nc(); ++c)
|
||||
@ -2876,6 +2879,9 @@ namespace dlib
|
||||
typedef typename matrix_exp<EXP>::type type;
|
||||
|
||||
type val;
|
||||
if (m.size() > 0)
|
||||
val.set_size(m(0,0).nr(), m(0,0).nc());
|
||||
|
||||
set_all_elements(val,0);
|
||||
for (long r = 0; r < m.nr(); ++r)
|
||||
{
|
||||
@ -2885,7 +2891,7 @@ namespace dlib
|
||||
}
|
||||
}
|
||||
|
||||
if (m.nr() * m.nc() == 1)
|
||||
if (m.nr() * m.nc() <= 1)
|
||||
return val;
|
||||
else
|
||||
return val/(m.nr()*m.nc() - 1);
|
||||
|
@ -807,6 +807,14 @@ namespace
|
||||
m(0,0) = uniform_matrix<double,3,1>(9);
|
||||
DLIB_CASSERT((round_zeros(variance(m)) == uniform_matrix<double,3,1>(16)),"");
|
||||
DLIB_CASSERT((round_zeros(mean(m)) == uniform_matrix<double,3,1>(3)),"");
|
||||
|
||||
matrix<matrix<double> > m2(2,2);
|
||||
set_all_elements(m2,uniform_matrix<double,3,1>(1));
|
||||
DLIB_CASSERT((round_zeros(variance(m2)) == uniform_matrix<double,3,1>(0)),"");
|
||||
DLIB_CASSERT((round_zeros(mean(m2)) == uniform_matrix<double,3,1>(1)),"");
|
||||
m2(0,0) = uniform_matrix<double,3,1>(9);
|
||||
DLIB_CASSERT((round_zeros(variance(m2)) == uniform_matrix<double,3,1>(16)),"");
|
||||
DLIB_CASSERT((round_zeros(mean(m2)) == uniform_matrix<double,3,1>(3)),"");
|
||||
}
|
||||
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user