Commit b2efcc52 authored by Davis King's avatar Davis King

Simplified the matrix code slightly. This also fixed a strange compile time bug

that you can get from gcc in certain cases.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403073
parent 8204dd7c
......@@ -107,7 +107,7 @@ namespace dlib
<< "\n\tnc(): " << nc()
<< "\n\tthis: " << this
);
return ref_(r,c);
return ref()(r,c);
}
const type operator() (
......@@ -132,32 +132,32 @@ namespace dlib
<< "\n\tthis: " << this
);
if (nc() == 1)
return ref_(i,0);
return ref()(i,0);
else
return ref_(0,i);
return ref()(0,i);
}
long size (
) const { return nr()*nc(); }
long nr (
) const { return get_nr_helper<exp_type,NR>::get(ref_); }
) const { return get_nr_helper<exp_type,NR>::get(ref()); }
long nc (
) const { return get_nc_helper<exp_type,NC>::get(ref_); }
) const { return get_nc_helper<exp_type,NC>::get(ref()); }
template <typename U, long iNR, long iNC, typename mm, typename l >
bool aliases (
const matrix<U,iNR,iNC,mm,l>& item
) const { return ref_.aliases(item); }
) const { return ref().aliases(item); }
template <typename U, long iNR, long iNC , typename mm, typename l>
bool destructively_aliases (
const matrix<U,iNR,iNC,mm,l>& item
) const { return ref_.destructively_aliases(item); }
) const { return ref().destructively_aliases(item); }
const exp_type& ref (
) const { return ref_; }
inline const exp_type& ref (
) const { return *static_cast<const exp_type*>(this); }
inline operator const type (
) const
......@@ -176,25 +176,17 @@ namespace dlib
// a temporary 1x1 matrix so that the expression will encounter
// all the overloads of matrix_assign() and have the chance to
// go through any applicable optimizations.
matrix<type,1,1> temp(ref_);
matrix<type,1,1> temp(ref());
return temp(0);
}
protected:
explicit matrix_exp (
const EXP& exp
) : ref_(exp) {}
matrix_exp() {}
matrix_exp(const matrix_exp& ) {}
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&);
const exp_type& ref_;
};
// ----------------------------------------------------------------------------------------
......@@ -333,7 +325,6 @@ namespace dlib
const LHS& lhs_,
const RHS& rhs_
) :
matrix_exp<matrix_multiply_exp>(*this),
lhs(lhs_),
rhs(rhs_)
{
......@@ -495,7 +486,6 @@ namespace dlib
const LHS& lhs_,
const RHS& rhs_
) :
matrix_exp<matrix_add_exp>(*this),
lhs(lhs_),
rhs(rhs_)
{
......@@ -604,7 +594,7 @@ namespace dlib
matrix_subtract_exp (
const LHS& lhs_,
const RHS& rhs_
) : matrix_exp<matrix_subtract_exp>(*this),
) :
lhs(lhs_),
rhs(rhs_)
{
......@@ -713,7 +703,6 @@ namespace dlib
const M& m_,
const type& s_
) :
matrix_exp<matrix_div_scal_exp>(*this),
m(m_),
s(s_)
{}
......@@ -807,7 +796,6 @@ namespace dlib
const M& m_,
const type& s_
) :
matrix_exp<matrix_mul_scal_exp>(*this),
m(m_),
s(s_)
{}
......@@ -1022,13 +1010,13 @@ namespace dlib
const static long NC = matrix_traits<matrix>::NC;
const static long cost = matrix_traits<matrix>::cost;
matrix () : matrix_exp<matrix>(*this)
matrix ()
{
}
explicit matrix (
long length
) : matrix_exp<matrix>(*this)
)
{
// This object you are trying to call matrix(length) on is not a column or
// row vector.
......@@ -1073,7 +1061,7 @@ namespace dlib
matrix (
long rows,
long cols
) : matrix_exp<matrix>(*this)
)
{
DLIB_ASSERT( (NR == 0 || NR == rows) && ( NC == 0 || NC == cols) &&
rows >= 0 && cols >= 0,
......@@ -1090,7 +1078,7 @@ namespace dlib
template <typename EXP>
matrix (
const matrix_exp<EXP>& m
): matrix_exp<matrix>(*this)
)
{
// You get an error on this line if the matrix m contains a type that isn't
// the same as the type contained in the target matrix.
......@@ -1127,7 +1115,7 @@ namespace dlib
template <typename U, size_t len>
matrix (
U (&array)[len]
): matrix_exp<matrix>(*this)
)
{
COMPILE_TIME_ASSERT(NR*NC == len && len > 0);
size_t idx = 0;
......@@ -1765,13 +1753,11 @@ namespace dlib
const_temp_matrix (
const matrix_exp<EXP>& item
) :
matrix_exp<const_temp_matrix>(*this),
ref_(item.ref())
{}
const_temp_matrix (
const EXP& item
) :
matrix_exp<const_temp_matrix>(*this),
ref_(item)
{}
......
......@@ -161,29 +161,22 @@ namespace dlib
- returns false
!*/
const exp_type& ref (
inline const exp_type& ref (
) const;
/*!
ensures
- returns a reference to the expression contained in *this.
(i.e. returns *static_cast<const exp_type*>(this) )
!*/
protected:
explicit matrix_exp (
const EXP& exp
);
/*!
ensures
- #ref() == exp.ref()
!*/
// Only derived classes of matrix_exp may call the matrix_exp constructors.
matrix_exp(const matrix_exp&);
matrix_exp();
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);
// no one may ever use the assignment operator on a matrix_exp
matrix_exp& operator= (const matrix_exp&);
};
......
......@@ -257,7 +257,6 @@ namespace dlib
matrix_unary_exp (
const M& m_
) :
matrix_exp<matrix_unary_exp>(*this),
m(m_)
{}
......@@ -344,7 +343,6 @@ namespace dlib
const M& m_,
const S& s_
) :
matrix_exp<matrix_scalar_binary_exp>(*this),
m(m_),
s(s_)
{
......@@ -438,7 +436,6 @@ namespace dlib
const S& s1_,
const S& s2_
) :
matrix_exp<matrix_scalar_ternary_exp>(*this),
m(m_),
s1(s1_),
s2(s2_)
......@@ -531,7 +528,6 @@ namespace dlib
const M1& m1_,
const M2& m2_
) :
matrix_exp<matrix_binary_exp>(*this),
m1(m1_),
m2(m2_)
{}
......@@ -624,7 +620,6 @@ namespace dlib
const M2& m2_,
const M3& m3_
) :
matrix_exp<matrix_ternary_exp>(*this),
m1(m1_),
m2(m2_),
m3(m3_)
......@@ -722,7 +717,6 @@ namespace dlib
const M3& m3_,
const M4& m4_
) :
matrix_exp<matrix_fourary_exp>(*this),
m1(m1_),
m2(m2_),
m3(m3_),
......@@ -809,7 +803,6 @@ namespace dlib
long nc__,
const S& s_
) :
matrix_exp<dynamic_matrix_scalar_unary_exp>(*this),
nr_(nr__),
nc_(nc__),
s(s_)
......@@ -892,7 +885,6 @@ namespace dlib
matrix_scalar_unary_exp (
const S& s_
) :
matrix_exp<matrix_scalar_unary_exp>(*this),
s(s_)
{
COMPILE_TIME_ASSERT(is_matrix<S>::value == false);
......@@ -963,9 +955,7 @@ namespace dlib
{}
matrix_zeroary_exp (
) :
matrix_exp<matrix_zeroary_exp>(*this)
{}
) {}
const typename OP::type operator() (
long r,
......@@ -1052,7 +1042,6 @@ namespace dlib
const EXPr& rows_,
const EXPc& cols_
) :
matrix_exp<matrix_sub_range_exp>(*this),
m(m_),
rows(rows_),
cols(cols_)
......@@ -1140,7 +1129,6 @@ namespace dlib
matrix_std_vector_exp (
const M& m_
) :
matrix_exp<matrix_std_vector_exp>(*this),
m(m_)
{
}
......@@ -1223,7 +1211,6 @@ namespace dlib
matrix_array_exp (
const M& m_
) :
matrix_exp<matrix_array_exp>(*this),
m(m_)
{
}
......@@ -1306,7 +1293,6 @@ namespace dlib
matrix_array2d_exp (
const M& m_
) :
matrix_exp<matrix_array2d_exp>(*this),
m(m_)
{
}
......@@ -1396,7 +1382,6 @@ namespace dlib
const long& nr__,
const long& nc__
) :
matrix_exp<matrix_sub_exp>(*this),
m(m_),
r_(r__),
c_(c__),
......@@ -1473,8 +1458,7 @@ namespace dlib
matrix_range_exp (
T start_,
T end_
) :
matrix_exp<matrix_range_exp>(*this)
)
{
start = start_;
if (start_ <= end_)
......@@ -1487,8 +1471,7 @@ namespace dlib
T start_,
T inc_,
T end_
) :
matrix_exp<matrix_range_exp>(*this)
)
{
start = start_;
nc_ = std::abs(end_ - start_)/inc_ + 1;
......@@ -1503,8 +1486,7 @@ namespace dlib
T end_,
long num,
bool
) :
matrix_exp<matrix_range_exp>(*this)
)
{
start = start_;
nc_ = num;
......@@ -1590,8 +1572,7 @@ namespace dlib
T start_,
T end_,
long num
) :
matrix_exp<matrix_log_range_exp>(*this)
)
{
start = start_;
nc_ = num;
......@@ -1673,9 +1654,7 @@ namespace dlib
{}
matrix_range_static_exp (
) :
matrix_exp<matrix_range_static_exp>(*this)
{}
) {}
long operator() (
long ,
......
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