Commit c5ff6a74 authored by Davis King's avatar Davis King

Improved speed of reshape_to_column_vector()

parent 48e02587
...@@ -3901,6 +3901,51 @@ namespace dlib ...@@ -3901,6 +3901,51 @@ namespace dlib
return matrix_op<op>(op(m.ref())); return matrix_op<op>(op(m.ref()));
} }
// ----------------------------------------------------------------------------------------
template <
typename T,
long NR_,
long NC_,
typename MM
>
struct op_mat_to_vect2
{
typedef matrix<T,NR_,NC_,MM,row_major_layout> M;
op_mat_to_vect2(const M& m_) : m(m_) {}
const M& m;
const static long cost = M::cost+2;
const static long NR = M::NC*M::NR;
const static long NC = 1;
typedef typename M::type type;
typedef typename M::const_ret_type const_ret_type;
typedef typename M::mem_manager_type mem_manager_type;
typedef typename M::layout_type layout_type;
const_ret_type apply ( long r, long ) const { return (&m(0,0))[r]; }
long nr () const { return m.size(); }
long nc () const { return 1; }
template <typename U> bool aliases ( const matrix_exp<U>& item) const { return m.aliases(item); }
template <typename U> bool destructively_aliases ( const matrix_exp<U>& item) const { return m.aliases(item); }
};
template <
typename T,
long NR,
long NC,
typename MM
>
const matrix_op<op_mat_to_vect2<T,NR,NC,MM> > reshape_to_column_vector (
const matrix<T,NR,NC,MM,row_major_layout>& m
)
{
typedef op_mat_to_vect2<T,NR,NC,MM> op;
return matrix_op<op>(op(m.ref()));
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename M1, typename M2> template <typename M1, typename M2>
......
...@@ -610,6 +610,7 @@ namespace ...@@ -610,6 +610,7 @@ namespace
m2 = 1,2,3,4,5,6; m2 = 1,2,3,4,5,6;
DLIB_TEST(reshape_to_column_vector(m) == m2); DLIB_TEST(reshape_to_column_vector(m) == m2);
DLIB_TEST(reshape_to_column_vector(m+m) == m2+m2);
} }
{ {
...@@ -622,6 +623,7 @@ namespace ...@@ -622,6 +623,7 @@ namespace
m2 = 1,2,3,4,5,6; m2 = 1,2,3,4,5,6;
DLIB_TEST(reshape_to_column_vector(m) == m2); DLIB_TEST(reshape_to_column_vector(m) == m2);
DLIB_TEST(reshape_to_column_vector(m+m) == m2+m2);
} }
} }
......
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