Slightly simplified and generalized the matrix expression code related to

aliasing detection.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403270
This commit is contained in:
Davis King 2009-11-14 02:40:09 +00:00
parent 4753899226
commit 4b1f025fec
3 changed files with 128 additions and 127 deletions

View File

@ -146,14 +146,14 @@ namespace dlib
long nc (
) const { return get_nc_helper<exp_type,NC>::get(ref()); }
template <typename U, long iNR, long iNC, typename mm, typename l >
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,mm,l>& item
const matrix_exp<U>& item
) const { return ref().aliases(item); }
template <typename U, long iNR, long iNC , typename mm, typename l>
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,mm,l>& item
const matrix_exp<U>& item
) const { return ref().destructively_aliases(item); }
inline const exp_type& ref (
@ -359,14 +359,14 @@ namespace dlib
long nc (
) const { return rhs.nc(); }
template <typename U, long iNR, long iNC, typename mm, typename l >
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,mm,l>& item
const matrix_exp<U>& item
) const { return lhs.aliases(item) || rhs.aliases(item); }
template <typename U, long iNR, long iNC , typename mm, typename l>
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,mm,l>& item
const matrix_exp<U>& item
) const { return aliases(item); }
LHS_ref_type lhs;
@ -508,14 +508,14 @@ namespace dlib
inline const type operator() ( long i ) const
{ return matrix_exp<matrix_add_exp>::operator()(i); }
template <typename U, long iNR, long iNC , typename mm, typename l>
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,mm,l>& item
const matrix_exp<U>& item
) const { return lhs.aliases(item) || rhs.aliases(item); }
template <typename U, long iNR, long iNC, typename mm, typename l >
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,mm,l>& item
const matrix_exp<U>& item
) const { return lhs.destructively_aliases(item) || rhs.destructively_aliases(item); }
long nr (
@ -614,14 +614,14 @@ namespace dlib
inline const type operator() ( long i ) const
{ return matrix_exp<matrix_subtract_exp>::operator()(i); }
template <typename U, long iNR, long iNC, typename mm, typename l >
template <typename U>
bool aliases (
const matrix<U,iNR,iNC, mm,l>& item
const matrix_exp<U>& item
) const { return lhs.aliases(item) || rhs.aliases(item); }
template <typename U, long iNR, long iNC , typename mm, typename l>
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,mm,l>& item
const matrix_exp<U>& item
) const { return lhs.destructively_aliases(item) || rhs.destructively_aliases(item); }
long nr (
@ -701,14 +701,14 @@ namespace dlib
inline const type operator() ( long i ) const
{ return matrix_exp<matrix_div_scal_exp>::operator()(i); }
template <typename U, long iNR, long iNC, typename mm , typename l>
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,mm,l>& item
const matrix_exp<U>& item
) const { return m.aliases(item); }
template <typename U, long iNR, long iNC, typename mm, typename l >
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,mm,l>& item
const matrix_exp<U>& item
) const { return m.destructively_aliases(item); }
long nr (
@ -791,14 +791,14 @@ namespace dlib
inline const type operator() ( long i ) const
{ return matrix_exp<matrix_mul_scal_exp>::operator()(i); }
template <typename U, long iNR, long iNC , typename mm, typename l>
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,mm,l>& item
const matrix_exp<U>& item
) const { return m.aliases(item); }
template <typename U, long iNR, long iNC, typename mm, typename l >
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,mm,l>& item
const matrix_exp<U>& item
) const { return m.destructively_aliases(item); }
long nr (
@ -1488,20 +1488,20 @@ namespace dlib
data.swap(item.data);
}
template <typename U, long iNR, long iNC, typename mm, typename l >
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,mm,l>&
) const { return false; }
template <typename U, long iNR, long iNC, typename mm, typename l>
bool destructively_aliases (
const matrix<U,iNR,iNC,mm,l>&
const matrix_exp<U>& item
) const { return false; }
bool aliases (
const matrix& item
const matrix_exp<matrix<T,num_rows,num_cols, mem_manager,layout> >& item
) const { return (this == &item); }
template <typename U>
bool destructively_aliases (
const matrix_exp<U>&
) const { return false; }
private:
struct literal_assign_helper
{
@ -1752,14 +1752,14 @@ namespace dlib
const type operator() ( long i ) const
{ return ref_(i); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return ref_.aliases(item); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return ref_.destructively_aliases(item); }
long nr (

View File

@ -123,22 +123,23 @@ namespace dlib
- returns nr()*nc()
!*/
template <typename U, long iNR, long iNC , typename mm, typename l>
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,mm,l>& item
const matrix_exp<U>& item
) const;
/*!
ensures
- if (this matrix expression contains/aliases the given matrix or contains
any subexpressions that contain/alias the given matrix) then
- if (A change to the state of item could cause a change to the state of *this
matrix_exp object. ) then
- returns true
- This happens when this matrix_exp contains item in some way.
- else
- returns false
!*/
template <typename U, long iNR, long iNC, typename mm, typename l>
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,mm,l>& item
const matrix_exp<U>& item
) const;
/*!
ensures
@ -148,7 +149,7 @@ namespace dlib
(i.e. if this expression has different dimensions than item then
we have destructive aliasing)
- returns true if the following expression would evaluate incorrectly:
- returns true if the following assignment would evaluate incorrectly:
for (long r = 0; r < nr(); ++r)
for (long c = 0; c < nc(); ++c)
item(r,c) = (*this)(r,c)

View File

@ -102,34 +102,34 @@ namespace dlib
struct has_destructive_aliasing
{
template <typename M, typename U, long iNR, long iNC, typename MM, typename L >
template <typename M, typename U>
static bool destructively_aliases (
const M& m,
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) { return m.aliases(item); }
template <typename M1, typename M2, typename U, long iNR, long iNC, typename MM, typename L >
template <typename M1, typename M2, typename U>
static bool destructively_aliases (
const M1& m1,
const M2& m2,
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) { return m1.aliases(item) || m2.aliases(item) ; }
template <typename M1, typename M2, typename M3, typename U, long iNR, long iNC, typename MM, typename L >
template <typename M1, typename M2, typename M3, typename U>
static bool destructively_aliases (
const M1& m1,
const M2& m2,
const M3& m3,
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) { return m1.aliases(item) || m2.aliases(item) || m3.aliases(item); }
template <typename M1, typename M2, typename M3, typename M4, typename U, long iNR, long iNC, typename MM, typename L >
template <typename M1, typename M2, typename M3, typename M4, typename U>
static bool destructively_aliases (
const M1& m1,
const M2& m2,
const M3& m3,
const M4& m4,
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) { return m1.aliases(item) || m2.aliases(item) || m3.aliases(item) || m4.aliases(item); }
};
@ -137,34 +137,34 @@ namespace dlib
struct has_nondestructive_aliasing
{
template <typename M, typename U, long iNR, long iNC, typename MM, typename L >
template <typename M, typename U>
static bool destructively_aliases (
const M& m,
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) { return m.destructively_aliases(item); }
template <typename M1, typename M2, typename U, long iNR, long iNC, typename MM, typename L >
template <typename M1, typename M2, typename U>
static bool destructively_aliases (
const M1& m1,
const M2& m2,
const matrix<U,iNR,iNC, MM, L>& item
const matrix_exp<U>& item
) { return m1.destructively_aliases(item) || m2.destructively_aliases(item) ; }
template <typename M1, typename M2, typename M3, typename U, long iNR, long iNC, typename MM, typename L >
template <typename M1, typename M2, typename M3, typename U>
static bool destructively_aliases (
const M1& m1,
const M2& m2,
const M3& m3,
const matrix<U,iNR,iNC, MM, L>& item
const matrix_exp<U>& item
) { return m1.destructively_aliases(item) || m2.destructively_aliases(item) || m3.destructively_aliases(item) ; }
template <typename M1, typename M2, typename M3, typename M4, typename U, long iNR, long iNC, typename MM, typename L >
template <typename M1, typename M2, typename M3, typename M4, typename U>
static bool destructively_aliases (
const M1& m1,
const M2& m2,
const M3& m3,
const M4& m4,
const matrix<U,iNR,iNC, MM, L>& item
const matrix<U>& item
) { return m1.destructively_aliases(item) ||
m2.destructively_aliases(item) ||
m3.destructively_aliases(item) ||
@ -261,14 +261,14 @@ namespace dlib
const typename OP::type operator() ( long i ) const
{ return matrix_exp<matrix_unary_exp>::operator()(i); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return m.aliases(item); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return OP::destructively_aliases(m,item); }
long nr (
@ -343,14 +343,14 @@ namespace dlib
const typename OP::type operator() ( long i ) const
{ return matrix_exp<matrix_scalar_binary_exp>::operator()(i); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return m.aliases(item); }
template <typename U, long iNR, long iNC , typename MM, typename L>
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return OP::destructively_aliases(m,item); }
long nr (
@ -428,14 +428,14 @@ namespace dlib
const typename OP::type operator() ( long i ) const
{ return matrix_exp<matrix_scalar_ternary_exp>::operator()(i); }
template <typename U, long iNR, long iNC, typename MM, typename L>
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return m.aliases(item); }
template <typename U, long iNR, long iNC , typename MM, typename L>
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return OP::destructively_aliases(m,item); }
long nr (
@ -510,14 +510,14 @@ namespace dlib
const typename OP::type operator() ( long i ) const
{ return matrix_exp<matrix_binary_exp>::operator()(i); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return m1.aliases(item) || m2.aliases(item); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return OP::destructively_aliases(m1,m2,item); }
long nr (
@ -595,14 +595,14 @@ namespace dlib
const typename OP::type operator() ( long i ) const
{ return matrix_exp<matrix_ternary_exp>::operator()(i); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return m1.aliases(item) || m2.aliases(item) || m3.aliases(item); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return OP::destructively_aliases(m1,m2,m3,item); }
long nr (
@ -684,14 +684,14 @@ namespace dlib
const typename OP::type operator() ( long i ) const
{ return matrix_exp<matrix_fourary_exp>::operator()(i); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return m1.aliases(item) || m2.aliases(item) || m3.aliases(item) || m4.aliases(item); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return OP::destructively_aliases(m1,m2,m3,m4,item); }
long nr (
@ -763,14 +763,14 @@ namespace dlib
const typename OP::type operator() ( long i ) const
{ return matrix_exp<dynamic_matrix_scalar_unary_exp>::operator()(i); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>&
const matrix_exp<U>&
) const { return false; }
template <typename U, long iNR, long iNC , typename MM, typename L>
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>&
const matrix_exp<U>&
) const { return false; }
long nr (
@ -837,14 +837,14 @@ namespace dlib
const typename OP::type operator() ( long i ) const
{ return matrix_exp<matrix_scalar_unary_exp>::operator()(i); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>&
const matrix_exp<U>&
) const { return false; }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>&
const matrix_exp<U>&
) const { return false; }
long nr (
@ -899,14 +899,14 @@ namespace dlib
const typename OP::type operator() ( long i ) const
{ return matrix_exp<matrix_zeroary_exp>::operator()(i); }
template <typename U, long iNR, long iNC , typename MM, typename L>
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return false; }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return false; }
long nr (
@ -981,14 +981,14 @@ namespace dlib
const typename M::type operator() ( long i ) const
{ return matrix_exp<matrix_sub_range_exp>::operator()(i); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return m.aliases(item) || rows.aliases(item) || cols.aliases(item); }
template <typename U, long iNR, long iNC , typename MM, typename L>
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return m.aliases(item) || rows.aliases(item) || cols.aliases(item); }
long nr (
@ -1059,14 +1059,14 @@ namespace dlib
const typename M::value_type& operator() ( long i ) const
{ return m[i]; }
template <typename U, long iNR, long iNC, typename MM, typename L>
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>&
const matrix_exp<U>&
) const { return false; }
template <typename U, long iNR, long iNC , typename MM, typename L>
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>&
const matrix_exp<U>&
) const { return false; }
long nr (
@ -1134,14 +1134,14 @@ namespace dlib
const typename M::type& operator() ( long i ) const
{ return m[i]; }
template <typename U, long iNR, long iNC, typename MM, typename L>
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return false; }
template <typename U, long iNR, long iNC , typename MM, typename L>
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return false; }
long nr (
@ -1209,14 +1209,14 @@ namespace dlib
const typename M::type operator() ( long i ) const
{ return matrix_exp<matrix_array2d_exp>::operator()(i); }
template <typename U, long iNR, long iNC, typename MM, typename L>
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>&
const matrix_exp<U>&
) const { return false; }
template <typename U, long iNR, long iNC , typename MM, typename L>
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>&
const matrix_exp<U>&
) const { return false; }
long nr (
@ -1291,14 +1291,14 @@ namespace dlib
const typename M::type operator() ( long i ) const
{ return matrix_exp<matrix_sub_exp>::operator()(i); }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return m.aliases(item); }
template <typename U, long iNR, long iNC , typename MM, typename L>
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return m.aliases(item); }
long nr (
@ -1396,14 +1396,14 @@ namespace dlib
long c
) const { return start + c*inc; }
template <typename U, long iNR, long iNC , typename MM, typename L>
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>&
const matrix_exp<U>&
) const { return false; }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>&
const matrix_exp<U>&
) const { return false; }
long nr (
@ -1474,14 +1474,14 @@ namespace dlib
long c
) const { return std::pow(10,start + c*inc); }
template <typename U, long iNR, long iNC , typename MM, typename L>
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>&
const matrix_exp<U>&
) const { return false; }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>&
const matrix_exp<U>&
) const { return false; }
long nr (
@ -1537,14 +1537,14 @@ namespace dlib
long c
) const { return start + c*inc; }
template <typename U, long iNR, long iNC , typename MM, typename L>
template <typename U>
bool aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return false; }
template <typename U, long iNR, long iNC, typename MM, typename L >
template <typename U>
bool destructively_aliases (
const matrix<U,iNR,iNC,MM,L>& item
const matrix_exp<U>& item
) const { return false; }
long nr (