arm_householder_f16.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_householder_f16.c
  4. * Description: Half floating-point Householder transform
  5. *
  6. * $Date: 15 June 2022
  7. * $Revision: V1.11.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2022 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. #include "dsp/matrix_functions_f16.h"
  29. #include "dsp/basic_math_functions_f16.h"
  30. #include "dsp/fast_math_functions_f16.h"
  31. #include "dsp/matrix_utils.h"
  32. #include <math.h>
  33. /**
  34. @ingroup groupMatrix
  35. */
  36. /**
  37. @addtogroup MatrixHouseholder
  38. @{
  39. */
  40. /**
  41. @brief Householder transform of a half floating point vector.
  42. @param[in] pSrc points to the input vector.
  43. @param[in] threshold norm2 threshold.
  44. @param[in] blockSize dimension of the vector space.
  45. @param[out] pOut points to the output vector.
  46. @return beta return the scaling factor beta
  47. */
  48. #if defined(ARM_FLOAT16_SUPPORTED)
  49. float16_t arm_householder_f16(
  50. const float16_t * pSrc,
  51. const float16_t threshold,
  52. uint32_t blockSize,
  53. float16_t * pOut
  54. )
  55. {
  56. uint32_t i;
  57. float16_t epsilon;
  58. float16_t x1norm2,alpha;
  59. float16_t beta,tau,r;
  60. epsilon = threshold;
  61. alpha = pSrc[0];
  62. for(i=1; i < blockSize; i++)
  63. {
  64. pOut[i] = pSrc[i];
  65. }
  66. pOut[0] = 1.0f16;
  67. arm_dot_prod_f16(pSrc+1,pSrc+1,blockSize-1,&x1norm2);
  68. if ((_Float16)x1norm2<=(_Float16)epsilon)
  69. {
  70. tau = 0.0f16;
  71. memset(pOut,0,blockSize * sizeof(float16_t));
  72. }
  73. else
  74. {
  75. beta = (_Float16)alpha * (_Float16)alpha + (_Float16)x1norm2;
  76. (void)arm_sqrt_f16(beta,&beta);
  77. if ((_Float16)alpha > 0.0f16)
  78. {
  79. beta = -(_Float16)beta;
  80. }
  81. r = 1.0f16 / ((_Float16)alpha -(_Float16)beta);
  82. arm_scale_f16(pOut,r,pOut,blockSize);
  83. pOut[0] = 1.0f16;
  84. tau = ((_Float16)beta - (_Float16)alpha) / (_Float16)beta;
  85. }
  86. return(tau);
  87. }
  88. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
  89. /**
  90. @} end of MatrixHouseholder group
  91. */