From 44c814e3340151b36343e218ceead1790661b8b5 Mon Sep 17 00:00:00 2001 From: Rostislav Vasilikhin Date: Tue, 23 Jul 2024 07:06:15 +0200 Subject: [PATCH] Merge pull request #25936 from savuor:rv/hal_dot HAL for dot product added #25936 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake --- modules/core/src/hal_replacement.hpp | 21 +++++++++++++++++++++ modules/core/src/matmul.dispatch.cpp | 11 ++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/core/src/hal_replacement.hpp b/modules/core/src/hal_replacement.hpp index f78608dbad..67f3ac7141 100644 --- a/modules/core/src/hal_replacement.hpp +++ b/modules/core/src/hal_replacement.hpp @@ -899,6 +899,27 @@ inline int hal_ni_meanStdDev(const uchar* src_data, size_t src_step, int width, #define cv_hal_meanStdDev hal_ni_meanStdDev //! @endcond +/** + * @brief calculates dot product of two vectors (represented as 2d images) + * + * @param a_data Pointer to 1st 2nd image data + * @param a_step Stride of 1st 2nd image + * @param b_data Pointer to 1st 2nd image data + * @param b_step Stride of 1st 2nd image + * @param width Width of both images + * @param height Height of both images + * @param type Data type of both images, for example CV_8U or CV_32F + * @param dot_val Pointer to resulting dot product value + * @return int + */ +inline int hal_ni_dotProduct(const uchar* a_data, size_t a_step, const uchar* b_data, size_t b_step, int width, int height, + int type, double *dot_val) +{ return CV_HAL_ERROR_NOT_IMPLEMENTED; } + +//! @cond IGNORED +#define cv_hal_dotProduct hal_ni_dotProduct +//! @endcond + /** @brief hal_flip @param src_type source and destination image type diff --git a/modules/core/src/matmul.dispatch.cpp b/modules/core/src/matmul.dispatch.cpp index 81953265d7..35b7ad54c4 100644 --- a/modules/core/src/matmul.dispatch.cpp +++ b/modules/core/src/matmul.dispatch.cpp @@ -995,9 +995,18 @@ double Mat::dot(InputArray _mat) const CV_INSTRUMENT_REGION(); Mat mat = _mat.getMat(); + CV_Assert_N( mat.type() == type(), mat.size == size); + int cn = channels(); + if (this->dims <= 2) + { + double product = 0; + CALL_HAL_RET(dotProduct, cv_hal_dotProduct, product, this->data, this->step, mat.data, mat.step, + this->cols * cn, this->rows, this->depth()); + } + DotProdFunc func = getDotProdFunc(depth()); - CV_Assert_N( mat.type() == type(), mat.size == size, func != 0 ); + CV_Assert(func != 0 ); if( isContinuous() && mat.isContinuous() ) {