Skip to content

Add support for std::array<T, N>#8535

Merged
alalek merged 3 commits intoopencv:masterfrom
arnaudbrejeon:std_array
Apr 19, 2017
Merged

Add support for std::array<T, N>#8535
alalek merged 3 commits intoopencv:masterfrom
arnaudbrejeon:std_array

Conversation

@arnaudbrejeon
Copy link
Copy Markdown
Contributor

@arnaudbrejeon arnaudbrejeon commented Apr 7, 2017

resolves #5086

Partially adds support for std::array from request "Add InputArray and OutputArray overloads for std::array #5086"

  • CV_CXX_STD_ARRAY is defined to know if std::array is supported by the compiler
  • New constructors for InputArray, OutputArray, InputOutputArray, and Mat that take std::array and std::array<Mat> as input.
  • Add tests (similar to std::vector tests)

// For some cases (with vector) dst.size != src.size, so force to column-based form
// It prevents memory corruption in case of column-based src
if (_dst.isVector())
if (_dst.isVector() || _dst.isArray())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should avoid introduction of new "isArray()" method and merge it with isVector().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I will update the commits to take this into account

@arnaudbrejeon
Copy link
Copy Markdown
Contributor Author

arnaudbrejeon commented Apr 11, 2017

I've removed isArray and added support for std::array<cv::Mat>

#ifdef CV_CXX_STD_ARRAY
//! builds matrix from std::array with or without copying the data
template<typename _Tp, std::size_t _N> explicit UMat(const std::array<_Tp, _N>& vec, bool copyData=false);
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this overload.
UMat usage is highly integrated with OpenCL, which usually requires large enough amount of data (there is significant overhead for small arrays). In general, we should not allow users/developers to write a slow code.

@alalek
Copy link
Copy Markdown
Member

alalek commented Apr 19, 2017

Well done! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add InputArray and OutputArray overloads for std::array

2 participants