Commit 9ccab1b2 authored by Davis King's avatar Davis King

Added the find_min_and_max() function. I also changed the code in the

lu_decomposition::is_singular() function to avoid what appears to be a
bug in gcc 4.2.4 that caused one of the regression tests to segfault
when built with -O3.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402873
parent 3919e4d5
......@@ -215,13 +215,15 @@ namespace dlib
<< "\n\tthis: " << this
);
type eps = max(abs(diag(LU)));
type max_val, min_val;
find_min_and_max (abs(diag(LU)), min_val, max_val);
type eps = max_val;
if (eps != 0)
eps *= std::sqrt(std::numeric_limits<type>::epsilon())/10;
else
eps = 1; // there is no max so just use 1
return min(abs(diag(LU))) < eps;
return min_val < eps;
}
// ----------------------------------------------------------------------------------------
......
......@@ -20,6 +20,39 @@
namespace dlib
{
// ----------------------------------------------------------------------------------------
template <
typename EXP
>
void find_min_and_max (
const matrix_exp<EXP>& m,
typename EXP::type& min_val,
typename EXP::type& max_val
)
{
DLIB_ASSERT(m.size() > 0,
"\ttype max(const matrix_exp& m)"
<< "\n\tYou can't ask for the max() of an empty matrix"
<< "\n\tm.size(): " << m.size()
);
typedef typename matrix_exp<EXP>::type type;
min_val = m(0,0);
max_val = min_val;
for (long r = 0; r < m.nr(); ++r)
{
for (long c = 0; c < m.nc(); ++c)
{
type temp = m(r,c);
if (temp > max_val)
max_val = temp;
if (temp < min_val)
min_val = temp;
}
}
}
// ----------------------------------------------------------------------------------------
template <
......
......@@ -621,6 +621,23 @@ namespace dlib
- returns the value of the biggest element of m
!*/
// ----------------------------------------------------------------------------------------
void find_min_and_max (
const matrix_exp& m,
matrix_exp::type& min_val,
matrix_exp::type& max_val
);
/*!
requires
- m.size() > 0
ensures
- #min_val == min(m)
- #max_val == max(m)
- This function computes both the min and max in just one pass
over the elements of the matrix m.
!*/
// ----------------------------------------------------------------------------------------
const matrix_exp::type sum (
......
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