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
29 #include "dsp/matrix_functions_f16.h"
30 #include "dsp/basic_math_functions_f16.h"
31 #include "dsp/fast_math_functions_f16.h"
32
33 #include "dsp/matrix_utils.h"
34
35
36 #include <math.h>
37
38
39
40 /**
41 @ingroup groupMatrix
42 */
43
44
45 /**
46 @addtogroup MatrixHouseholder
47 @{
48 */
49
50 /**
51 @brief Householder transform of a half floating point vector.
52 @param[in] pSrc points to the input vector.
53 @param[in] threshold norm2 threshold.
54 @param[in] blockSize dimension of the vector space.
55 @param[out] pOut points to the output vector.
56 @return beta return the scaling factor beta
57 */
58
59
60 #if defined(ARM_FLOAT16_SUPPORTED)
61
62
63
arm_householder_f16(const float16_t * pSrc,const float16_t threshold,uint32_t blockSize,float16_t * pOut)64 ARM_DSP_ATTRIBUTE float16_t arm_householder_f16(
65 const float16_t * pSrc,
66 const float16_t threshold,
67 uint32_t blockSize,
68 float16_t * pOut
69 )
70
71 {
72 uint32_t i;
73 float16_t epsilon;
74 float16_t x1norm2,alpha;
75 float16_t beta,tau,r;
76
77 epsilon = threshold;
78
79 alpha = pSrc[0];
80
81 for(i=1; i < blockSize; i++)
82 {
83 pOut[i] = pSrc[i];
84 }
85 pOut[0] = 1.0f16;
86
87 arm_dot_prod_f16(pSrc+1,pSrc+1,blockSize-1,&x1norm2);
88
89 if ((_Float16)x1norm2<=(_Float16)epsilon)
90 {
91 tau = 0.0f16;
92 memset(pOut,0,blockSize * sizeof(float16_t));
93 }
94 else
95 {
96 beta = (_Float16)alpha * (_Float16)alpha + (_Float16)x1norm2;
97 (void)arm_sqrt_f16(beta,&beta);
98
99 if ((_Float16)alpha > 0.0f16)
100 {
101 beta = -(_Float16)beta;
102 }
103
104 r = 1.0f16 / ((_Float16)alpha -(_Float16)beta);
105 arm_scale_f16(pOut,r,pOut,blockSize);
106 pOut[0] = 1.0f16;
107
108
109 tau = ((_Float16)beta - (_Float16)alpha) / (_Float16)beta;
110
111 }
112
113 return(tau);
114
115 }
116
117
118 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
119 /**
120 @} end of MatrixHouseholder group
121 */
122