Added an identity_matrix() that can take a runtime defined size.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402261
This commit is contained in:
Davis King 2008-05-24 15:10:09 +00:00
parent e042b167b4
commit add9a09a0a
2 changed files with 48 additions and 0 deletions

View File

@ -2409,6 +2409,39 @@ namespace dlib
return matrix_exp<exp>(exp());
}
// ----------------------------------------------------------------------------------------
template <
typename T
>
struct op_identity_matrix_2 : has_nondestructive_aliasing
{
const static long NR = 0;
const static long NC = 0;
typedef typename memory_manager<char>::kernel_1a mem_manager_type;
typedef T type;
static type apply (const T&, long r, long c)
{ return static_cast<type>(r == c); }
};
template <
typename T
>
const matrix_exp<dynamic_matrix_scalar_unary_exp<T,op_identity_matrix_2<T> > > identity_matrix (
const long& size
)
{
DLIB_ASSERT(size > 0,
"\tconst matrix_exp identity_matrix<T>(size)"
<< "\n\tsize must be bigger than 0"
<< "\n\tsize: " << size
);
typedef dynamic_matrix_scalar_unary_exp<T,op_identity_matrix_2<T> > exp;
// the scalar value of the dynamic_matrix_scalar_unary_exp just isn't
// used by this operator
return matrix_exp<exp>(exp(size,size,0));
}
// ----------------------------------------------------------------------------------------
template <

View File

@ -90,6 +90,21 @@ namespace dlib
- returns an nr by nc matrix with elements of type T and all set to val.
!*/
// ----------------------------------------------------------------------------------------
template <
typename T
>
const matrix_exp identity_matrix (
long N
);
/*!
requires
- N > 0
ensures
- returns an N by N identity matrix with elements of type T.
!*/
// ----------------------------------------------------------------------------------------
template <