Commit 53ea098d authored by Davis King's avatar Davis King

Cleaned up the matrix_assign() stuff a little more. Also added some stuff

particular to gcc to control how things get inlined.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402721
parent dd83589a
......@@ -13,6 +13,7 @@
#include "../memory_manager.h"
#include "../is_kind.h"
#include "matrix_data_layout.h"
#include "matrix_assign_fwd.h"
#ifdef _MSC_VER
// Disable the following warnings for Visual Studio
......@@ -887,18 +888,6 @@ namespace dlib
const matrix_exp<EXP2>& m2
) { return !(m1 == m2); }
// ----------------------------------------------------------------------------------------
template <
typename matrix_dest_type,
typename src_exp
>
void matrix_assign (
matrix_dest_type& dest,
const matrix_exp<src_exp>& src
);
// See matrix_assign.h for the actual implementation of this function.
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
......
......@@ -7,6 +7,7 @@
#include "matrix.h"
#include "matrix_utilities.h"
#include "../enable_if.h"
#include "matrix_assign_fwd.h"
namespace dlib
{
......@@ -18,22 +19,6 @@ namespace dlib
*/
template <
typename matrix_dest_type,
typename src_exp
>
void matrix_assign (
matrix_dest_type& dest,
const matrix_exp<src_exp>& src
);
/*!
requires
- src.destructively_aliases(dest) == false
ensures
- #dest == src
- the part of dest outside the above sub matrix remains unchanged
!*/
namespace ma
{
// This namespace defines whatever helpers we need in the rest of this file.
......@@ -61,32 +46,6 @@ namespace dlib
template < typename EXP >
struct matrix_is_vector<EXP, typename enable_if_c<EXP::NR==1 || EXP::NC==1>::type > { static const bool value = true; };
template < typename EXP, typename enable = void >
struct is_small_matrix { static const bool value = false; };
template < typename EXP >
struct is_small_matrix<EXP, typename enable_if_c<EXP::NR>=1 && EXP::NC>=1 &&
EXP::NR<=100 && EXP::NC<=100>::type > { static const bool value = true; };
}
// ----------------------------------------------------------------------------------------
template <
typename matrix_dest_type,
typename src_exp
>
void matrix_assign (
matrix_dest_type& dest,
const matrix_exp<src_exp>& src
)
{
for (long r = 0; r < src.nr(); ++r)
{
for (long c = 0; c < src.nc(); ++c)
{
dest(r,c) = src(r,c);
}
}
}
// ----------------------------------------------------------------------------------------
......@@ -97,8 +56,7 @@ namespace dlib
typename EXP2,
unsigned long count
>
inline typename disable_if_c<ma::matrix_is_vector<EXP1>::value || ma::matrix_is_vector<EXP2>::value ||
ma::is_small_matrix<EXP1>::value || ma::is_small_matrix<EXP2>::value >::type matrix_assign (
inline typename disable_if_c<ma::matrix_is_vector<EXP1>::value || ma::matrix_is_vector<EXP2>::value>::type matrix_assign_big (
matrix_dest_type& dest,
const matrix_exp<matrix_multiply_exp<EXP1,EXP2,count> >& src
)
......
// Copyright (C) 2008 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_MATRIx_ASSIGn_FWD_
#define DLIB_MATRIx_ASSIGn_FWD_
#include "../enable_if.h"
namespace dlib
{
// ----------------------------------------------------------------------------------------
namespace ma
{
template < typename EXP, typename enable = void >
struct is_small_matrix { static const bool value = false; };
template < typename EXP >
struct is_small_matrix<EXP, typename enable_if_c<EXP::NR>=1 && EXP::NC>=1 &&
EXP::NR<=100 && EXP::NC<=100>::type > { static const bool value = true; };
}
// ----------------------------------------------------------------------------------------
template <
typename EXP
>
class matrix_exp;
// ----------------------------------------------------------------------------------------
// In newer versions of GCC it is necessary to explicitly tell it to not try to
// inline the matrix_assign() function when working with matrix objects that
// don't have dimensions that are known at compile time. Doing this makes the
// resulting binaries a lot faster when -O3 is used. This whole deal with
// different versions of matrix_assign() is just to support getting the right
// inline behavior out of GCC.
#ifdef __GNUC__
#define DLIB_DONT_INLINE __attribute__((noinline))
#else
#define DLIB_DONT_INLINE
#endif
template <
typename matrix_dest_type,
typename src_exp
>
DLIB_DONT_INLINE void matrix_assign_big (
matrix_dest_type& dest,
const matrix_exp<src_exp>& src
)
{
for (long r = 0; r < src.nr(); ++r)
{
for (long c = 0; c < src.nc(); ++c)
{
dest(r,c) = src(r,c);
}
}
}
template <
typename matrix_dest_type,
typename src_exp
>
inline void matrix_assign_small (
matrix_dest_type& dest,
const matrix_exp<src_exp>& src
)
{
for (long r = 0; r < src.nr(); ++r)
{
for (long c = 0; c < src.nc(); ++c)
{
dest(r,c) = src(r,c);
}
}
}
// ----------------------------------------------------------------------------------------
template <
typename matrix_dest_type,
typename src_exp
>
inline typename disable_if<ma::is_small_matrix<src_exp> >::type matrix_assign (
matrix_dest_type& dest,
const matrix_exp<src_exp>& src
)
/*!
requires
- src.destructively_aliases(dest) == false
ensures
- #dest == src
- the part of dest outside the above sub matrix remains unchanged
!*/
{
matrix_assign_big(dest,src);
}
// ----------------------------------------------------------------------------------------
template <
typename matrix_dest_type,
typename src_exp
>
inline typename enable_if<ma::is_small_matrix<src_exp> >::type matrix_assign (
matrix_dest_type& dest,
const matrix_exp<src_exp>& src
)
/*!
requires
- src.destructively_aliases(dest) == false
ensures
- #dest == src
- the part of dest outside the above sub matrix remains unchanged
!*/
{
matrix_assign_small(dest,src);
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_MATRIx_ASSIGn_FWD_
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