//! <0 - a diagonal from the lower half)
UMat diag(int d=0) const;
//! constructs a square diagonal matrix which main diagonal is vector "d"
- static UMat diag(const UMat& d);
+ static UMat diag(const UMat& d, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
+ static UMat diag(const UMat& d) { return diag(d, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
//! returns deep copy of the matrix, i.e. the data is copied
UMat clone() const CV_NODISCARD;
double dot(InputArray m) const;
//! Matlab-style matrix initialization
- static UMat zeros(int rows, int cols, int type);
- static UMat zeros(Size size, int type);
- static UMat zeros(int ndims, const int* sz, int type);
- static UMat ones(int rows, int cols, int type);
- static UMat ones(Size size, int type);
- static UMat ones(int ndims, const int* sz, int type);
- static UMat eye(int rows, int cols, int type);
- static UMat eye(Size size, int type);
+ static UMat zeros(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
+ static UMat zeros(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
+ static UMat zeros(int ndims, const int* sz, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
+ static UMat zeros(int rows, int cols, int type) { return zeros(rows, cols, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
+ static UMat zeros(Size size, int type) { return zeros(size, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
+ static UMat zeros(int ndims, const int* sz, int type) { return zeros(ndims, sz, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
+ static UMat ones(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
+ static UMat ones(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
+ static UMat ones(int ndims, const int* sz, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
+ static UMat ones(int rows, int cols, int type) { return ones(rows, cols, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
+ static UMat ones(Size size, int type) { return ones(size, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
+ static UMat ones(int ndims, const int* sz, int type) { return ones(ndims, sz, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
+ static UMat eye(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
+ static UMat eye(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
+ static UMat eye(int rows, int cols, int type) { return eye(rows, cols, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
+ static UMat eye(Size size, int type) { return eye(size, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
//! allocates new matrix data unless the matrix already has specified size and type.
// previous data is unreferenced if needed.
namespace cv {
-UMat UMat::eye(int rows, int cols, int type)
+UMat UMat::eye(int rows, int cols, int type, UMatUsageFlags usageFlags)
{
- return UMat::eye(Size(cols, rows), type);
+ return UMat::eye(Size(cols, rows), type, usageFlags);
}
-UMat UMat::eye(Size size, int type)
+UMat UMat::eye(Size size, int type, UMatUsageFlags usageFlags)
{
- UMat m(size, type);
+ UMat m(size, type, usageFlags);
setIdentity(m);
return m;
}
return hdr;
}
-UMat UMat::diag(const UMat& d)
+UMat UMat::diag(const UMat& d, UMatUsageFlags usageFlags)
{
CV_Assert( d.cols == 1 || d.rows == 1 );
int len = d.rows + d.cols - 1;
- UMat m(len, len, d.type(), Scalar(0));
+ UMat m(len, len, d.type(), Scalar(0), usageFlags);
UMat md = m.diag();
if( d.cols == 1 )
d.copyTo(md);
return m;
}
-UMat UMat::zeros(int rows, int cols, int type)
+UMat UMat::zeros(int rows, int cols, int type, UMatUsageFlags usageFlags)
{
- return UMat(rows, cols, type, Scalar::all(0));
+ return UMat(rows, cols, type, Scalar::all(0), usageFlags);
}
-UMat UMat::zeros(Size size, int type)
+UMat UMat::zeros(Size size, int type, UMatUsageFlags usageFlags)
{
- return UMat(size, type, Scalar::all(0));
+ return UMat(size, type, Scalar::all(0), usageFlags);
}
-UMat UMat::zeros(int ndims, const int* sz, int type)
+UMat UMat::zeros(int ndims, const int* sz, int type, UMatUsageFlags usageFlags)
{
- return UMat(ndims, sz, type, Scalar::all(0));
+ return UMat(ndims, sz, type, Scalar::all(0), usageFlags);
}
-UMat UMat::ones(int rows, int cols, int type)
+UMat UMat::ones(int rows, int cols, int type, UMatUsageFlags usageFlags)
{
- return UMat::ones(Size(cols, rows), type);
+ return UMat(rows, cols, type, Scalar(1), usageFlags);
}
-UMat UMat::ones(Size size, int type)
+UMat UMat::ones(Size size, int type, UMatUsageFlags usageFlags)
{
- return UMat(size, type, Scalar(1));
+ return UMat(size, type, Scalar(1), usageFlags);
}
-UMat UMat::ones(int ndims, const int* sz, int type)
+UMat UMat::ones(int ndims, const int* sz, int type, UMatUsageFlags usageFlags)
{
- return UMat(ndims, sz, type, Scalar(1));
+ return UMat(ndims, sz, type, Scalar(1), usageFlags);
}
}
}
}
+//////////////////////////////// with usageFlags /////////////////////////////////////////////////
+
+OCL_TEST_P(UMatExpr, WithUsageFlags)
+{
+ for (int j = 0; j < test_loop_times; j++)
+ {
+ generateTestData();
+
+ UMat u0 = UMat::zeros(size, type, cv::USAGE_ALLOCATE_HOST_MEMORY);
+ UMat u1 = UMat::ones(size, type, cv::USAGE_ALLOCATE_HOST_MEMORY);
+ UMat u8 = UMat::eye(size, type, cv::USAGE_ALLOCATE_HOST_MEMORY);
+
+ EXPECT_EQ(cv::USAGE_ALLOCATE_HOST_MEMORY, u0.usageFlags);
+ EXPECT_EQ(cv::USAGE_ALLOCATE_HOST_MEMORY, u1.usageFlags);
+ EXPECT_EQ(cv::USAGE_ALLOCATE_HOST_MEMORY, u8.usageFlags);
+ }
+}
+
//////////////////////////////// Instantiation /////////////////////////////////////////////////
OCL_INSTANTIATE_TEST_CASE_P(MatrixOperation, UMatExpr, Combine(OCL_ALL_DEPTHS_16F, OCL_ALL_CHANNELS));