Commit fef18843 authored by Davis King's avatar Davis King

Fixed a bug which caused you to get a compiler error if you tried

to call dot() on two 1x1 matrices which were statically dimensioned.
parent 5a4a62f7
......@@ -596,7 +596,7 @@ namespace dlib
}
template < typename EXP1, typename EXP2 >
typename enable_if_c<EXP1::NR == 1 && EXP2::NR == 1, typename EXP1::type>::type
typename enable_if_c<EXP1::NR == 1 && EXP2::NR == 1 && EXP1::NC != 1 && EXP2::NC != 1, typename EXP1::type>::type
dot ( const matrix_exp<EXP1>& m1, const matrix_exp<EXP2>& m2)
{
DLIB_ASSERT(m1.size() == m2.size(),
......@@ -610,7 +610,7 @@ namespace dlib
}
template < typename EXP1, typename EXP2 >
typename enable_if_c<EXP1::NR == 1 && EXP2::NC == 1, typename EXP1::type>::type
typename enable_if_c<EXP1::NR == 1 && EXP2::NC == 1 && EXP1::NC != 1 && EXP2::NR != 1, typename EXP1::type>::type
dot ( const matrix_exp<EXP1>& m1, const matrix_exp<EXP2>& m2)
{
DLIB_ASSERT(m1.size() == m2.size(),
......@@ -624,7 +624,7 @@ namespace dlib
}
template < typename EXP1, typename EXP2 >
typename enable_if_c<EXP1::NC == 1 && EXP2::NR == 1, typename EXP1::type>::type
typename enable_if_c<EXP1::NC == 1 && EXP2::NR == 1 && EXP1::NR != 1 && EXP2::NC != 1, typename EXP1::type>::type
dot ( const matrix_exp<EXP1>& m1, const matrix_exp<EXP2>& m2)
{
DLIB_ASSERT(m1.size() == m2.size(),
......@@ -638,7 +638,7 @@ namespace dlib
}
template < typename EXP1, typename EXP2 >
typename enable_if_c<EXP1::NC == 1 && EXP2::NC == 1, typename EXP1::type>::type
typename enable_if_c<EXP1::NC == 1 && EXP2::NC == 1 && EXP1::NR != 1 && EXP2::NR != 1, typename EXP1::type>::type
dot ( const matrix_exp<EXP1>& m1, const matrix_exp<EXP2>& m2)
{
DLIB_ASSERT(m1.size() == m2.size(),
......@@ -651,6 +651,20 @@ namespace dlib
return trans(m1)*m2;
}
template < typename EXP1, typename EXP2 >
typename enable_if_c<(EXP1::NC == 1 && EXP1::NR == 1) || (EXP2::NC == 1 && EXP2::NR == 1), typename EXP1::type>::type
dot ( const matrix_exp<EXP1>& m1, const matrix_exp<EXP2>& m2)
{
DLIB_ASSERT(m1.size() == m2.size(),
"\t type dot(const matrix_exp& m1, const matrix_exp& m2)"
<< "\n\t You can only compute the dot product between vectors of equal length"
<< "\n\t m1.size(): " << m1.size()
<< "\n\t m2.size(): " << m2.size()
);
return m1(0)*m2(0);
}
// ----------------------------------------------------------------------------------------
template <typename M, long R, long C>
......
......@@ -909,6 +909,29 @@ namespace
DLIB_TEST(m == m2);
}
{
matrix<double,1,1> a, b;
a = 2;
b = 3;
DLIB_TEST(dot(a,b) == 6);
}
{
matrix<double,1,1> a;
matrix<double,0,1> b(1);
a = 2;
b = 3;
DLIB_TEST(dot(a,b) == 6);
DLIB_TEST(dot(b,a) == 6);
}
{
matrix<double,1,1> a;
matrix<double,1,0> b(1);
a = 2;
b = 3;
DLIB_TEST(dot(a,b) == 6);
DLIB_TEST(dot(b,a) == 6);
}
}
class matrix_tester : public tester
......
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