arm_householder_f64.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_householder_f64.c
  4. * Description: Double 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.h"
  29. #include "dsp/basic_math_functions.h"
  30. #include "dsp/fast_math_functions.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 double 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. float64_t arm_householder_f64(
  49. const float64_t * pSrc,
  50. const float64_t threshold,
  51. uint32_t blockSize,
  52. float64_t * pOut
  53. )
  54. {
  55. uint32_t i;
  56. float64_t epsilon;
  57. float64_t x1norm2,alpha;
  58. float64_t beta,tau,r;
  59. epsilon = threshold;
  60. alpha = pSrc[0];
  61. for(i=1; i < blockSize; i++)
  62. {
  63. pOut[i] = pSrc[i];
  64. }
  65. pOut[0] = 1.0;
  66. arm_dot_prod_f64(pSrc+1,pSrc+1,blockSize-1,&x1norm2);
  67. if (x1norm2<=epsilon)
  68. {
  69. tau = 0.0;
  70. memset(pOut,0,blockSize * sizeof(float64_t));
  71. }
  72. else
  73. {
  74. beta = alpha * alpha + x1norm2;
  75. beta=sqrt(beta);
  76. if (alpha > 0.0)
  77. {
  78. beta = -beta;
  79. }
  80. r = 1.0 / (alpha -beta);
  81. arm_scale_f64(pOut,r,pOut,blockSize);
  82. pOut[0] = 1.0;
  83. tau = (beta - alpha) / beta;
  84. }
  85. return(tau);
  86. }
  87. /**
  88. @} end of MatrixHouseholder group
  89. */