0
0
mirror of https://github.com/opencv/opencv.git synced 2026-01-18 17:21:42 +01:00

Merge pull request #27216 from CodeLinaro:xuezha_3rdPost

Add SVD into FastCV HAL
This commit is contained in:
Alexander Smorkalov
2025-04-16 17:48:36 +03:00
committed by GitHub
2 changed files with 87 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* Copyright (c) 2024-2025 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
@@ -32,6 +32,9 @@
#define cv_hal_mul16s fastcv_hal_mul16s
#undef cv_hal_mul32f
#define cv_hal_mul32f fastcv_hal_mul32f
#undef cv_hal_SVD32f
#define cv_hal_SVD32f fastcv_hal_SVD32f
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief look-up table transform of an array.
@@ -219,4 +222,32 @@ int fastcv_hal_mul32f(
int height,
double scale);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Performs singular value decomposition of \f$M\times N\f$(\f$M>N\f$) matrix \f$A = U*\Sigma*V^T\f$.
///
/// @param src Pointer to input MxN matrix A stored in column major order.
/// After finish of work src will be filled with rows of U or not modified (depends of flag CV_HAL_SVD_MODIFY_A).
/// @param src_step Number of bytes between two consequent columns of matrix A.
/// @param w Pointer to array for singular values of matrix A (i. e. first N diagonal elements of matrix \f$\Sigma\f$).
/// @param u Pointer to output MxN or MxM matrix U (size depends of flags).
/// Pointer must be valid if flag CV_HAL_SVD_MODIFY_A not used.
/// @param u_step Number of bytes between two consequent rows of matrix U.
/// @param vt Pointer to array for NxN matrix V^T.
/// @param vt_step Number of bytes between two consequent rows of matrix V^T.
/// @param m Number fo rows in matrix A.
/// @param n Number of columns in matrix A.
/// @param flags Algorithm options (combination of CV_HAL_SVD_FULL_UV, ...).
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int fastcv_hal_SVD32f(
float* src,
size_t src_step,
float* w,
float* u,
size_t u_step,
float* vt,
size_t vt_step,
int m,
int n,
int flags);
#endif

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* Copyright (c) 2024-2025 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
@@ -399,7 +399,7 @@ int fastcv_hal_mul8u(
int8_t sF;
if(FCV_CMP_EQ(scale,1.0)) { sF = 0; }
else if(scale > 1.0)
else if(scale > 1.0)
{
if(FCV_CMP_EQ(scale,2.0)) { sF = -1; }
else if(FCV_CMP_EQ(scale,4.0)) { sF = -2; }
@@ -471,7 +471,7 @@ int fastcv_hal_mul16s(
int8_t sF;
if(FCV_CMP_EQ(scale,1.0)) { sF = 0; }
else if(scale > 1.0)
else if(scale > 1.0)
{
if(FCV_CMP_EQ(scale,2.0)) { sF = -1; }
else if(FCV_CMP_EQ(scale,4.0)) { sF = -2; }
@@ -571,4 +571,56 @@ int fastcv_hal_mul32f(
fcvStatus status = FASTCV_SUCCESS;
CV_HAL_RETURN(status, hal_mul32f);
}
int fastcv_hal_SVD32f(
float* src,
size_t src_step,
float* w,
float* u,
size_t u_step,
float* vt,
size_t vt_step,
int m,
int n,
int flags)
{
if (n * sizeof(float) != src_step)
CV_HAL_RETURN_NOT_IMPLEMENTED("step is not supported");
INITIALIZATION_CHECK;
fcvStatus status = FASTCV_SUCCESS;
cv::Mat tmpU(m, n, CV_32F);
cv::Mat tmpV(n, n, CV_32F);
switch (flags)
{
case CV_HAL_SVD_NO_UV:
{
status = fcvSVDf32_v2(src, m, n, w, u, vt, (float32_t *)tmpU.data, (float32_t *)tmpV.data, false);
break;
}
case CV_HAL_SVD_SHORT_UV:
{
if ((n * sizeof(float) == u_step) && (n * sizeof(float) == vt_step))
status = fcvSVDf32_v2(src, m, n, w, u, vt, (float32_t *)tmpU.data, (float32_t *)tmpV.data, false);
else
CV_HAL_RETURN_NOT_IMPLEMENTED("step is not supported");
break;
}
case CV_HAL_SVD_FULL_UV:
{
if ((n * sizeof(float) == u_step) && (n * sizeof(float) == vt_step))
status = fcvSVDf32_v2(src, m, n, w, u, vt, (float32_t *)tmpU.data, (float32_t *)tmpV.data, true);
else
CV_HAL_RETURN_NOT_IMPLEMENTED("step is not supported");
break;
}
default:
CV_HAL_RETURN_NOT_IMPLEMENTED(cv::format("Flags:%d is not supported", flags));
}
CV_HAL_RETURN(status, fastcv_hal_SVD32f);
}