Commit 58386628 authored by Davis King's avatar Davis King

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

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402744
parent 33350213
......@@ -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
......
......@@ -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 (
);
......
This diff is collapsed.
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