Unverified Commit 4d0f1354 authored by Alexander Alekhin's avatar Alexander Alekhin Committed by GitHub

Merge pull request #16700 from alalek:fix_core_matexpr_size_gemm

core: fix MatExpr::size() for gemm()

* core(test): MatExpr::size() test for gemm()

* core: fix MatExpr::size() for gemm()
parent a5ca5f6d
...@@ -117,8 +117,17 @@ public: ...@@ -117,8 +117,17 @@ public:
void transpose(const MatExpr& expr, MatExpr& res) const CV_OVERRIDE; void transpose(const MatExpr& expr, MatExpr& res) const CV_OVERRIDE;
Size size(const MatExpr& expr) const CV_OVERRIDE
{
return Size(
(expr.flags & GEMM_2_T) ? expr.b.rows : expr.b.cols,
(expr.flags & GEMM_1_T) ? expr.a.cols : expr.a.rows
);
}
static void makeExpr(MatExpr& res, int flags, const Mat& a, const Mat& b, static void makeExpr(MatExpr& res, int flags, const Mat& a, const Mat& b,
double alpha=1, const Mat& c=Mat(), double beta=1); double alpha=1, const Mat& c=Mat(), double beta=1);
}; };
static MatOp_GEMM g_MatOp_GEMM; static MatOp_GEMM g_MatOp_GEMM;
...@@ -199,7 +208,7 @@ static inline bool isReciprocal(const MatExpr& e) { return isBin(e,'/') && (!e.b ...@@ -199,7 +208,7 @@ static inline bool isReciprocal(const MatExpr& e) { return isBin(e,'/') && (!e.b
static inline bool isT(const MatExpr& e) { return e.op == &g_MatOp_T; } static inline bool isT(const MatExpr& e) { return e.op == &g_MatOp_T; }
static inline bool isInv(const MatExpr& e) { return e.op == &g_MatOp_Invert; } static inline bool isInv(const MatExpr& e) { return e.op == &g_MatOp_Invert; }
static inline bool isSolve(const MatExpr& e) { return e.op == &g_MatOp_Solve; } static inline bool isSolve(const MatExpr& e) { return e.op == &g_MatOp_Solve; }
static inline bool isGEMM(const MatExpr& e) { return e.op == &g_MatOp_GEMM; } //static inline bool isGEMM(const MatExpr& e) { return e.op == &g_MatOp_GEMM; }
static inline bool isMatProd(const MatExpr& e) { return e.op == &g_MatOp_GEMM && (!e.c.data || e.beta == 0); } static inline bool isMatProd(const MatExpr& e) { return e.op == &g_MatOp_GEMM && (!e.c.data || e.beta == 0); }
static inline bool isInitializer(const MatExpr& e) { return e.op == getGlobalMatOpInitializer(); } static inline bool isInitializer(const MatExpr& e) { return e.op == getGlobalMatOpInitializer(); }
...@@ -1240,8 +1249,6 @@ Size MatExpr::size() const ...@@ -1240,8 +1249,6 @@ Size MatExpr::size() const
{ {
if( isT(*this) || isInv(*this) ) if( isT(*this) || isInv(*this) )
return Size(a.rows, a.cols); return Size(a.rows, a.cols);
if( isGEMM(*this) )
return Size(b.cols, a.rows);
if( isSolve(*this) ) if( isSolve(*this) )
return Size(b.cols, a.cols); return Size(b.cols, a.cols);
if( isInitializer(*this) ) if( isInitializer(*this) )
......
...@@ -2029,6 +2029,29 @@ TEST(Core_MatExpr, issue_16655) ...@@ -2029,6 +2029,29 @@ TEST(Core_MatExpr, issue_16655)
<< "Mat: CV_8UC3 != " << typeToString(ab_mat.type()); << "Mat: CV_8UC3 != " << typeToString(ab_mat.type());
} }
TEST(Core_MatExpr, issue_16689)
{
Mat a(Size(10, 5), CV_32FC1, 5);
Mat b(Size(10, 5), CV_32FC1, 2);
Mat bt(Size(5, 10), CV_32FC1, 3);
{
MatExpr r = a * bt; // gemm
EXPECT_EQ(Mat(r).size(), r.size()) << "[10x5] x [5x10] => [5x5]";
}
{
MatExpr r = a * b.t(); // gemm
EXPECT_EQ(Mat(r).size(), r.size()) << "[10x5] x [10x5].t() => [5x5]";
}
{
MatExpr r = a.t() * b; // gemm
EXPECT_EQ(Mat(r).size(), r.size()) << "[10x5].t() x [10x5] => [10x10]";
}
{
MatExpr r = a.t() * bt.t(); // gemm
EXPECT_EQ(Mat(r).size(), r.size()) << "[10x5].t() x [5x10].t() => [10x10]";
}
}
#ifdef HAVE_EIGEN #ifdef HAVE_EIGEN
TEST(Core_Eigen, eigen2cv_check_Mat_type) TEST(Core_Eigen, eigen2cv_check_Mat_type)
{ {
......
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