Commit 8557e674 authored by Davis King's avatar Davis King

Added the const_ret_type typedef to the matrix_exp. It is now required that all

matrix expressions define this type.  This enables the expressions to return elements
by constant reference when appropriate rather than always returning by value.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403432
parent fc8807a7
......@@ -64,6 +64,7 @@ namespace dlib
struct matrix_traits
{
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
typedef typename EXP::layout_type layout_type;
const static long NR = EXP::NR;
......@@ -84,6 +85,7 @@ namespace dlib
public:
typedef typename matrix_traits<EXP>::type type;
typedef typename matrix_traits<EXP>::const_ret_type const_ret_type;
typedef typename matrix_traits<EXP>::mem_manager_type mem_manager_type;
typedef typename matrix_traits<EXP>::layout_type layout_type;
const static long NR = matrix_traits<EXP>::NR;
......@@ -93,7 +95,7 @@ namespace dlib
typedef matrix<type,NR,NC,mem_manager_type,layout_type> matrix_type;
typedef EXP exp_type;
inline const type operator() (
inline const const_ret_type operator() (
long r,
long c
) const
......@@ -110,7 +112,7 @@ namespace dlib
return ref()(r,c);
}
const type operator() (
const const_ret_type operator() (
long i
) const
{
......@@ -261,6 +263,7 @@ namespace dlib
struct matrix_traits<matrix_multiply_exp<LHS,RHS> >
{
typedef typename LHS::type type;
typedef typename LHS::type const_ret_type;
typedef typename LHS::mem_manager_type mem_manager_type;
typedef typename LHS::layout_type layout_type;
const static long NR = LHS::NR;
......@@ -303,6 +306,7 @@ namespace dlib
public:
typedef typename matrix_traits<matrix_multiply_exp>::type type;
typedef typename matrix_traits<matrix_multiply_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_multiply_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_multiply_exp>::NR;
const static long NC = matrix_traits<matrix_multiply_exp>::NC;
......@@ -450,6 +454,7 @@ namespace dlib
struct matrix_traits<matrix_add_exp<LHS,RHS> >
{
typedef typename LHS::type type;
typedef typename LHS::type const_ret_type;
typedef typename LHS::mem_manager_type mem_manager_type;
typedef typename LHS::layout_type layout_type;
const static long NR = (RHS::NR > LHS::NR) ? RHS::NR : LHS::NR;
......@@ -469,6 +474,7 @@ namespace dlib
!*/
public:
typedef typename matrix_traits<matrix_add_exp>::type type;
typedef typename matrix_traits<matrix_add_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_add_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_add_exp>::NR;
const static long NC = matrix_traits<matrix_add_exp>::NC;
......@@ -555,6 +561,7 @@ namespace dlib
struct matrix_traits<matrix_subtract_exp<LHS,RHS> >
{
typedef typename LHS::type type;
typedef typename LHS::type const_ret_type;
typedef typename LHS::mem_manager_type mem_manager_type;
typedef typename LHS::layout_type layout_type;
const static long NR = (RHS::NR > LHS::NR) ? RHS::NR : LHS::NR;
......@@ -574,6 +581,7 @@ namespace dlib
!*/
public:
typedef typename matrix_traits<matrix_subtract_exp>::type type;
typedef typename matrix_traits<matrix_subtract_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_subtract_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_subtract_exp>::NR;
const static long NC = matrix_traits<matrix_subtract_exp>::NC;
......@@ -661,6 +669,7 @@ namespace dlib
struct matrix_traits<matrix_div_scal_exp<M> >
{
typedef typename M::type type;
typedef typename M::type const_ret_type;
typedef typename M::mem_manager_type mem_manager_type;
typedef typename M::layout_type layout_type;
const static long NR = M::NR;
......@@ -679,6 +688,7 @@ namespace dlib
!*/
public:
typedef typename matrix_traits<matrix_div_scal_exp>::type type;
typedef typename matrix_traits<matrix_div_scal_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_div_scal_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_div_scal_exp>::NR;
const static long NC = matrix_traits<matrix_div_scal_exp>::NC;
......@@ -745,6 +755,7 @@ namespace dlib
struct matrix_traits<matrix_mul_scal_exp<M,use_reference> >
{
typedef typename M::type type;
typedef typename M::type const_ret_type;
typedef typename M::mem_manager_type mem_manager_type;
typedef typename M::layout_type layout_type;
const static long NR = M::NR;
......@@ -769,6 +780,7 @@ namespace dlib
!*/
public:
typedef typename matrix_traits<matrix_mul_scal_exp>::type type;
typedef typename matrix_traits<matrix_mul_scal_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_mul_scal_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_mul_scal_exp>::NR;
const static long NC = matrix_traits<matrix_mul_scal_exp>::NC;
......@@ -973,6 +985,7 @@ namespace dlib
struct matrix_traits<matrix<T,num_rows, num_cols, mem_manager, layout> >
{
typedef T type;
typedef const T& const_ret_type;
typedef mem_manager mem_manager_type;
typedef layout layout_type;
const static long NR = num_rows;
......@@ -995,6 +1008,7 @@ namespace dlib
public:
typedef typename matrix_traits<matrix>::type type;
typedef typename matrix_traits<matrix>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix>::mem_manager_type mem_manager_type;
typedef typename matrix_traits<matrix>::layout_type layout_type;
const static long NR = matrix_traits<matrix>::NR;
......@@ -1723,6 +1737,7 @@ namespace dlib
struct matrix_traits<const_temp_matrix<EXP> >
{
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
typedef typename EXP::layout_type layout_type;
const static long NR = EXP::NR;
......@@ -1735,6 +1750,7 @@ namespace dlib
{
public:
typedef typename matrix_traits<const_temp_matrix>::type type;
typedef typename matrix_traits<const_temp_matrix>::const_ret_type const_ret_type;
typedef typename matrix_traits<const_temp_matrix>::mem_manager_type mem_manager_type;
typedef typename matrix_traits<const_temp_matrix>::layout_type layout_type;
const static long NR = matrix_traits<const_temp_matrix>::NR;
......@@ -1752,12 +1768,12 @@ namespace dlib
ref_(item)
{}
const type operator() (
const const_ret_type operator() (
long r,
long c
) const { return ref_(r,c); }
const type operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return ref_(i); }
template <typename U>
......
......@@ -49,10 +49,17 @@ namespace dlib
are going to be accessing the same element over and over it might
be faster to assign the matrix_exp to a temporary matrix and then
use that temporary.
const_ret_type typedef (defined below)
The purpose of the const_ret_type typedef is to allow matrix expressions
to return their elements by reference when appropriate. So const_ret_type
should either be of the same type as "type" or be of type "const type&".
!*/
public:
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
typedef typename EXP::layout_type layout_type;
const static long cost = EXP::cost;
......@@ -61,7 +68,7 @@ namespace dlib
typedef matrix<type,NR,NC, mem_manager_type,layout_type> matrix_type;
typedef EXP exp_type;
const type operator() (
const const_ret_type operator() (
long r,
long c
) const;
......@@ -75,7 +82,7 @@ namespace dlib
the matrix represented by this matrix expression)
!*/
const type operator() (
const const_ret_type operator() (
long i
) const;
/*!
......
......@@ -31,9 +31,10 @@ namespace dlib
const static long NR = EXP::NC;
const static long NC = EXP::NR;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{ return std::conj(m(c,r)); }
template <typename M>
......
......@@ -215,6 +215,7 @@ namespace dlib
{
typedef typename OP_::template op<M> OP;
typedef typename OP::type type;
typedef typename OP::const_ret_type const_ret_type;
typedef typename OP::mem_manager_type mem_manager_type;
typedef typename M::layout_type layout_type;
const static long NR = OP::NR;
......@@ -236,6 +237,7 @@ namespace dlib
public:
typedef typename matrix_traits<matrix_unary_exp>::type type;
typedef typename matrix_traits<matrix_unary_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_unary_exp>::mem_manager_type mem_manager_type;
typedef typename matrix_traits<matrix_unary_exp>::layout_type layout_type;
const static long NR = matrix_traits<matrix_unary_exp>::NR;
......@@ -253,12 +255,12 @@ namespace dlib
m(m_)
{}
const typename OP::type operator() (
const const_ret_type operator() (
long r,
long c
) const { return OP::apply(m,r,c); }
const typename OP::type operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return matrix_exp<matrix_unary_exp>::operator()(i); }
template <typename U>
......@@ -291,6 +293,7 @@ namespace dlib
{
typedef typename OP_::template op<M> OP;
typedef typename OP::type type;
typedef typename OP::const_ret_type const_ret_type;
typedef typename OP::mem_manager_type mem_manager_type;
const static long NR = OP::NR;
const static long NC = OP::NC;
......@@ -313,6 +316,7 @@ namespace dlib
public:
typedef typename matrix_traits<matrix_scalar_binary_exp>::type type;
typedef typename matrix_traits<matrix_scalar_binary_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_scalar_binary_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_scalar_binary_exp>::NR;
const static long NC = matrix_traits<matrix_scalar_binary_exp>::NC;
......@@ -335,12 +339,12 @@ namespace dlib
COMPILE_TIME_ASSERT(is_matrix<S>::value == false);
}
const typename OP::type operator() (
const const_ret_type operator() (
long r,
long c
) const { return OP::apply(m,s,r,c); }
const typename OP::type operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return matrix_exp<matrix_scalar_binary_exp>::operator()(i); }
template <typename U>
......@@ -374,6 +378,7 @@ namespace dlib
{
typedef typename OP_::template op<M> OP;
typedef typename OP::type type;
typedef typename OP::const_ret_type const_ret_type;
typedef typename OP::mem_manager_type mem_manager_type;
const static long NR = OP::NR;
const static long NC = OP::NC;
......@@ -396,6 +401,7 @@ namespace dlib
public:
typedef typename matrix_traits<matrix_scalar_ternary_exp>::type type;
typedef typename matrix_traits<matrix_scalar_ternary_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_scalar_ternary_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_scalar_ternary_exp>::NR;
const static long NC = matrix_traits<matrix_scalar_ternary_exp>::NC;
......@@ -420,12 +426,12 @@ namespace dlib
COMPILE_TIME_ASSERT(is_matrix<S>::value == false);
}
const typename OP::type operator() (
const const_ret_type operator() (
long r,
long c
) const { return OP::apply(m,s1,s2,r,c); }
const typename OP::type operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return matrix_exp<matrix_scalar_ternary_exp>::operator()(i); }
template <typename U>
......@@ -460,6 +466,7 @@ namespace dlib
{
typedef typename OP_::template op<M1,M2> OP;
typedef typename OP::type type;
typedef typename OP::const_ret_type const_ret_type;
typedef typename OP::mem_manager_type mem_manager_type;
const static long NR = OP::NR;
const static long NC = OP::NC;
......@@ -482,6 +489,7 @@ namespace dlib
public:
typedef typename matrix_traits<matrix_binary_exp>::type type;
typedef typename matrix_traits<matrix_binary_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_binary_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_binary_exp>::NR;
const static long NC = matrix_traits<matrix_binary_exp>::NC;
......@@ -502,12 +510,12 @@ namespace dlib
m2(m2_)
{}
const typename OP::type operator() (
const const_ret_type operator() (
long r,
long c
) const { return OP::apply(m1,m2,r,c); }
const typename OP::type operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return matrix_exp<matrix_binary_exp>::operator()(i); }
template <typename U>
......@@ -542,6 +550,7 @@ namespace dlib
{
typedef typename OP_::template op<M1,M2,M3> OP;
typedef typename OP::type type;
typedef typename OP::const_ret_type const_ret_type;
typedef typename OP::mem_manager_type mem_manager_type;
const static long NR = OP::NR;
const static long NC = OP::NC;
......@@ -565,6 +574,7 @@ namespace dlib
public:
typedef typename matrix_traits<matrix_ternary_exp>::type type;
typedef typename matrix_traits<matrix_ternary_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_ternary_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_ternary_exp>::NR;
const static long NC = matrix_traits<matrix_ternary_exp>::NC;
......@@ -587,12 +597,12 @@ namespace dlib
m3(m3_)
{}
const typename OP::type operator() (
const const_ret_type operator() (
long r,
long c
) const { return OP::apply(m1,m2,m3,r,c); }
const typename OP::type operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return matrix_exp<matrix_ternary_exp>::operator()(i); }
template <typename U>
......@@ -628,6 +638,7 @@ namespace dlib
{
typedef typename OP_::template op<M1,M2,M3,M4> OP;
typedef typename OP::type type;
typedef typename OP::const_ret_type const_ret_type;
typedef typename OP::mem_manager_type mem_manager_type;
const static long NR = OP::NR;
const static long NC = OP::NC;
......@@ -652,6 +663,7 @@ namespace dlib
public:
typedef typename matrix_traits<matrix_fourary_exp>::type type;
typedef typename matrix_traits<matrix_fourary_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_fourary_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_fourary_exp>::NR;
const static long NC = matrix_traits<matrix_fourary_exp>::NC;
......@@ -676,12 +688,12 @@ namespace dlib
m4(m4_)
{}
const typename OP::type operator() (
const const_ret_type operator() (
long r,
long c
) const { return OP::apply(m1,m2,m3,m4,r,c); }
const typename OP::type operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return matrix_exp<matrix_fourary_exp>::operator()(i); }
template <typename U>
......@@ -717,6 +729,7 @@ namespace dlib
struct matrix_traits<dynamic_matrix_scalar_unary_exp<S,OP> >
{
typedef typename OP::type type;
typedef typename OP::const_ret_type const_ret_type;
typedef typename OP::mem_manager_type mem_manager_type;
const static long NR = OP::NR;
const static long NC = OP::NC;
......@@ -736,6 +749,7 @@ namespace dlib
!*/
public:
typedef typename matrix_traits<dynamic_matrix_scalar_unary_exp>::type type;
typedef typename matrix_traits<dynamic_matrix_scalar_unary_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<dynamic_matrix_scalar_unary_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<dynamic_matrix_scalar_unary_exp>::NR;
const static long NC = matrix_traits<dynamic_matrix_scalar_unary_exp>::NC;
......@@ -755,12 +769,12 @@ namespace dlib
COMPILE_TIME_ASSERT(is_matrix<S>::value == false);
}
const typename OP::type operator() (
const const_ret_type operator() (
long r,
long c
) const { return OP::apply(s,r,c); }
const typename OP::type operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return matrix_exp<dynamic_matrix_scalar_unary_exp>::operator()(i); }
template <typename U>
......@@ -795,6 +809,7 @@ namespace dlib
struct matrix_traits<matrix_scalar_unary_exp<S,OP> >
{
typedef typename OP::type type;
typedef typename OP::const_ret_type const_ret_type;
typedef typename OP::mem_manager_type mem_manager_type;
const static long NR = OP::NR;
const static long NC = OP::NC;
......@@ -814,6 +829,7 @@ namespace dlib
!*/
public:
typedef typename matrix_traits<matrix_scalar_unary_exp>::type type;
typedef typename matrix_traits<matrix_scalar_unary_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_scalar_unary_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_scalar_unary_exp>::NR;
const static long NC = matrix_traits<matrix_scalar_unary_exp>::NC;
......@@ -829,12 +845,12 @@ namespace dlib
COMPILE_TIME_ASSERT(is_matrix<S>::value == false);
}
const typename OP::type operator() (
const const_ret_type operator() (
long r,
long c
) const { return OP::apply(s,r,c); }
const typename OP::type operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return matrix_exp<matrix_scalar_unary_exp>::operator()(i); }
template <typename U>
......@@ -867,6 +883,7 @@ namespace dlib
struct matrix_traits<matrix_zeroary_exp<OP> >
{
typedef typename OP::type type;
typedef typename OP::const_ret_type const_ret_type;
typedef typename OP::mem_manager_type mem_manager_type;
const static long NR = OP::NR;
const static long NC = OP::NC;
......@@ -881,6 +898,7 @@ namespace dlib
{
public:
typedef typename matrix_traits<matrix_zeroary_exp>::type type;
typedef typename matrix_traits<matrix_zeroary_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_zeroary_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_zeroary_exp>::NR;
const static long NC = matrix_traits<matrix_zeroary_exp>::NC;
......@@ -891,12 +909,12 @@ namespace dlib
matrix_zeroary_exp (
) {}
const typename OP::type operator() (
const const_ret_type operator() (
long r,
long c
) const { return OP::apply(r,c); }
const typename OP::type operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return matrix_exp<matrix_zeroary_exp>::operator()(i); }
template <typename U>
......@@ -930,6 +948,7 @@ namespace dlib
struct matrix_traits<matrix_sub_range_exp<M,EXPr,EXPc> >
{
typedef typename M::type type;
typedef typename M::const_ret_type const_ret_type;
typedef typename M::mem_manager_type mem_manager_type;
typedef typename M::layout_type layout_type;
const static long NR = EXPr::NR*EXPr::NC;
......@@ -950,6 +969,7 @@ namespace dlib
!*/
public:
typedef typename matrix_traits<matrix_sub_range_exp>::type type;
typedef typename matrix_traits<matrix_sub_range_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_sub_range_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_sub_range_exp>::NR;
const static long NC = matrix_traits<matrix_sub_range_exp>::NC;
......@@ -973,12 +993,12 @@ namespace dlib
{
}
const typename M::type operator() (
const const_ret_type operator() (
long r,
long c
) const { return m(rows(r),cols(c)); }
const typename M::type operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return matrix_exp<matrix_sub_range_exp>::operator()(i); }
template <typename U>
......@@ -1013,6 +1033,7 @@ namespace dlib
struct matrix_traits<matrix_std_vector_exp<M> >
{
typedef typename M::value_type type;
typedef const typename M::value_type& const_ret_type;
typedef typename memory_manager<char>::kernel_1a mem_manager_type;
const static long NR = 0;
const static long NC = 1;
......@@ -1032,6 +1053,7 @@ namespace dlib
!*/
public:
typedef typename matrix_traits<matrix_std_vector_exp>::type type;
typedef typename matrix_traits<matrix_std_vector_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_std_vector_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_std_vector_exp>::NR;
const static long NC = matrix_traits<matrix_std_vector_exp>::NC;
......@@ -1051,12 +1073,12 @@ namespace dlib
{
}
const typename M::value_type& operator() (
const const_ret_type operator() (
long r,
long
) const { return m[r]; }
const typename M::value_type& operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return m[i]; }
template <typename U>
......@@ -1088,6 +1110,7 @@ namespace dlib
struct matrix_traits<matrix_array_exp<M> >
{
typedef typename M::type type;
typedef const typename M::type& const_ret_type;
typedef typename M::mem_manager_type mem_manager_type;
typedef row_major_layout layout_type;
const static long NR = 0;
......@@ -1107,6 +1130,7 @@ namespace dlib
!*/
public:
typedef typename matrix_traits<matrix_array_exp>::type type;
typedef typename matrix_traits<matrix_array_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_array_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_array_exp>::NR;
const static long NC = matrix_traits<matrix_array_exp>::NC;
......@@ -1126,12 +1150,12 @@ namespace dlib
{
}
const typename M::type& operator() (
const const_ret_type operator() (
long r,
long
) const { return m[r]; }
const typename M::type& operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return m[i]; }
template <typename U>
......@@ -1163,6 +1187,7 @@ namespace dlib
struct matrix_traits<matrix_array2d_exp<M> >
{
typedef typename M::type type;
typedef const typename M::type& const_ret_type;
typedef typename M::mem_manager_type mem_manager_type;
typedef row_major_layout layout_type;
const static long NR = 0;
......@@ -1182,6 +1207,7 @@ namespace dlib
!*/
public:
typedef typename matrix_traits<matrix_array2d_exp>::type type;
typedef typename matrix_traits<matrix_array2d_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_array2d_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_array2d_exp>::NR;
const static long NC = matrix_traits<matrix_array2d_exp>::NC;
......@@ -1201,12 +1227,12 @@ namespace dlib
{
}
const typename M::type& operator() (
const const_ret_type operator() (
long r,
long c
) const { return m[r][c]; }
const typename M::type operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return matrix_exp<matrix_array2d_exp>::operator()(i); }
template <typename U>
......@@ -1238,6 +1264,7 @@ namespace dlib
struct matrix_traits<matrix_sub_exp<M> >
{
typedef typename M::type type;
typedef typename M::const_ret_type const_ret_type;
typedef typename M::mem_manager_type mem_manager_type;
typedef typename M::layout_type layout_type;
const static long NR = 0;
......@@ -1256,6 +1283,7 @@ namespace dlib
!*/
public:
typedef typename matrix_traits<matrix_sub_exp>::type type;
typedef typename matrix_traits<matrix_sub_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_sub_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_sub_exp>::NR;
const static long NC = matrix_traits<matrix_sub_exp>::NC;
......@@ -1283,12 +1311,12 @@ namespace dlib
{
}
const typename M::type operator() (
const const_ret_type operator() (
long r,
long c
) const { return m(r+r_,c+c_); }
const typename M::type operator() ( long i ) const
const const_ret_type operator() ( long i ) const
{ return matrix_exp<matrix_sub_exp>::operator()(i); }
template <typename U>
......@@ -1321,6 +1349,7 @@ namespace dlib
struct matrix_traits<matrix_range_exp<T> >
{
typedef T type;
typedef T const_ret_type;
typedef memory_manager<char>::kernel_1a mem_manager_type;
typedef row_major_layout layout_type;
const static long NR = 1;
......@@ -1333,6 +1362,7 @@ namespace dlib
{
public:
typedef typename matrix_traits<matrix_range_exp>::type type;
typedef typename matrix_traits<matrix_range_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_range_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_range_exp>::NR;
const static long NC = matrix_traits<matrix_range_exp>::NC;
......@@ -1387,12 +1417,12 @@ namespace dlib
}
T operator() (
const const_ret_type operator() (
long,
long c
) const { return start + c*inc; }
T operator() (
const const_ret_type operator() (
long c
) const { return start + c*inc; }
......@@ -1426,6 +1456,7 @@ namespace dlib
struct matrix_traits<matrix_log_range_exp<T> >
{
typedef T type;
typedef T const_ret_type;
typedef memory_manager<char>::kernel_1a mem_manager_type;
typedef row_major_layout layout_type;
const static long NR = 1;
......@@ -1438,6 +1469,7 @@ namespace dlib
{
public:
typedef typename matrix_traits<matrix_log_range_exp>::type type;
typedef typename matrix_traits<matrix_log_range_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_log_range_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_log_range_exp>::NR;
const static long NC = matrix_traits<matrix_log_range_exp>::NC;
......@@ -1465,12 +1497,12 @@ namespace dlib
}
T operator() (
const const_ret_type operator() (
long,
long c
) const { return std::pow((T)10,start + c*inc); }
T operator() (
const const_ret_type operator() (
long c
) const { return std::pow(10,start + c*inc); }
......@@ -1504,6 +1536,7 @@ namespace dlib
struct matrix_traits<matrix_range_static_exp<start,inc_,end> >
{
typedef long type;
typedef long const_ret_type;
typedef memory_manager<char>::kernel_1a mem_manager_type;
const static long NR = 1;
const static long NC = tabs<(end - start)>::value/inc_ + 1;
......@@ -1516,6 +1549,7 @@ namespace dlib
{
public:
typedef typename matrix_traits<matrix_range_static_exp>::type type;
typedef typename matrix_traits<matrix_range_static_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<matrix_range_static_exp>::mem_manager_type mem_manager_type;
const static long NR = matrix_traits<matrix_range_static_exp>::NR;
const static long NC = matrix_traits<matrix_range_static_exp>::NC;
......@@ -1528,12 +1562,12 @@ namespace dlib
matrix_range_static_exp (
) {}
long operator() (
const const_ret_type operator() (
long ,
long c
) const { return start + c*inc; }
long operator() (
const const_ret_type operator() (
long c
) const { return start + c*inc; }
......
......@@ -23,8 +23,9 @@ namespace dlib
{ \
const static long cost = EXP::cost+(extra_cost); \
typedef typename EXP::type type; \
typedef typename EXP::type const_ret_type; \
template <typename M> \
static type apply ( const M& m, long r, long c) \
static const const_ret_type apply ( const M& m, long r, long c) \
{ return static_cast<type>(std::name(m(r,c))); } \
};}; \
template < typename EXP > \
......@@ -65,8 +66,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost+7;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
return static_cast<type>(1/(1 + std::exp(-m(r,c))));
}
......@@ -92,8 +94,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost+7;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M, typename T>
static type apply ( const M& m, const T& eps, long r, long c)
static const const_ret_type apply ( const M& m, const T& eps, long r, long c)
{
const type temp = m(r,c);
if (temp >= eps || temp <= -eps)
......@@ -139,8 +142,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost+7;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
const type temp = m(r,c);
return temp*temp*temp;
......@@ -167,8 +171,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost+6;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
const type temp = m(r,c);
return temp*temp;
......@@ -195,8 +200,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost+7;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M, typename S>
static type apply ( const M& m, const S& s, long r, long c)
static const const_ret_type apply ( const M& m, const S& s, long r, long c)
{ return static_cast<type>(std::pow(m(r,c),s)); }
};
};
......@@ -228,8 +234,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost+7;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M, typename S>
static type apply ( const M& m, const S& s, long r, long c)
static const const_ret_type apply ( const M& m, const S& s, long r, long c)
{ return static_cast<type>(std::pow(s,m(r,c))); }
};
};
......@@ -261,8 +268,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost+6;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
const type temp = m(r,c);
if (temp != static_cast<type>(0))
......@@ -301,8 +309,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost+6;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
const type temp = m(r,c);
if (temp != static_cast<type>(0))
......@@ -338,8 +347,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost+5;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M>
static type apply ( const M& m, const type& s, long r, long c)
static const const_ret_type apply ( const M& m, const type& s, long r, long c)
{
return m(r,c)*s;
}
......@@ -377,8 +387,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost+7;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
return static_cast<type>(std::floor(m(r,c)+0.5));
}
......@@ -390,8 +401,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost;
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
return m(r,c);
}
......@@ -420,8 +432,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost+7;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
return static_cast<type>(std::abs(m(r,c)));
}
......@@ -432,8 +445,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost;
typedef T type;
typedef T const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
return static_cast<type>(std::abs(m(r,c)));
}
......@@ -460,8 +474,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost+1;
typedef std::complex<typename EXP::type> type;
typedef std::complex<typename EXP::type> const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
return type(m(r,c));
}
......@@ -487,9 +502,10 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP1::cost+EXP2::cost+1;
typedef std::complex<typename EXP1::type> type;
typedef std::complex<typename EXP1::type> const_ret_type;
template <typename M1, typename M2>
static type apply ( const M1& m1, const M2& m2 , long r, long c)
static const const_ret_type apply ( const M1& m1, const M2& m2 , long r, long c)
{ return type(m1(r,c),m2(r,c)); }
};
};
......@@ -529,8 +545,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost+6;
typedef typename EXP::type::value_type type;
typedef typename EXP::type::value_type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{ return std::norm(m(r,c)); }
};
};
......@@ -555,8 +572,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost;
typedef typename EXP::type::value_type type;
typedef typename EXP::type::value_type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{ return std::real(m(r,c)); }
};
};
......@@ -581,8 +599,9 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan,7)
{
const static long cost = EXP::cost;
typedef typename EXP::type::value_type type;
typedef typename EXP::type::value_type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{ return std::imag(m(r,c)); }
};
};
......
......@@ -158,9 +158,10 @@ namespace dlib
const static long NR = 1;
const static long NC = EXP::NC;
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long row, long, long c)
static const const_ret_type apply ( const M& m, long row, long, long c)
{ return m(row,c); }
template <typename M>
......@@ -201,9 +202,10 @@ namespace dlib
const static long NR = 1;
const static long NC = 0;
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long row, long , long , long c)
static const const_ret_type apply ( const M& m, long row, long , long , long c)
{ return m(row,c); }
template <typename M>
......@@ -245,12 +247,13 @@ namespace dlib
{
const static long cost = EXP1::cost+EXP2::cost;
typedef typename EXP1::type type;
typedef typename EXP1::const_ret_type const_ret_type;
typedef typename EXP1::mem_manager_type mem_manager_type;
const static long NR = EXP2::NC*EXP2::NR;
const static long NC = EXP1::NC;
template <typename M1, typename M2>
static type apply ( const M1& m1, const M2& rows , long r, long c)
static const const_ret_type apply ( const M1& m1, const M2& rows , long r, long c)
{ return m1(rows(r),c); }
template <typename M1, typename M2>
......@@ -298,9 +301,10 @@ namespace dlib
const static long NR = EXP::NR;
const static long NC = 1;
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long col, long r, long)
static const const_ret_type apply ( const M& m, long col, long r, long)
{ return m(r,col); }
template <typename M>
......@@ -341,9 +345,10 @@ namespace dlib
const static long NR = 0;
const static long NC = 1;
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long col, long , long r, long )
static const const_ret_type apply ( const M& m, long col, long , long r, long )
{ return m(r,col); }
template <typename M>
......@@ -384,13 +389,14 @@ namespace dlib
struct op : has_destructive_aliasing
{
typedef typename EXP1::type type;
typedef typename EXP1::const_ret_type const_ret_type;
typedef typename EXP1::mem_manager_type mem_manager_type;
const static long NR = EXP1::NR;
const static long NC = EXP2::NC*EXP2::NR;
const static long cost = EXP1::cost+EXP2::cost;
template <typename M1, typename M2>
static type apply ( const M1& m1, const M2& cols , long r, long c)
static const const_ret_type apply ( const M1& m1, const M2& cols , long r, long c)
{ return m1(r,cols(c)); }
template <typename M1, typename M2>
......
......@@ -348,7 +348,8 @@ namespace dlib
const static long NC = 1;
typedef typename memory_manager<char>::kernel_1a mem_manager_type;
typedef T type;
static type apply (const T* val, long r, long )
typedef const T& const_ret_type;
static const const_ret_type apply (const T* val, long r, long )
{ return val[r]; }
};
......@@ -380,9 +381,10 @@ namespace dlib
const static long NR = EXP::NC;
const static long NC = EXP::NR;
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{ return m(c,r); }
template <typename M>
......@@ -511,9 +513,10 @@ namespace dlib
const static long NR = (EXP::NR==0) ? 0 : (EXP::NR - 1);
const static long NC = (EXP::NC==0) ? 0 : (EXP::NC - 1);
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
if (r < R)
{
......@@ -547,9 +550,10 @@ namespace dlib
const static long NR = (EXP::NR==0) ? 0 : (EXP::NR - 1);
const static long NC = (EXP::NC==0) ? 0 : (EXP::NC - 1);
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long R, long C, long r, long c)
static const const_ret_type apply ( const M& m, long R, long C, long r, long c)
{
if (r < R)
{
......@@ -632,9 +636,10 @@ namespace dlib
const static long NR = EXP::NR;
const static long NC = (EXP::NC==0) ? 0 : (EXP::NC - 1);
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
if (c < C)
{
......@@ -662,9 +667,10 @@ namespace dlib
const static long NR = EXP::NR;
const static long NC = (EXP::NC==0) ? 0 : (EXP::NC - 1);
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long C, long r, long c)
static const const_ret_type apply ( const M& m, long C, long r, long c)
{
if (c < C)
{
......@@ -736,9 +742,10 @@ namespace dlib
const static long NR = (EXP::NR==0) ? 0 : (EXP::NR - 1);
const static long NC = EXP::NC;
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
if (r < R)
{
......@@ -766,9 +773,10 @@ namespace dlib
const static long NR = (EXP::NR==0) ? 0 : (EXP::NR - 1);
const static long NC = EXP::NC;
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long R, long r, long c)
static const const_ret_type apply ( const M& m, long R, long r, long c)
{
if (r < R)
{
......@@ -840,9 +848,10 @@ namespace dlib
const static long NR = N;
const static long NC = N;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
if (r==c)
return m(r);
......@@ -887,9 +896,10 @@ namespace dlib
const static long NR = (EXP::NC&&EXP::NR)? (tmin<EXP::NR,EXP::NC>::value) : (0);
const static long NC = 1;
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long r, long )
static const const_ret_type apply ( const M& m, long r, long )
{ return m(r,r); }
template <typename M>
......@@ -920,8 +930,9 @@ namespace dlib
{
const static long cost = EXP::cost;
typedef target_type type;
typedef target_type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{ return static_cast<target_type>(m(r,c)); }
};
};
......@@ -949,8 +960,9 @@ namespace dlib
{
const static long cost = EXP::cost+1;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M, typename S>
static type apply ( const M& m, const S& s, long r, long c)
static const const_ret_type apply ( const M& m, const S& s, long r, long c)
{
if (m(r,c) < s)
return 1;
......@@ -1001,8 +1013,9 @@ namespace dlib
{
const static long cost = EXP::cost+1;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M, typename S>
static type apply ( const M& m, const S& s, long r, long c)
static const const_ret_type apply ( const M& m, const S& s, long r, long c)
{
if (m(r,c) <= s)
return 1;
......@@ -1053,8 +1066,9 @@ namespace dlib
{
const static long cost = EXP::cost+1;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M, typename S>
static type apply ( const M& m, const S& s, long r, long c)
static const const_ret_type apply ( const M& m, const S& s, long r, long c)
{
if (m(r,c) > s)
return 1;
......@@ -1105,8 +1119,9 @@ namespace dlib
{
const static long cost = EXP::cost+1;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M, typename S>
static type apply ( const M& m, const S& s, long r, long c)
static const const_ret_type apply ( const M& m, const S& s, long r, long c)
{
if (m(r,c) >= s)
return 1;
......@@ -1157,8 +1172,9 @@ namespace dlib
{
const static long cost = EXP::cost+1;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M, typename S>
static type apply ( const M& m, const S& s, long r, long c)
static const const_ret_type apply ( const M& m, const S& s, long r, long c)
{
if (m(r,c) == s)
return 1;
......@@ -1209,8 +1225,9 @@ namespace dlib
{
const static long cost = EXP::cost+1;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M, typename S>
static type apply ( const M& m, const S& s, long r, long c)
static const const_ret_type apply ( const M& m, const S& s, long r, long c)
{
if (m(r,c) != s)
return 1;
......@@ -1527,7 +1544,8 @@ namespace dlib
const static long NC = 0;
typedef typename memory_manager<char>::kernel_1a mem_manager_type;
typedef T type;
static type apply (const T& val, long , long )
typedef const T& const_ret_type;
static const const_ret_type apply (const T& val, long , long )
{ return val; }
};
......@@ -1604,7 +1622,8 @@ namespace dlib
const static long NC = NC_;
typedef typename memory_manager<char>::kernel_1a mem_manager_type;
typedef T type;
static type apply (const T& val, long , long )
typedef const T& const_ret_type;
static const const_ret_type apply (const T& val, long , long )
{ return val; }
};
......@@ -1638,7 +1657,8 @@ namespace dlib
const static long NC = NC_;
typedef typename memory_manager<char>::kernel_1a mem_manager_type;
typedef T type;
static type apply ( long , long )
typedef T const_ret_type;
static const const_ret_type apply ( long , long )
{ return val; }
};
......@@ -1668,7 +1688,8 @@ namespace dlib
const static long NC = 0;
typedef typename memory_manager<char>::kernel_1a mem_manager_type;
typedef T type;
static type apply (const T&, long r, long c)
typedef T const_ret_type;
static const const_ret_type apply (const T&, long r, long c)
{ return static_cast<type>(r == c); }
};
......@@ -1703,7 +1724,8 @@ namespace dlib
const static long NC = N;
typedef typename memory_manager<char>::kernel_1a mem_manager_type;
typedef T type;
static type apply ( long r, long c)
typedef T const_ret_type;
static const const_ret_type apply ( long r, long c)
{ return static_cast<type>(r == c); }
template <typename M>
......@@ -1735,8 +1757,9 @@ namespace dlib
{
const static long cost = EXP::cost + 1;
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{ return m((r+R)%m.nr(),(c+C)%m.nc()); }
};
};
......@@ -1770,10 +1793,11 @@ namespace dlib
struct op : public has_nondestructive_aliasing, public preserves_dimensions<EXP1,EXP2>
{
typedef typename compatible<typename EXP1::type, typename EXP2::type>::type type;
typedef type const_ret_type;
const static long cost = EXP1::cost + EXP2::cost + 1;
template <typename M1, typename M2>
static type apply ( const M1& m1, const M2& m2 , long r, long c)
static const const_ret_type apply ( const M1& m1, const M2& m2 , long r, long c)
{ return m1(r,c)*m2(r,c); }
};
};
......@@ -1811,10 +1835,11 @@ namespace dlib
struct op : public has_nondestructive_aliasing, public preserves_dimensions<EXP1,EXP2,EXP3>
{
typedef typename EXP1::type type;
typedef typename EXP1::type const_ret_type;
const static long cost = EXP1::cost + EXP2::cost + EXP3::cost + 2;
template <typename M1, typename M2, typename M3>
static type apply ( const M1& m1, const M2& m2, const M3& m3 , long r, long c)
static const const_ret_type apply ( const M1& m1, const M2& m2, const M3& m3 , long r, long c)
{ return m1(r,c)*m2(r,c)*m3(r,c); }
};
};
......@@ -1863,10 +1888,11 @@ namespace dlib
struct op : public has_nondestructive_aliasing, public preserves_dimensions<EXP1,EXP2,EXP3,EXP4>
{
typedef typename EXP1::type type;
typedef typename EXP1::type const_ret_type;
const static long cost = EXP1::cost + EXP2::cost + EXP3::cost + EXP4::cost + 3;
template <typename M1, typename M2, typename M3, typename M4>
static type apply ( const M1& m1, const M2& m2, const M3& m3, const M4& m4 , long r, long c)
static const const_ret_type apply ( const M1& m1, const M2& m2, const M3& m3, const M4& m4 , long r, long c)
{ return m1(r,c)*m2(r,c)*m3(r,c)*m4(r,c); }
};
};
......@@ -2097,10 +2123,11 @@ namespace dlib
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
const static long cost = EXP::cost + 1;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
const type temp = m(r,c);
if (temp > static_cast<type>(upper))
......@@ -2134,10 +2161,11 @@ namespace dlib
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
const static long cost = EXP::cost + 2;
template <typename M>
static type apply ( const M& m, const type& lower, const type& upper, long r, long c)
static const const_ret_type apply ( const M& m, const type& lower, const type& upper, long r, long c)
{
const type temp = m(r,c);
if (temp > upper)
......@@ -2229,12 +2257,13 @@ namespace dlib
{
const static long cost = EXP1::cost + EXP2::cost + 1;
typedef typename EXP1::type type;
typedef typename EXP1::type const_ret_type;
typedef typename EXP1::mem_manager_type mem_manager_type;
const static long NR = EXP1::NR;
const static long NC = EXP1::NC;
template <typename M1, typename M2>
static type apply ( const M1& m1, const M2& m2 , long r, long c)
static const const_ret_type apply ( const M1& m1, const M2& m2 , long r, long c)
{ return m1(r,c)*m2(c); }
template <typename M1, typename M2>
......@@ -2386,10 +2415,11 @@ namespace dlib
const static long NR = EXP1::NR*EXP2::NR;
const static long NC = EXP1::NC*EXP2::NC;
typedef typename EXP1::type type;
typedef typename EXP1::type const_ret_type;
typedef typename EXP1::mem_manager_type mem_manager_type;
template <typename M1, typename M2>
static type apply ( const M1& m1, const M2& m2 , long r, long c)
static const const_ret_type apply ( const M1& m1, const M2& m2 , long r, long c)
{
return m1(r/m2.nr(),c/m2.nc())*m2(r%m2.nr(),c%m2.nc());
}
......@@ -2426,8 +2456,9 @@ namespace dlib
{
const static long cost = EXP::cost+1;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
if (r >= c)
return m(r,c);
......@@ -2436,7 +2467,7 @@ namespace dlib
}
template <typename M>
static type apply ( const M& m, const type& s, long r, long c)
static const const_ret_type apply ( const M& m, const type& s, long r, long c)
{
if (r > c)
return m(r,c);
......@@ -2480,9 +2511,10 @@ namespace dlib
{
const static long cost = EXP::cost+1;
typedef typename EXP::type type;
typedef typename EXP::type const_ret_type;
template <typename M>
static type apply ( const M& m, long r, long c)
static const const_ret_type apply ( const M& m, long r, long c)
{
if (r <= c)
return m(r,c);
......@@ -2491,7 +2523,7 @@ namespace dlib
}
template <typename M>
static type apply ( const M& m, const type& s, long r, long c)
static const const_ret_type apply ( const M& m, const type& s, long r, long c)
{
if (r < c)
return m(r,c);
......@@ -2633,13 +2665,14 @@ namespace dlib
{
const static long cost = EXP1::cost+EXP2::cost+1;
typedef typename EXP1::type type;
typedef typename EXP1::const_ret_type const_ret_type;
typedef typename EXP1::mem_manager_type mem_manager_type;
const static long NR = EXP1::NR+EXP2::NR;
const static long NC = EXP1::NC*EXP2::NC;
template <typename M1, typename M2>
static type apply ( const M1& m1, const M2& m2 , long r, long c)
static const const_ret_type apply ( const M1& m1, const M2& m2 , long r, long c)
{
if (r < m1.nr())
return m1(r, c/m2.nc());
......@@ -2680,9 +2713,10 @@ namespace dlib
const static long NR = EXP::NC*EXP::NR;
const static long NC = 1;
typedef typename EXP::type type;
typedef typename EXP::const_ret_type const_ret_type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long r, long )
static const const_ret_type apply ( const M& m, long r, long )
{ return m(r/m.nc(), r%m.nc()); }
template <typename M>
......
......@@ -22,6 +22,7 @@ namespace dlib
struct matrix_traits<kernel_matrix_exp<kernel_type,alloc> >
{
typedef typename kernel_type::scalar_type type;
typedef typename kernel_type::scalar_type const_ret_type;
typedef typename kernel_type::mem_manager_type mem_manager_type;
typedef row_major_layout layout_type;
const static long NR = 0;
......@@ -38,6 +39,7 @@ namespace dlib
typedef typename kernel_type::sample_type sample_type;
public:
typedef typename matrix_traits<kernel_matrix_exp>::type type;
typedef typename matrix_traits<kernel_matrix_exp>::const_ret_type const_ret_type;
typedef typename matrix_traits<kernel_matrix_exp>::mem_manager_type mem_manager_type;
typedef typename matrix_traits<kernel_matrix_exp>::layout_type layout_type;
const static long NR = matrix_traits<kernel_matrix_exp>::NR;
......@@ -114,8 +116,9 @@ namespace dlib
const static long cost = EXP::cost+100;
typedef typename kernel_type::scalar_type type;
typedef typename kernel_type::scalar_type const_ret_type;
template <typename M>
static type apply ( const M& m, const kernel_type& kern, const long r, long c)
static const const_ret_type apply ( const M& m, const kernel_type& kern, const long r, long c)
{
return kern(m(r),m(c));
}
......@@ -161,6 +164,7 @@ namespace dlib
struct matrix_traits<kernel_matrix_exp1<kernel_type,lhs_type> >
{
typedef typename kernel_type::scalar_type type;
typedef typename kernel_type::scalar_type const_ret_type;
typedef typename kernel_type::mem_manager_type mem_manager_type;
typedef row_major_layout layout_type;
const static long NR = 0;
......@@ -177,6 +181,7 @@ namespace dlib
typedef typename kernel_type::sample_type sample_type;
public:
typedef typename matrix_traits<kernel_matrix_exp1>::type type;
typedef typename matrix_traits<kernel_matrix_exp1>::type const_ret_type;
typedef typename matrix_traits<kernel_matrix_exp1>::mem_manager_type mem_manager_type;
typedef typename matrix_traits<kernel_matrix_exp1>::layout_type layout_type;
const static long NR = matrix_traits<kernel_matrix_exp1>::NR;
......@@ -276,6 +281,7 @@ namespace dlib
struct matrix_traits<kernel_matrix_exp2<kernel_type,lhs_type> >
{
typedef typename kernel_type::scalar_type type;
typedef typename kernel_type::scalar_type const_ret_type;
typedef typename kernel_type::mem_manager_type mem_manager_type;
typedef row_major_layout layout_type;
const static long NR = 1;
......@@ -292,6 +298,7 @@ namespace dlib
typedef typename kernel_type::sample_type sample_type;
public:
typedef typename matrix_traits<kernel_matrix_exp2>::type type;
typedef typename matrix_traits<kernel_matrix_exp2>::const_ret_type const_ret_type;
typedef typename matrix_traits<kernel_matrix_exp2>::mem_manager_type mem_manager_type;
typedef typename matrix_traits<kernel_matrix_exp2>::layout_type layout_type;
const static long NR = matrix_traits<kernel_matrix_exp2>::NR;
......@@ -391,6 +398,7 @@ namespace dlib
struct matrix_traits<kernel_matrix_exp3<kernel_type,lhs_type,rhs_type> >
{
typedef typename kernel_type::scalar_type type;
typedef typename kernel_type::scalar_type const_ret_type;
typedef typename kernel_type::mem_manager_type mem_manager_type;
typedef row_major_layout layout_type;
const static long NR = 0;
......@@ -408,6 +416,7 @@ namespace dlib
typedef typename kernel_type::sample_type sample_type;
public:
typedef typename matrix_traits<kernel_matrix_exp3>::type type;
typedef typename matrix_traits<kernel_matrix_exp3>::const_ret_type const_ret_type;
typedef typename matrix_traits<kernel_matrix_exp3>::mem_manager_type mem_manager_type;
typedef typename matrix_traits<kernel_matrix_exp3>::layout_type layout_type;
const static long NR = matrix_traits<kernel_matrix_exp3>::NR;
......
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