Commit ce3ed659 authored by Davis King's avatar Davis King

Added overloads of max_pointwise() and min_pointwise() that take 3 arguments.

parent 678728dc
......@@ -353,6 +353,58 @@ namespace dlib
return matrix_op<op>(op(a.ref(),b.ref()));
}
// ----------------------------------------------------------------------------------------
template <typename M1, typename M2, typename M3>
struct op_min_pointwise3 : basic_op_mmm<M1,M2,M3>
{
op_min_pointwise3( const M1& m1_, const M2& m2_, const M3& m3_) :
basic_op_mmm<M1,M2,M3>(m1_,m2_,m3_){}
typedef typename M1::type type;
typedef const typename M1::type const_ret_type;
const static long cost = M1::cost + M2::cost + M3::cost + 2;
const_ret_type apply (long r, long c) const
{ return std::min(this->m1(r,c),std::min(this->m2(r,c),this->m3(r,c))); }
};
template <
typename EXP1,
typename EXP2,
typename EXP3
>
inline const matrix_op<op_min_pointwise3<EXP1,EXP2,EXP3> >
min_pointwise (
const matrix_exp<EXP1>& a,
const matrix_exp<EXP2>& b,
const matrix_exp<EXP3>& c
)
{
COMPILE_TIME_ASSERT((is_same_type<typename EXP1::type,typename EXP2::type>::value == true));
COMPILE_TIME_ASSERT((is_same_type<typename EXP2::type,typename EXP3::type>::value == true));
COMPILE_TIME_ASSERT(EXP1::NR == EXP2::NR || EXP1::NR == 0 || EXP2::NR == 0);
COMPILE_TIME_ASSERT(EXP1::NC == EXP2::NC || EXP1::NR == 0 || EXP2::NC == 0);
COMPILE_TIME_ASSERT(EXP2::NR == EXP3::NR || EXP2::NR == 0 || EXP3::NR == 0);
COMPILE_TIME_ASSERT(EXP2::NC == EXP3::NC || EXP2::NC == 0 || EXP3::NC == 0);
DLIB_ASSERT(a.nr() == b.nr() &&
a.nc() == b.nc() &&
b.nr() == c.nr() &&
b.nc() == c.nc(),
"\tconst matrix_exp min_pointwise(a,b,c)"
<< "\n\tYou can only make a do a pointwise min between equally sized matrices"
<< "\n\ta.nr(): " << a.nr()
<< "\n\ta.nc(): " << a.nc()
<< "\n\tb.nr(): " << b.nr()
<< "\n\tb.nc(): " << b.nc()
<< "\n\tc.nr(): " << c.nr()
<< "\n\tc.nc(): " << c.nc()
);
typedef op_min_pointwise3<EXP1,EXP2,EXP3> op;
return matrix_op<op>(op(a.ref(),b.ref(),c.ref()));
}
// ----------------------------------------------------------------------------------------
template <typename M1, typename M2>
......@@ -392,6 +444,58 @@ namespace dlib
return matrix_op<op>(op(a.ref(),b.ref()));
}
// ----------------------------------------------------------------------------------------
template <typename M1, typename M2, typename M3>
struct op_max_pointwise3 : basic_op_mmm<M1,M2,M3>
{
op_max_pointwise3( const M1& m1_, const M2& m2_, const M3& m3_) :
basic_op_mmm<M1,M2,M3>(m1_,m2_,m3_){}
typedef typename M1::type type;
typedef const typename M1::type const_ret_type;
const static long cost = M1::cost + M2::cost + M3::cost + 2;
const_ret_type apply (long r, long c) const
{ return std::max(this->m1(r,c),std::max(this->m2(r,c),this->m3(r,c))); }
};
template <
typename EXP1,
typename EXP2,
typename EXP3
>
inline const matrix_op<op_max_pointwise3<EXP1,EXP2,EXP3> >
max_pointwise (
const matrix_exp<EXP1>& a,
const matrix_exp<EXP2>& b,
const matrix_exp<EXP3>& c
)
{
COMPILE_TIME_ASSERT((is_same_type<typename EXP1::type,typename EXP2::type>::value == true));
COMPILE_TIME_ASSERT((is_same_type<typename EXP2::type,typename EXP3::type>::value == true));
COMPILE_TIME_ASSERT(EXP1::NR == EXP2::NR || EXP1::NR == 0 || EXP2::NR == 0);
COMPILE_TIME_ASSERT(EXP1::NC == EXP2::NC || EXP1::NR == 0 || EXP2::NC == 0);
COMPILE_TIME_ASSERT(EXP2::NR == EXP3::NR || EXP2::NR == 0 || EXP3::NR == 0);
COMPILE_TIME_ASSERT(EXP2::NC == EXP3::NC || EXP2::NC == 0 || EXP3::NC == 0);
DLIB_ASSERT(a.nr() == b.nr() &&
a.nc() == b.nc() &&
b.nr() == c.nr() &&
b.nc() == c.nc(),
"\tconst matrix_exp max_pointwise(a,b,c)"
<< "\n\tYou can only make a do a pointwise max between equally sized matrices"
<< "\n\ta.nr(): " << a.nr()
<< "\n\ta.nc(): " << a.nc()
<< "\n\tb.nr(): " << b.nr()
<< "\n\tb.nc(): " << b.nc()
<< "\n\tc.nr(): " << c.nr()
<< "\n\tc.nc(): " << c.nc()
);
typedef op_max_pointwise3<EXP1,EXP2,EXP3> op;
return matrix_op<op>(op(a.ref(),b.ref(),c.ref()));
}
// ----------------------------------------------------------------------------------------
template <
......
......@@ -1380,6 +1380,15 @@ namespace dlib
R(r,c) == std::min(a(r,c), b(r,c))
!*/
const matrix_exp min_pointwise (
const matrix_exp& a,
const matrix_exp& b,
const matrix_exp& c
);
/*!
performs min_pointwise(a,min_pointwise(b,c));
!*/
// ----------------------------------------------------------------------------------------
const matrix_exp::type max (
......@@ -1413,6 +1422,15 @@ namespace dlib
R(r,c) == std::max(a(r,c), b(r,c))
!*/
const matrix_exp max_pointwise (
const matrix_exp& a,
const matrix_exp& b,
const matrix_exp& c
);
/*!
performs max_pointwise(a,max_pointwise(b,c));
!*/
// ----------------------------------------------------------------------------------------
void find_min_and_max (
......
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