You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge pull request opencv#25892 from WanliZhong:v_sincos
Add support for v_sin and v_cos (Sine and Cosine) opencv#25892
This PR aims to implement `v_sincos(v_float16 x)`, `v_sincos(v_float32 x)` and `v_sincos(v_float64 x)`.
Merged after opencv#25891 and opencv#26023
**NOTE:**
Also, the patch changes already added `v_exp`, `v_log` and `v_erf` to pass parameters by reference instead of by value, to match API of other universal intrinsics.
TODO:
- [x] double and half float precision
- [x] tests for them
- [x] doc to explain the implementation
### 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.
- [ ] The feature is well documented and sample code can be built with the project CMake
* @brief Compute sine \f$ sin(x) \f$ and cosine \f$ cos(x) \f$ of elements at the same time
751
+
*
752
+
* Only for floating point types. Core implementation steps:
753
+
* 1. Input Normalization: Scale the periodicity from 2π to 4 and reduce the angle to the range \f$ [0, \frac{\pi}{4}] \f$ using periodicity and trigonometric identities.
754
+
* 2. Polynomial Approximation for \f$ sin(x) \f$ and \f$ cos(x) \f$:
755
+
* - For float16 and float32, use a Taylor series with 4 terms for sine and 5 terms for cosine.
756
+
* - For float64, use a Taylor series with 7 terms for sine and 8 terms for cosine.
757
+
* 3. Select Results: select and convert the final sine and cosine values for the original input angle.
758
+
*
759
+
* @note The precision of the calculation depends on the implementation and the data type of the input vector.
760
+
*/
761
+
template<typename _Tp, int n>
762
+
inlinevoidv_sincos(const v_reg<_Tp, n>& x, v_reg<_Tp, n>& s, v_reg<_Tp, n>& c)
763
+
{
764
+
for( int i = 0; i < n; i++ )
765
+
{
766
+
s.s[i] = std::sin(x.s[i]);
767
+
c.s[i] = std::cos(x.s[i]);
768
+
}
769
+
}
770
+
771
+
/**
772
+
* @brief Sine \f$ sin(x) \f$ of elements
773
+
*
774
+
* Only for floating point types. Core implementation the same as @ref v_sincos.
775
+
*/
749
776
OPENCV_HAL_IMPL_MATH_FUNC(v_sin, std::sin, _Tp)
777
+
778
+
/**
779
+
* @brief Cosine \f$ cos(x) \f$ of elements
780
+
*
781
+
* Only for floating point types. Core implementation the same as @ref v_sincos.
0 commit comments