Commit dd83589a authored by Davis King's avatar Davis King

- Moved the matrix_assign() totally into the matrix_assign.h file

  - Updated matrix regression tests.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402720
parent c4512e68
...@@ -896,23 +896,8 @@ namespace dlib ...@@ -896,23 +896,8 @@ namespace dlib
void matrix_assign ( void matrix_assign (
matrix_dest_type& dest, matrix_dest_type& dest,
const matrix_exp<src_exp>& src const matrix_exp<src_exp>& src
) );
/*! // See matrix_assign.h for the actual implementation of this function.
requires
- src.destructively_aliases(dest) == false
ensures
- #dest == src
- the part of dest outside the above sub matrix remains unchanged
!*/
{
for (long r = 0; r < src.nr(); ++r)
{
for (long c = 0; c < src.nc(); ++c)
{
dest(r,c) = src(r,c);
}
}
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -10,9 +10,33 @@ ...@@ -10,9 +10,33 @@
namespace dlib namespace dlib
{ {
/*
This file is where all the implementations of matrix_assign() live. The point of the
matrix_assign() functions is to contain all the various optimizations that help the
matrix assign a matrix_exp to an actual matrix object quickly.
*/
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 namespace ma
{ {
// This namespace defines whatever helpers we need in the rest of this file.
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
...@@ -45,6 +69,26 @@ namespace dlib ...@@ -45,6 +69,26 @@ namespace dlib
} }
// ----------------------------------------------------------------------------------------
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);
}
}
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
......
...@@ -921,25 +921,28 @@ namespace ...@@ -921,25 +921,28 @@ namespace
{ {
matrix<double> m(2,3); matrix<double> m(2,3);
m << 1,2,3, m = 1,2,3,
5,6,7; 5,6,7;
DLIB_CASSERT(m(0,0) == 1 && m(0,1) == 2 && m(0,2) == 3 && DLIB_CASSERT(m(0,0) == 1 && m(0,1) == 2 && m(0,2) == 3 &&
m(1,0) == 5 && m(1,1) == 6 && m(1,2) == 7,""); m(1,0) == 5 && m(1,1) == 6 && m(1,2) == 7,"");
m = 4;
DLIB_CASSERT((m == uniform_matrix<double,2,3>(4)),"");
matrix<double,2,3> m2; matrix<double,2,3> m2;
m2 << 1,2,3, m2 = 1,2,3,
5,6,7; 5,6,7;
DLIB_CASSERT(m2(0,0) == 1 && m2(0,1) == 2 && m2(0,2) == 3 && DLIB_CASSERT(m2(0,0) == 1 && m2(0,1) == 2 && m2(0,2) == 3 &&
m2(1,0) == 5 && m2(1,1) == 6 && m2(1,2) == 7,""); m2(1,0) == 5 && m2(1,1) == 6 && m2(1,2) == 7,"");
matrix<double,2,1> m3; matrix<double,2,1> m3;
m3 << 1, m3 = 1,
5; 5;
DLIB_CASSERT(m3(0) == 1 && m3(1) == 5 ,""); DLIB_CASSERT(m3(0) == 1 && m3(1) == 5 ,"");
matrix<double,1,2> m4; matrix<double,1,2> m4;
m4 << 1, 5; m4 = 1, 5;
DLIB_CASSERT(m3(0) == 1 && m3(1) == 5 ,""); DLIB_CASSERT(m3(0) == 1 && m3(1) == 5 ,"");
} }
......
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