mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
Merge pull request #16653 from alalek:core_inputarray_matexpr
This commit is contained in:
commit
9c58a7cb1e
@ -3580,6 +3580,8 @@ public:
|
||||
Mat cross(const Mat& m) const;
|
||||
double dot(const Mat& m) const;
|
||||
|
||||
void swap(MatExpr& b);
|
||||
|
||||
const MatOp* op;
|
||||
int flags;
|
||||
|
||||
|
@ -150,9 +150,6 @@ _InputArray::_InputArray(const Mat_<_Tp>& m)
|
||||
inline _InputArray::_InputArray(const double& val)
|
||||
{ init(FIXED_TYPE + FIXED_SIZE + MATX + CV_64F + ACCESS_READ, &val, Size(1,1)); }
|
||||
|
||||
inline _InputArray::_InputArray(const MatExpr& expr)
|
||||
{ init(FIXED_TYPE + FIXED_SIZE + EXPR + ACCESS_READ, &expr); }
|
||||
|
||||
inline _InputArray::_InputArray(const cuda::GpuMat& d_mat)
|
||||
{ init(CUDA_GPU_MAT + ACCESS_READ, &d_mat); }
|
||||
|
||||
@ -4054,6 +4051,9 @@ inline void UMatData::markDeviceCopyObsolete(bool flag)
|
||||
|
||||
//! @endcond
|
||||
|
||||
static inline
|
||||
void swap(MatExpr& a, MatExpr& b) { a.swap(b); }
|
||||
|
||||
} //cv
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
@ -1821,4 +1821,37 @@ MatExpr Mat::eye(Size size, int type)
|
||||
return e;
|
||||
}
|
||||
|
||||
void MatExpr::swap(MatExpr& other)
|
||||
{
|
||||
using std::swap;
|
||||
|
||||
swap(op, other.op);
|
||||
swap(flags, other.flags);
|
||||
|
||||
swap(a, other.a);
|
||||
swap(b, other.b);
|
||||
swap(c, other.c);
|
||||
|
||||
swap(alpha, other.alpha);
|
||||
swap(beta, other.beta);
|
||||
|
||||
swap(s, other.s);
|
||||
}
|
||||
|
||||
_InputArray::_InputArray(const MatExpr& expr)
|
||||
{
|
||||
#if 1
|
||||
if (!isIdentity(expr))
|
||||
{
|
||||
Mat result = expr; // TODO improve through refcount == 1 of expr.a (inplace operation is possible - except gemm?)
|
||||
MatExpr result_expr(result);
|
||||
swap(const_cast<MatExpr&>(expr), result_expr);
|
||||
}
|
||||
CV_Assert(isIdentity(expr));
|
||||
init(FIXED_TYPE + FIXED_SIZE + MAT + ACCESS_READ, &expr.a);
|
||||
#else
|
||||
init(FIXED_TYPE + FIXED_SIZE + EXPR + ACCESS_READ, &expr);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // cv::
|
||||
|
@ -1969,6 +1969,21 @@ TEST(Core_InputArray, support_CustomType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST(Core_InputArray, fetch_MatExpr)
|
||||
{
|
||||
Mat a(Size(10, 5), CV_32FC1, 5);
|
||||
Mat b(Size(10, 5), CV_32FC1, 2);
|
||||
MatExpr expr = a * b.t(); // gemm expression
|
||||
Mat dst;
|
||||
cv::add(expr, Scalar(1), dst); // invoke gemm() here
|
||||
void* expr_data = expr.a.data;
|
||||
Mat result = expr; // should not call gemm() here again
|
||||
EXPECT_EQ(expr_data, result.data); // expr data is reused
|
||||
EXPECT_EQ(dst.size(), result.size());
|
||||
}
|
||||
|
||||
|
||||
TEST(Core_Vectors, issue_13078)
|
||||
{
|
||||
float floats_[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
|
Loading…
Reference in New Issue
Block a user