General cleanup (also added all the needed typedefs for layout_type).

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402744
This commit is contained in:
Davis King 2008-12-22 14:19:43 +00:00
parent 3335021349
commit 583866281c
3 changed files with 68 additions and 128 deletions

View File

@ -65,9 +65,7 @@ namespace dlib
{
typedef typename EXP::type type;
typedef typename EXP::mem_manager_type mem_manager_type;
// TODO
//typedef typename EXP::layout_type layout_type;
typedef typename EXP::layout_type layout_type;
const static long NR = EXP::NR;
const static long NC = EXP::NC;
const static long cost = EXP::cost;
@ -87,8 +85,7 @@ namespace dlib
public:
typedef typename matrix_traits<EXP>::type type;
typedef typename matrix_traits<EXP>::mem_manager_type mem_manager_type;
// TODO
//typedef typename matrix_traits<EXP>::layout_type layout_type;
typedef typename matrix_traits<EXP>::layout_type layout_type;
const static long NR = matrix_traits<EXP>::NR;
const static long NC = matrix_traits<EXP>::NC;
const static long cost = matrix_traits<EXP>::cost;
@ -267,6 +264,7 @@ namespace dlib
{
typedef typename LHS::type type;
typedef typename LHS::mem_manager_type mem_manager_type;
typedef typename LHS::layout_type layout_type;
const static long NR = LHS::NR;
const static long NC = RHS::NC;
@ -305,6 +303,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_multiply_exp>::NR;
const static long NC = matrix_traits<matrix_multiply_exp>::NC;
const static long cost = matrix_traits<matrix_multiply_exp>::cost;
typedef typename matrix_traits<matrix_multiply_exp>::layout_type layout_type;
const static bool lhs_is_costly = matrix_traits<matrix_multiply_exp>::lhs_is_costly;
@ -398,6 +397,7 @@ namespace dlib
{
typedef typename LHS::type 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;
const static long NC = (RHS::NC > LHS::NC) ? RHS::NC : LHS::NC;
const static long cost = LHS::cost+RHS::cost;
@ -419,6 +419,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_add_exp>::NR;
const static long NC = matrix_traits<matrix_add_exp>::NC;
const static long cost = matrix_traits<matrix_add_exp>::cost;
typedef typename matrix_traits<matrix_add_exp>::layout_type layout_type;
matrix_add_exp (
const matrix_add_exp& item
@ -506,6 +507,7 @@ namespace dlib
{
typedef typename LHS::type 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;
const static long NC = (RHS::NC > LHS::NC) ? RHS::NC : LHS::NC;
const static long cost = LHS::cost+RHS::cost;
@ -527,6 +529,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_subtract_exp>::NR;
const static long NC = matrix_traits<matrix_subtract_exp>::NC;
const static long cost = matrix_traits<matrix_subtract_exp>::cost;
typedef typename matrix_traits<matrix_subtract_exp>::layout_type layout_type;
matrix_subtract_exp (
const matrix_subtract_exp& item
@ -613,6 +616,7 @@ namespace dlib
{
typedef typename M::type type;
typedef typename M::mem_manager_type mem_manager_type;
typedef typename M::layout_type layout_type;
const static long NR = M::NR;
const static long NC = M::NC;
const static long cost = M::cost+1;
@ -638,6 +642,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_div_scal_exp>::NR;
const static long NC = matrix_traits<matrix_div_scal_exp>::NC;
const static long cost = matrix_traits<matrix_div_scal_exp>::cost;
typedef typename matrix_traits<matrix_div_scal_exp>::layout_type layout_type;
matrix_div_scal_exp (
const matrix_div_scal_exp& item
@ -707,6 +712,7 @@ namespace dlib
{
typedef typename M::type type;
typedef typename M::mem_manager_type mem_manager_type;
typedef typename M::layout_type layout_type;
const static long NR = M::NR;
const static long NC = M::NC;
const static long cost = M::cost+1;
@ -731,6 +737,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_mul_scal_exp>::NR;
const static long NC = matrix_traits<matrix_mul_scal_exp>::NC;
const static long cost = matrix_traits<matrix_mul_scal_exp>::cost;
typedef typename matrix_traits<matrix_mul_scal_exp>::layout_type layout_type;
matrix_mul_scal_exp (
const matrix_mul_scal_exp& item

View File

@ -21,114 +21,6 @@ namespace dlib
>
class matrix;
// ----------------------------------------------------------------------------------------
template <
typename T,
long num_rows,
long num_cols,
typename mem_manager,
typename layout
>
class matrix_ref
{
/*!
WHAT THIS OBJECT REPRESENTS
This object represents a copyable (via the copy constructor but not
operator=) reference to a matrix object.
!*/
public:
typedef T type;
typedef matrix_ref ref_type;
typedef mem_manager mem_manager_type;
typedef layout layout_type;
const static long NR = num_rows;
const static long NC = num_cols;
matrix_ref (
const matrix<T,num_rows,num_cols,mem_manager,layout>& m
);
/*!
ensures
- #aliases(m) == true
(i.e. #*this references/aliases the matrix m.)
!*/
matrix_ref (
const matrix_ref& r
);
/*!
ensures
- #*this references/aliases the same matrix as r does.
!*/
const T& operator() (
long r,
long c
) const;
/*!
requires
- 0 <= r < nr()
- 0 <= c < nc()
ensures
- returns a const reference to the value at the given row and column in
this matrix.
!*/
long nr (
) const;
/*!
ensures
- returns the number of rows in the matrix referenced by *this
!*/
long nc (
) const;
/*!
ensures
- returns the number of columns in the matrix referenced by *this
!*/
long size (
) const;
/*!
ensures
- returns nr()*nc()
!*/
template <typename U, long iNR, long iNC, typename mm, typename l>
bool destructively_aliases (
const matrix<U,iNR,iNC,mm,l>& item
) const;
/*!
ensures
- returns false
!*/
template <typename U, long iNR, long iNC, typename mm, typename l>
bool aliases (
const matrix<U,iNR,iNC,mm,l>& item
) const;
/*!
ensures
- if (item is the matrix referenced by *this) then
- returns true
- else
- returns false
!*/
const ref_type& ref(
) const { return *this; }
/*!
ensures
- returns *this
!*/
private:
// no assignment operator
matrix_ref& operator=(const matrix_ref&);
};
// ----------------------------------------------------------------------------------------
template <
@ -138,8 +30,7 @@ namespace dlib
{
/*!
REQUIREMENTS ON EXP
- must be a matrix_exp or matrix_ref object (or an object with
a compatible interface)
- must be an object that inherits publicly from matrix_exp (this class).
WHAT THIS OBJECT REPRESENTS
This object represents an expression that evaluates to a matrix
@ -162,20 +53,13 @@ namespace dlib
public:
typedef typename EXP::type type;
typedef typename EXP::ref_type ref_type;
typedef typename EXP::mem_manager_type mem_manager_type;
typedef typename EXP::layout_type layout_type;
const static long cost = EXP::cost;
const static long NR = EXP::NR;
const static long NC = EXP::NC;
typedef matrix<type,NR,NC, mem_manager_type> matrix_type;
const static long cost = EXP::cost;
matrix_exp (
const EXP& exp
);
/*!
ensures
- #ref() == exp.ref()
!*/
typedef EXP exp_type;
const type operator() (
long r,
@ -277,13 +161,30 @@ namespace dlib
- returns false
!*/
const ref_type& ref (
const exp_type& ref (
) const;
/*!
ensures
- returns a copyable reference to the subexpression contained in *this.
!*/
protected:
explicit matrix_exp (
const EXP& exp
);
/*!
ensures
- #ref() == exp.ref()
!*/
private:
// you can't copy a matrix_exp at all. Things that inherit from it must
// define their own copy constructors that call the above protected
// constructor so that the reference below is maintained correctly.
matrix_exp(const matrix_exp& item);
matrix_exp& operator= (const matrix_exp&);
};
// ----------------------------------------------------------------------------------------
@ -412,7 +313,7 @@ namespace dlib
typename mem_manager = memory_manager<char>::kernel_1a,
typename layout = default_matrix_layout
>
class matrix : public matrix_exp<matrix_ref<T,num_rows,num_cols,mem_manager,layout> >
class matrix : public matrix_exp<matrix<T,num_rows,num_cols,mem_manager,layout> >
{
/*!
REQUIREMENTS ON num_rows and num_cols
@ -464,11 +365,11 @@ namespace dlib
public:
typedef T type;
typedef matrix_ref<T,num_rows,num_cols,mem_manager,layout> ref_type;
typedef mem_manager mem_manager_type;
typedef layout layout_type;
const static long NR = num_rows;
const static long NC = num_cols;
const static long cost = 1;
matrix (
);

View File

@ -34,6 +34,7 @@ namespace dlib
typedef typename OP_::template op<M> OP;
typedef typename OP::type type;
typedef typename OP::mem_manager_type mem_manager_type;
typedef typename M::layout_type layout_type;
const static long NR = OP::NR;
const static long NC = OP::NC;
const static long cost = OP::cost;
@ -54,6 +55,7 @@ namespace dlib
public:
typedef typename matrix_traits<matrix_unary_exp>::type 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;
const static long NC = matrix_traits<matrix_unary_exp>::NC;
const static long cost = matrix_traits<matrix_unary_exp>::cost;
@ -120,6 +122,7 @@ namespace dlib
const static long NR = OP::NR;
const static long NC = OP::NC;
const static long cost = OP::cost;
typedef typename M::layout_type layout_type;
};
template <
@ -141,6 +144,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_scalar_binary_exp>::NR;
const static long NC = matrix_traits<matrix_scalar_binary_exp>::NC;
const static long cost = matrix_traits<matrix_scalar_binary_exp>::cost;
typedef typename matrix_traits<matrix_scalar_binary_exp>::layout_type layout_type;
matrix_scalar_binary_exp (
const matrix_scalar_binary_exp& item
@ -210,6 +214,7 @@ namespace dlib
const static long NR = OP::NR;
const static long NC = OP::NC;
const static long cost = OP::cost;
typedef typename M::layout_type layout_type;
};
template <
@ -231,6 +236,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_scalar_ternary_exp>::NR;
const static long NC = matrix_traits<matrix_scalar_ternary_exp>::NC;
const static long cost = matrix_traits<matrix_scalar_ternary_exp>::cost;
typedef typename matrix_traits<matrix_scalar_ternary_exp>::layout_type layout_type;
matrix_scalar_ternary_exp (
const matrix_scalar_ternary_exp& item
@ -305,6 +311,7 @@ namespace dlib
const static long NR = OP::NR;
const static long NC = OP::NC;
const static long cost = OP::cost;
typedef typename M1::layout_type layout_type;
};
template <
@ -326,6 +333,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_binary_exp>::NR;
const static long NC = matrix_traits<matrix_binary_exp>::NC;
const static long cost = matrix_traits<matrix_binary_exp>::cost;
typedef typename matrix_traits<matrix_binary_exp>::layout_type layout_type;
matrix_binary_exp (
const matrix_binary_exp& item
@ -393,6 +401,7 @@ namespace dlib
const static long NR = OP::NR;
const static long NC = OP::NC;
const static long cost = OP::cost;
typedef typename M1::layout_type layout_type;
};
template <
@ -415,6 +424,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_ternary_exp>::NR;
const static long NC = matrix_traits<matrix_ternary_exp>::NC;
const static long cost = matrix_traits<matrix_ternary_exp>::cost;
typedef typename matrix_traits<matrix_ternary_exp>::layout_type layout_type;
matrix_ternary_exp (
const matrix_ternary_exp& item
@ -486,6 +496,7 @@ namespace dlib
const static long NR = OP::NR;
const static long NC = OP::NC;
const static long cost = OP::cost;
typedef typename M1::layout_type layout_type;
};
template <
@ -509,6 +520,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_fourary_exp>::NR;
const static long NC = matrix_traits<matrix_fourary_exp>::NC;
const static long cost = matrix_traits<matrix_fourary_exp>::cost;
typedef typename matrix_traits<matrix_fourary_exp>::layout_type layout_type;
matrix_fourary_exp (
const matrix_fourary_exp& item
@ -583,6 +595,7 @@ namespace dlib
const static long NR = OP::NR;
const static long NC = OP::NC;
const static long cost = OP::cost;
typedef default_matrix_layout layout_type;
};
template <
@ -601,6 +614,7 @@ namespace dlib
const static long NR = matrix_traits<dynamic_matrix_scalar_unary_exp>::NR;
const static long NC = matrix_traits<dynamic_matrix_scalar_unary_exp>::NC;
const static long cost = matrix_traits<dynamic_matrix_scalar_unary_exp>::cost;
typedef typename matrix_traits<dynamic_matrix_scalar_unary_exp>::layout_type layout_type;
dynamic_matrix_scalar_unary_exp (
const dynamic_matrix_scalar_unary_exp& item
@ -668,6 +682,7 @@ namespace dlib
const static long NR = OP::NR;
const static long NC = OP::NC;
const static long cost = OP::cost;
typedef default_matrix_layout layout_type;
};
template <
@ -686,6 +701,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_scalar_unary_exp>::NR;
const static long NC = matrix_traits<matrix_scalar_unary_exp>::NC;
const static long cost = matrix_traits<matrix_scalar_unary_exp>::cost;
typedef typename matrix_traits<matrix_scalar_unary_exp>::layout_type layout_type;
matrix_scalar_unary_exp (
const matrix_scalar_unary_exp& item
@ -745,6 +761,7 @@ namespace dlib
const static long NR = OP::NR;
const static long NC = OP::NC;
const static long cost = OP::cost;
typedef default_matrix_layout layout_type;
};
template <
@ -758,6 +775,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_zeroary_exp>::NR;
const static long NC = matrix_traits<matrix_zeroary_exp>::NC;
const static long cost = matrix_traits<matrix_zeroary_exp>::cost;
typedef typename matrix_traits<matrix_zeroary_exp>::layout_type layout_type;
matrix_zeroary_exp (
const matrix_zeroary_exp& item
@ -810,6 +828,7 @@ namespace dlib
{
typedef typename M::type 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;
const static long NC = EXPc::NR*EXPr::NC;
const static long cost = EXPr::cost+EXPc::cost+M::cost;
@ -832,6 +851,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_sub_range_exp>::NR;
const static long NC = matrix_traits<matrix_sub_range_exp>::NC;
const static long cost = matrix_traits<matrix_sub_range_exp>::cost;
typedef typename matrix_traits<matrix_sub_range_exp>::layout_type layout_type;
matrix_sub_range_exp (
const matrix_sub_range_exp& item
@ -904,6 +924,7 @@ namespace dlib
const static long NR = 0;
const static long NC = 1;
const static long cost = 1;
typedef default_matrix_layout layout_type;
};
template <
@ -922,6 +943,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_std_vector_exp>::NR;
const static long NC = matrix_traits<matrix_std_vector_exp>::NC;
const static long cost = matrix_traits<matrix_std_vector_exp>::cost;
typedef typename matrix_traits<matrix_std_vector_exp>::layout_type layout_type;
matrix_std_vector_exp (
const matrix_std_vector_exp& item
@ -982,6 +1004,7 @@ namespace dlib
{
typedef typename M::type type;
typedef typename M::mem_manager_type mem_manager_type;
typedef default_matrix_layout layout_type;
const static long NR = 0;
const static long NC = 1;
const static long cost = 1;
@ -1003,6 +1026,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_array_exp>::NR;
const static long NC = matrix_traits<matrix_array_exp>::NC;
const static long cost = matrix_traits<matrix_array_exp>::cost;
typedef typename matrix_traits<matrix_array_exp>::layout_type layout_type;
matrix_array_exp (
const matrix_array_exp& item
@ -1063,6 +1087,7 @@ namespace dlib
{
typedef typename M::type type;
typedef typename M::mem_manager_type mem_manager_type;
typedef default_matrix_layout layout_type;
const static long NR = 0;
const static long NC = 0;
const static long cost = 1;
@ -1084,6 +1109,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_array2d_exp>::NR;
const static long NC = matrix_traits<matrix_array2d_exp>::NC;
const static long cost = matrix_traits<matrix_array2d_exp>::cost;
typedef typename matrix_traits<matrix_array2d_exp>::layout_type layout_type;
matrix_array2d_exp (
const matrix_array2d_exp& item
@ -1144,6 +1170,7 @@ namespace dlib
{
typedef typename M::type type;
typedef typename M::mem_manager_type mem_manager_type;
typedef typename M::layout_type layout_type;
const static long NR = 0;
const static long NC = 0;
const static long cost = M::cost+1;
@ -1164,6 +1191,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_sub_exp>::NR;
const static long NC = matrix_traits<matrix_sub_exp>::NC;
const static long cost = matrix_traits<matrix_sub_exp>::cost;
typedef typename matrix_traits<matrix_sub_exp>::layout_type layout_type;
matrix_sub_exp (
const matrix_sub_exp& item
@ -1237,6 +1265,7 @@ namespace dlib
{
typedef long type;
typedef memory_manager<char>::kernel_1a mem_manager_type;
typedef default_matrix_layout layout_type;
const static long NR = 0;
const static long NC = 1;
const static long cost = 1;
@ -1250,6 +1279,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_range_exp>::NR;
const static long NC = matrix_traits<matrix_range_exp>::NC;
const static long cost = matrix_traits<matrix_range_exp>::cost;
typedef matrix_traits<matrix_range_exp>::layout_type layout_type;
matrix_range_exp (
const matrix_range_exp& item
@ -1331,6 +1361,7 @@ namespace dlib
const static long NR = tabs<(end - start)>::value/inc_ + 1;
const static long NC = 1;
const static long cost = 1;
typedef default_matrix_layout layout_type;
};
template <long start, long inc_, long end>
@ -1342,6 +1373,7 @@ namespace dlib
const static long NR = matrix_traits<matrix_range_static_exp>::NR;
const static long NC = matrix_traits<matrix_range_static_exp>::NC;
const static long cost = matrix_traits<matrix_range_static_exp>::cost;
typedef typename matrix_traits<matrix_range_static_exp>::layout_type layout_type;
const static long inc = (start <= end)?inc_:-inc_;