mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Made sum() and mean() work with complex numbers.
This commit is contained in:
parent
2cfe8f9329
commit
7f5dbb715d
@ -1669,13 +1669,26 @@ namespace dlib
|
||||
template <
|
||||
typename EXP
|
||||
>
|
||||
inline const typename matrix_exp<EXP>::type mean (
|
||||
inline const typename disable_if<is_complex<typename EXP::type>, typename matrix_exp<EXP>::type>::type mean (
|
||||
const matrix_exp<EXP>& m
|
||||
)
|
||||
{
|
||||
return sum(m)/(m.nr()*m.nc());
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <
|
||||
typename EXP
|
||||
>
|
||||
inline const typename enable_if<is_complex<typename EXP::type>, typename matrix_exp<EXP>::type>::type mean (
|
||||
const matrix_exp<EXP>& m
|
||||
)
|
||||
{
|
||||
typedef typename EXP::type::value_type type;
|
||||
return sum(m)/(type)(m.nr()*m.nc());
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <
|
||||
|
@ -775,6 +775,15 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void test_complex()
|
||||
{
|
||||
matrix<complex<double> > a, b;
|
||||
|
||||
a = complex_matrix(linspace(1,7,7), linspace(2,8,7));
|
||||
b = complex_matrix(linspace(4,10,7), linspace(2,8,7));
|
||||
|
||||
DLIB_TEST(mean(a) == complex<double>(4, 5));
|
||||
}
|
||||
|
||||
|
||||
class matrix_tester : public tester
|
||||
@ -795,6 +804,8 @@ namespace
|
||||
test_stuff();
|
||||
for (int i = 0; i < 10; ++i)
|
||||
matrix_test();
|
||||
|
||||
test_complex();
|
||||
}
|
||||
} a;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user