Commit f825990c authored by Davis King's avatar Davis King

Changed the matrix operations so that they result in shorter type names

when compiled.  This avoids problems in compilers like visual studio.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402301
parent 2801ca62
......@@ -16,19 +16,20 @@ namespace dlib
// ----------------------------------------------------------------------------------------
#define DLIB_MATRIX_SIMPLE_STD_FUNCTION(name) template <typename EXP> \
struct op_##name : has_nondestructive_aliasing, preserves_dimensions<EXP> \
#define DLIB_MATRIX_SIMPLE_STD_FUNCTION(name) struct op_##name { \
template <typename EXP> \
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP> \
{ \
typedef typename EXP::type type; \
template <typename M> \
static type apply ( const M& m, long r, long c) \
{ return static_cast<type>(std::name(m(r,c))); } \
}; \
};}; \
template < typename EXP > \
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_##name<EXP> > > name ( \
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_##name> > name ( \
const matrix_exp<EXP>& m) \
{ \
typedef matrix_unary_exp<matrix_exp<EXP>,op_##name<EXP> > exp; \
typedef matrix_unary_exp<matrix_exp<EXP>,op_##name> exp; \
return matrix_exp<exp>(exp(m)); \
}
......@@ -57,8 +58,10 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
// ----------------------------------------------------------------------------------------
struct op_sigmoid
{
template <typename EXP>
struct op_sigmoid : has_nondestructive_aliasing, preserves_dimensions<EXP>
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type type;
template <typename M>
......@@ -69,22 +72,25 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
return static_cast<type>(1.0/(1.0 + temp));
}
};
};
template <
typename EXP
>
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_sigmoid<EXP> > > sigmoid (
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_sigmoid> > sigmoid (
const matrix_exp<EXP>& m
)
{
typedef matrix_unary_exp<matrix_exp<EXP>,op_sigmoid<EXP> > exp;
typedef matrix_unary_exp<matrix_exp<EXP>,op_sigmoid> exp;
return matrix_exp<exp>(exp(m));
}
// ----------------------------------------------------------------------------------------
struct op_round_zeros
{
template <typename EXP>
struct op_round_zeros : has_nondestructive_aliasing, preserves_dimensions<EXP>
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type type;
template <typename M, typename T>
......@@ -97,11 +103,12 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
return 0;
}
};
};
template <
typename EXP
>
const matrix_exp<matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type,op_round_zeros<EXP> > > round_zeros (
const matrix_exp<matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type,op_round_zeros> > round_zeros (
const matrix_exp<EXP>& m
)
{
......@@ -111,14 +118,14 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
is_same_type<typename EXP::type,double>::value == true ||
is_same_type<typename EXP::type,long double>::value == true
));
typedef matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type, op_round_zeros<EXP> > exp;
typedef matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type, op_round_zeros> exp;
return matrix_exp<exp>(exp(m,10*std::numeric_limits<typename EXP::type>::epsilon()));
}
template <
typename EXP
>
const matrix_exp<matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type,op_round_zeros<EXP> > > round_zeros (
const matrix_exp<matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type,op_round_zeros> > round_zeros (
const matrix_exp<EXP>& m,
typename EXP::type eps
)
......@@ -129,70 +136,79 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
is_same_type<typename EXP::type,double>::value == true ||
is_same_type<typename EXP::type,long double>::value == true
));
typedef matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type, op_round_zeros<EXP> > exp;
typedef matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type, op_round_zeros> exp;
return matrix_exp<exp>(exp(m,eps));
}
// ----------------------------------------------------------------------------------------
struct op_cubed
{
template <typename EXP>
struct op_cubed : has_nondestructive_aliasing, preserves_dimensions<EXP>
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type type;
template <typename M>
static type apply ( const M& m, long r, long c)
{ return m(r,c)*m(r,c)*m(r,c); }
};
};
template <
typename EXP
>
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_cubed<EXP> > > cubed (
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_cubed> > cubed (
const matrix_exp<EXP>& m
)
{
typedef matrix_unary_exp<matrix_exp<EXP>,op_cubed<EXP> > exp;
typedef matrix_unary_exp<matrix_exp<EXP>,op_cubed> exp;
return matrix_exp<exp>(exp(m));
}
// ----------------------------------------------------------------------------------------
struct op_squared
{
template <typename EXP>
struct op_squared : has_nondestructive_aliasing, preserves_dimensions<EXP>
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type type;
template <typename M>
static type apply ( const M& m, long r, long c)
{ return m(r,c)*m(r,c); }
};
};
template <
typename EXP
>
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_squared<EXP> > > squared (
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_squared> > squared (
const matrix_exp<EXP>& m
)
{
typedef matrix_unary_exp<matrix_exp<EXP>,op_squared<EXP> > exp;
typedef matrix_unary_exp<matrix_exp<EXP>,op_squared> exp;
return matrix_exp<exp>(exp(m));
}
// ----------------------------------------------------------------------------------------
struct op_pow
{
template <typename EXP>
struct op_pow : has_nondestructive_aliasing, preserves_dimensions<EXP>
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type type;
template <typename M, typename S>
static type apply ( const M& m, const S& s, long r, long c)
{ return static_cast<type>(std::pow(m(r,c),s)); }
};
};
template <
typename EXP,
typename S
>
const matrix_exp<matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type,op_pow<EXP> > > pow (
const matrix_exp<matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type,op_pow> > pow (
const matrix_exp<EXP>& m,
const S& s
)
......@@ -203,14 +219,16 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
is_same_type<typename EXP::type,double>::value == true ||
is_same_type<typename EXP::type,long double>::value == true
));
typedef matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type,op_pow<EXP> > exp;
typedef matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type,op_pow> exp;
return matrix_exp<exp>(exp(m,s));
}
// ----------------------------------------------------------------------------------------
struct op_reciprocal
{
template <typename EXP>
struct op_reciprocal : has_nondestructive_aliasing, preserves_dimensions<EXP>
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type type;
template <typename M>
......@@ -223,11 +241,12 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
return 0;
}
};
};
template <
typename EXP
>
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_reciprocal<EXP> > > reciprocal (
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_reciprocal> > reciprocal (
const matrix_exp<EXP>& m
)
{
......@@ -237,14 +256,16 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
is_same_type<typename EXP::type,double>::value == true ||
is_same_type<typename EXP::type,long double>::value == true
));
typedef matrix_unary_exp<matrix_exp<EXP>,op_reciprocal<EXP> > exp;
typedef matrix_unary_exp<matrix_exp<EXP>,op_reciprocal> exp;
return matrix_exp<exp>(exp(m));
}
// ----------------------------------------------------------------------------------------
struct op_normalize
{
template <typename EXP>
struct op_normalize : has_nondestructive_aliasing, preserves_dimensions<EXP>
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type type;
template <typename M>
......@@ -253,11 +274,12 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
return m(r,c)*s;
}
};
};
template <
typename EXP
>
const matrix_exp<matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type,op_normalize<EXP> > > normalize (
const matrix_exp<matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type,op_normalize> > normalize (
const matrix_exp<EXP>& m
)
{
......@@ -267,7 +289,7 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
is_same_type<typename EXP::type,double>::value == true ||
is_same_type<typename EXP::type,long double>::value == true
));
typedef matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type, op_normalize<EXP> > exp;
typedef matrix_scalar_binary_exp<matrix_exp<EXP>,typename EXP::type, op_normalize> exp;
typename EXP::type temp = std::sqrt(sum(squared(m)));
if (temp != 0.0)
......@@ -278,8 +300,10 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
// ----------------------------------------------------------------------------------------
struct op_round
{
template <typename EXP>
struct op_round : has_nondestructive_aliasing, preserves_dimensions<EXP>
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type type;
template <typename M>
......@@ -288,11 +312,12 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
return static_cast<type>(std::floor(m(r,c)+0.5));
}
};
};
template <
typename EXP
>
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_round<EXP> > > round (
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_round> > round (
const matrix_exp<EXP>& m
)
{
......@@ -302,14 +327,16 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
is_same_type<typename EXP::type,double>::value == true ||
is_same_type<typename EXP::type,long double>::value == true
));
typedef matrix_unary_exp<matrix_exp<EXP>,op_round<EXP> > exp;
typedef matrix_unary_exp<matrix_exp<EXP>,op_round> exp;
return matrix_exp<exp>(exp(m));
}
// ----------------------------------------------------------------------------------------
struct op_complex_matrix
{
template <typename EXP1, typename EXP2>
struct op_complex_matrix : has_nondestructive_aliasing, preserves_dimensions<EXP1,EXP2>
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP1,EXP2>
{
typedef std::complex<typename EXP1::type> type;
......@@ -317,12 +344,13 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
static type apply ( const M1& m1, const M2& m2 , long r, long c)
{ return type(m1(r,c),m2(r,c)); }
};
};
template <
typename EXP1,
typename EXP2
>
const matrix_exp<matrix_binary_exp<matrix_exp<EXP1>,matrix_exp<EXP2>,op_complex_matrix<EXP1,EXP2> > > complex_matrix (
const matrix_exp<matrix_binary_exp<matrix_exp<EXP1>,matrix_exp<EXP2>,op_complex_matrix> > complex_matrix (
const matrix_exp<EXP1>& real_part,
const matrix_exp<EXP2>& imag_part
)
......@@ -340,73 +368,82 @@ DLIB_MATRIX_SIMPLE_STD_FUNCTION(atan)
<< "\n\timag_part.nr(): " << imag_part.nr()
<< "\n\timag_part.nc(): " << imag_part.nc()
);
typedef matrix_binary_exp<matrix_exp<EXP1>,matrix_exp<EXP2>,op_complex_matrix<EXP1,EXP2> > exp;
typedef matrix_binary_exp<matrix_exp<EXP1>,matrix_exp<EXP2>,op_complex_matrix> exp;
return matrix_exp<exp>(exp(real_part,imag_part));
}
// ----------------------------------------------------------------------------------------
struct op_norm
{
template <typename EXP>
struct op_norm : has_nondestructive_aliasing, preserves_dimensions<EXP>
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type::value_type type;
template <typename M>
static type apply ( const M& m, long r, long c)
{ return std::norm(m(r,c)); }
};
};
template <
typename EXP
>
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_norm<EXP> > > norm (
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_norm> > norm (
const matrix_exp<EXP>& m
)
{
typedef matrix_unary_exp<matrix_exp<EXP>,op_norm<EXP> > exp;
typedef matrix_unary_exp<matrix_exp<EXP>,op_norm> exp;
return matrix_exp<exp>(exp(m));
}
// ----------------------------------------------------------------------------------------
struct op_real
{
template <typename EXP>
struct op_real : has_nondestructive_aliasing, preserves_dimensions<EXP>
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type::value_type type;
template <typename M>
static type apply ( const M& m, long r, long c)
{ return std::real(m(r,c)); }
};
};
template <
typename EXP
>
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_real<EXP> > > real (
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_real> > real (
const matrix_exp<EXP>& m
)
{
typedef matrix_unary_exp<matrix_exp<EXP>,op_real<EXP> > exp;
typedef matrix_unary_exp<matrix_exp<EXP>,op_real> exp;
return matrix_exp<exp>(exp(m));
}
// ----------------------------------------------------------------------------------------
struct op_imag
{
template <typename EXP>
struct op_imag : has_nondestructive_aliasing, preserves_dimensions<EXP>
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type::value_type type;
template <typename M>
static type apply ( const M& m, long r, long c)
{ return std::imag(m(r,c)); }
};
};
template <
typename EXP
>
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_imag<EXP> > > imag (
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_imag> > imag (
const matrix_exp<EXP>& m
)
{
typedef matrix_unary_exp<matrix_exp<EXP>,op_imag<EXP> > exp;
typedef matrix_unary_exp<matrix_exp<EXP>,op_imag> exp;
return matrix_exp<exp>(exp(m));
}
......
......@@ -895,7 +895,7 @@ namespace dlib
template <
typename M,
typename OP
typename OP_
>
class matrix_unary_exp
{
......@@ -904,6 +904,8 @@ namespace dlib
- must be a matrix_exp or matrix_ref object (or
an object with a compatible interface).
!*/
typedef typename OP_::template op<M> OP;
public:
typedef typename OP::type type;
typedef matrix_unary_exp ref_type;
......@@ -1179,7 +1181,7 @@ namespace dlib
template <
typename M,
typename S,
typename OP
typename OP_
>
class matrix_scalar_binary_exp
{
......@@ -1188,6 +1190,8 @@ namespace dlib
- must be a matrix_exp or matrix_ref object (or
an object with a compatible interface).
!*/
typedef typename OP_::template op<M> OP;
public:
typedef typename OP::type type;
typedef matrix_scalar_binary_exp ref_type;
......@@ -1240,7 +1244,7 @@ namespace dlib
template <
typename M1,
typename M2,
typename OP
typename OP_
>
class matrix_binary_exp
{
......@@ -1249,6 +1253,8 @@ namespace dlib
- must be a matrix_exp or matrix_ref object (or
an object with a compatible interface).
!*/
typedef typename OP_::template op<M1,M2> OP;
public:
typedef typename OP::type type;
typedef matrix_binary_exp ref_type;
......@@ -1743,8 +1749,10 @@ namespace dlib
// ----------------------------------------------------------------------------------------
struct op_trans
{
template <typename EXP>
struct op_trans : has_destructive_aliasing
struct op : has_destructive_aliasing
{
const static long NR = EXP::NC;
const static long NC = EXP::NR;
......@@ -1759,22 +1767,26 @@ namespace dlib
template <typename M>
static long nc (const M& m) { return m.nr(); }
};
};
template <
typename EXP
>
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_trans<EXP> > > trans (
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_trans> > trans (
const matrix_exp<EXP>& m
)
{
typedef matrix_unary_exp<matrix_exp<EXP>,op_trans<EXP> > exp;
typedef matrix_unary_exp<matrix_exp<EXP>,op_trans> exp;
return matrix_exp<exp>(exp(m));
}
// ----------------------------------------------------------------------------------------
template <typename EXP, long R, long C>
struct op_removerc : has_destructive_aliasing
template <long R, long C>
struct op_removerc
{
template <typename EXP>
struct op : has_destructive_aliasing
{
const static long NR = EXP::NR - 1;
const static long NC = EXP::NC - 1;
......@@ -1804,13 +1816,14 @@ namespace dlib
template <typename M>
static long nc (const M& m) { return m.nc() - 1; }
};
};
template <
long R,
long C,
typename EXP
>
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_removerc<EXP,R,C> > > removerc (
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_removerc<R,C> > > removerc (
const matrix_exp<EXP>& m
)
{
......@@ -1826,14 +1839,16 @@ namespace dlib
<< "\n\tR: " << R
<< "\n\tC: " << C
);
typedef matrix_unary_exp<matrix_exp<EXP>,op_removerc<EXP,R,C> > exp;
typedef matrix_unary_exp<matrix_exp<EXP>,op_removerc<R,C> > exp;
return matrix_exp<exp>(exp(m));
}
// ----------------------------------------------------------------------------------------
struct op_diag
{
template <typename EXP>
struct op_diag : has_destructive_aliasing
struct op : has_destructive_aliasing
{
const static long NR = EXP::NC;
const static long NC = 1;
......@@ -1848,11 +1863,12 @@ namespace dlib
template <typename M>
static long nc (const M& m) { return 1; }
};
};
template <
typename EXP
>
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_diag<EXP> > > diag (
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_diag> > diag (
const matrix_exp<EXP>& m
)
{
......@@ -1864,30 +1880,34 @@ namespace dlib
<< "\n\tm.nr(): " << m.nr()
<< "\n\tm.nc(): " << m.nc()
);
typedef matrix_unary_exp<matrix_exp<EXP>,op_diag<EXP> > exp;
typedef matrix_unary_exp<matrix_exp<EXP>,op_diag> exp;
return matrix_exp<exp>(exp(m));
}
// ----------------------------------------------------------------------------------------
template <typename EXP, typename target_type>
struct op_cast : has_nondestructive_aliasing, preserves_dimensions<EXP>
template <typename target_type>
struct op_cast
{
template <typename EXP>
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef target_type type;
template <typename M>
static type apply ( const M& m, long r, long c)
{ return static_cast<target_type>(m(r,c)); }
};
};
template <
typename target_type,
typename EXP
>
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_cast<EXP,target_type> > > matrix_cast (
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_cast<target_type> > > matrix_cast (
const matrix_exp<EXP>& m
)
{
typedef matrix_unary_exp<matrix_exp<EXP>,op_cast<EXP,target_type> > exp;
typedef matrix_unary_exp<matrix_exp<EXP>,op_cast<target_type> > exp;
return matrix_exp<exp>(exp(m));
}
......@@ -2740,21 +2760,25 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template <long R, long C, typename EXP>
struct op_rotate : has_destructive_aliasing, preserves_dimensions<EXP>
template <long R, long C>
struct op_rotate
{
template <typename EXP>
struct op : has_destructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type type;
template <typename M>
static type apply ( const M& m, long r, long c)
{ return m((r+R)%m.nr(),(c+C)%m.nc()); }
};
};
template <
long R,
long C,
typename EXP
>
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_rotate<R,C,EXP> > > rotate (
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_rotate<R,C> > > rotate (
const matrix_exp<EXP>& m
)
{
......@@ -2770,14 +2794,16 @@ namespace dlib
<< "\n\tR: " << R
<< "\n\tC: " << C
);
typedef matrix_unary_exp<matrix_exp<EXP>,op_rotate<R,C,EXP> > exp;
typedef matrix_unary_exp<matrix_exp<EXP>,op_rotate<R,C> > exp;
return matrix_exp<exp>(exp(m));
}
// ----------------------------------------------------------------------------------------
template <typename EXP1, typename EXP2, typename EXP3 = void, typename EXP4 = void>
struct op_pointwise_multiply : public has_nondestructive_aliasing, public preserves_dimensions<EXP1,EXP2,EXP3,EXP4>
struct op_pointwise_multiply
{
template <typename EXP1, typename EXP2>
struct op : public has_nondestructive_aliasing, public preserves_dimensions<EXP1,EXP2>
{
typedef typename EXP1::type type;
......@@ -2785,12 +2811,13 @@ namespace dlib
static type apply ( const M1& m1, const M2& m2 , long r, long c)
{ return m1(r,c)*m2(r,c); }
};
};
template <
typename EXP1,
typename EXP2
>
inline const matrix_exp<matrix_binary_exp<matrix_exp<EXP1>,matrix_exp<EXP2>,op_pointwise_multiply<EXP1,EXP2> > > pointwise_multiply (
inline const matrix_exp<matrix_binary_exp<EXP1,EXP2,op_pointwise_multiply> > pointwise_multiply (
const matrix_exp<EXP1>& a,
const matrix_exp<EXP2>& b
)
......@@ -2807,8 +2834,8 @@ namespace dlib
<< "\n\tb.nr(): " << b.nr()
<< "\n\tb.nc(): " << b.nc()
);
typedef matrix_binary_exp<matrix_exp<EXP1>,matrix_exp<EXP2>,op_pointwise_multiply<EXP1,EXP2> > exp;
return matrix_exp<exp>(exp(a,b));
typedef matrix_binary_exp<EXP1,EXP2,op_pointwise_multiply> exp;
return matrix_exp<exp>(exp(a.ref(),b.ref()));
}
template <
......@@ -2816,9 +2843,7 @@ namespace dlib
typename EXP2,
typename EXP3
>
inline const matrix_exp<
matrix_binary_exp< matrix_binary_exp<matrix_exp<EXP1>,matrix_exp<EXP2>,op_pointwise_multiply<EXP1,EXP2> > ,
matrix_exp<EXP3>, op_pointwise_multiply<EXP1,EXP2,EXP3> > >
inline const matrix_exp<matrix_binary_exp<matrix_binary_exp<EXP1,EXP2,op_pointwise_multiply>,EXP3,op_pointwise_multiply> >
pointwise_multiply (
const matrix_exp<EXP1>& a,
const matrix_exp<EXP2>& b,
......@@ -2843,10 +2868,10 @@ namespace dlib
<< "\n\tc.nr(): " << c.nr()
<< "\n\tc.nc(): " << c.nc()
);
typedef matrix_binary_exp<matrix_exp<EXP1>,matrix_exp<EXP2>,op_pointwise_multiply<EXP1,EXP2> > exp;
typedef matrix_binary_exp< exp , matrix_exp<EXP3>, op_pointwise_multiply<EXP1,EXP2,EXP3> > exp2;
typedef matrix_binary_exp<EXP1,EXP2,op_pointwise_multiply> exp;
typedef matrix_binary_exp<exp , EXP3, op_pointwise_multiply> exp2;
return matrix_exp<exp2>(exp2(exp(a,b),c));
return matrix_exp<exp2>(exp2(exp(a.ref(),b.ref()),c.ref()));
}
template <
......@@ -2856,9 +2881,9 @@ namespace dlib
typename EXP4
>
inline const matrix_exp<
matrix_binary_exp< matrix_binary_exp<matrix_exp<EXP1>,matrix_exp<EXP2>,op_pointwise_multiply<EXP1,EXP2> > ,
matrix_binary_exp<matrix_exp<EXP3>,matrix_exp<EXP4>,op_pointwise_multiply<EXP3,EXP4> >,
op_pointwise_multiply<EXP1,EXP2,EXP3,EXP4> > >
matrix_binary_exp<matrix_binary_exp<EXP1,EXP2,op_pointwise_multiply> ,
matrix_binary_exp<EXP3,EXP4,op_pointwise_multiply>,
op_pointwise_multiply> >
pointwise_multiply (
const matrix_exp<EXP1>& a,
const matrix_exp<EXP2>& b,
......@@ -2890,11 +2915,11 @@ namespace dlib
<< "\n\td.nr(): " << d.nr()
<< "\n\td.nc(): " << d.nc()
);
typedef matrix_binary_exp<matrix_exp<EXP1>,matrix_exp<EXP2>,op_pointwise_multiply<EXP1,EXP2> > exp1;
typedef matrix_binary_exp<matrix_exp<EXP3>,matrix_exp<EXP4>,op_pointwise_multiply<EXP3,EXP4> > exp2;
typedef matrix_binary_exp<EXP1,EXP2,op_pointwise_multiply> exp1;
typedef matrix_binary_exp<EXP3,EXP4,op_pointwise_multiply> exp2;
typedef matrix_binary_exp< exp1 , exp2, op_pointwise_multiply<EXP1,EXP2,EXP3,EXP4> > exp3;
return matrix_exp<exp3>(exp3(exp1(a,b),exp2(c,d)));
typedef matrix_binary_exp< exp1 , exp2, op_pointwise_multiply> exp3;
return matrix_exp<exp3>(exp3(exp1(a.ref(),b.ref()),exp2(c.ref(),d.ref())));
}
// ----------------------------------------------------------------------------------------
......@@ -3072,8 +3097,11 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template <long lower, long upper, typename EXP>
struct op_clamp : has_nondestructive_aliasing, preserves_dimensions<EXP>
template <long lower, long upper>
struct op_clamp
{
template <typename EXP>
struct op : has_nondestructive_aliasing, preserves_dimensions<EXP>
{
typedef typename EXP::type type;
......@@ -3089,17 +3117,18 @@ namespace dlib
return temp;
}
};
};
template <
long l,
long u,
typename EXP
>
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_clamp<l,u,EXP> > > clamp (
const matrix_exp<matrix_unary_exp<matrix_exp<EXP>,op_clamp<l,u> > > clamp (
const matrix_exp<EXP>& m
)
{
typedef matrix_unary_exp<matrix_exp<EXP>,op_clamp<l,u,EXP> > exp;
typedef matrix_unary_exp<matrix_exp<EXP>,op_clamp<l,u> > exp;
return matrix_exp<exp>(exp(m));
}
......@@ -3134,8 +3163,10 @@ namespace dlib
// ----------------------------------------------------------------------------------------
struct op_scale_columns
{
template <typename EXP1, typename EXP2>
struct op_scale_columns : has_nondestructive_aliasing
struct op : has_nondestructive_aliasing
{
typedef typename EXP1::type type;
typedef typename EXP1::mem_manager_type mem_manager_type;
......@@ -3151,12 +3182,13 @@ namespace dlib
template <typename M1, typename M2>
static long nc (const M1& m1, const M2& ) { return m1.nc(); }
};
};
template <
typename EXP1,
typename EXP2
>
const matrix_exp<matrix_binary_exp<matrix_exp<EXP1>,matrix_exp<EXP2>,op_scale_columns<EXP1,EXP2> > > scale_columns (
const matrix_exp<matrix_binary_exp<matrix_exp<EXP1>,matrix_exp<EXP2>,op_scale_columns> > scale_columns (
const matrix_exp<EXP1>& m,
const matrix_exp<EXP2>& v
)
......@@ -3173,7 +3205,7 @@ namespace dlib
<< "\n\tv.nr(): " << v.nr()
<< "\n\tv.nc(): " << v.nc()
);
typedef matrix_binary_exp<matrix_exp<EXP1>,matrix_exp<EXP2>,op_scale_columns<EXP1,EXP2> > exp;
typedef matrix_binary_exp<matrix_exp<EXP1>,matrix_exp<EXP2>,op_scale_columns> exp;
return matrix_exp<exp>(exp(m,v));
}
......
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