source: S-port/trunk/Drivers/CMSIS/DSP/Source/MatrixFunctions/arm_mat_scale_f32.c@ 1

Last change on this file since 1 was 1, checked in by AlexLir, 2 years ago
File size: 5.1 KB
Line 
1/* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_mat_scale_f32.c
4 * Description: Multiplies a floating-point matrix by a scalar
5 *
6 * $Date: 27. January 2017
7 * $Revision: V.1.5.1
8 *
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
11/*
12 * Copyright (C) 2010-2017 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 "arm_math.h"
30
31/**
32 * @ingroup groupMatrix
33 */
34
35/**
36 * @defgroup MatrixScale Matrix Scale
37 *
38 * Multiplies a matrix by a scalar. This is accomplished by multiplying each element in the
39 * matrix by the scalar. For example:
40 * \image html MatrixScale.gif "Matrix Scaling of a 3 x 3 matrix"
41 *
42 * The function checks to make sure that the input and output matrices are of the same size.
43 *
44 * In the fixed-point Q15 and Q31 functions, <code>scale</code> is represented by
45 * a fractional multiplication <code>scaleFract</code> and an arithmetic shift <code>shift</code>.
46 * The shift allows the gain of the scaling operation to exceed 1.0.
47 * The overall scale factor applied to the fixed-point data is
48 * <pre>
49 * scale = scaleFract * 2^shift.
50 * </pre>
51 */
52
53/**
54 * @addtogroup MatrixScale
55 * @{
56 */
57
58/**
59 * @brief Floating-point matrix scaling.
60 * @param[in] *pSrc points to input matrix structure
61 * @param[in] scale scale factor to be applied
62 * @param[out] *pDst points to output matrix structure
63 * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
64 * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
65 *
66 */
67
68arm_status arm_mat_scale_f32(
69 const arm_matrix_instance_f32 * pSrc,
70 float32_t scale,
71 arm_matrix_instance_f32 * pDst)
72{
73 float32_t *pIn = pSrc->pData; /* input data matrix pointer */
74 float32_t *pOut = pDst->pData; /* output data matrix pointer */
75 uint32_t numSamples; /* total number of elements in the matrix */
76 uint32_t blkCnt; /* loop counters */
77 arm_status status; /* status of matrix scaling */
78
79#if defined (ARM_MATH_DSP)
80
81 float32_t in1, in2, in3, in4; /* temporary variables */
82 float32_t out1, out2, out3, out4; /* temporary variables */
83
84#endif // #if defined (ARM_MATH_DSP)
85
86#ifdef ARM_MATH_MATRIX_CHECK
87 /* Check for matrix mismatch condition */
88 if ((pSrc->numRows != pDst->numRows) || (pSrc->numCols != pDst->numCols))
89 {
90 /* Set status as ARM_MATH_SIZE_MISMATCH */
91 status = ARM_MATH_SIZE_MISMATCH;
92 }
93 else
94#endif /* #ifdef ARM_MATH_MATRIX_CHECK */
95 {
96 /* Total number of samples in the input matrix */
97 numSamples = (uint32_t) pSrc->numRows * pSrc->numCols;
98
99#if defined (ARM_MATH_DSP)
100
101 /* Run the below code for Cortex-M4 and Cortex-M3 */
102
103 /* Loop Unrolling */
104 blkCnt = numSamples >> 2;
105
106 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
107 ** a second loop below computes the remaining 1 to 3 samples. */
108 while (blkCnt > 0U)
109 {
110 /* C(m,n) = A(m,n) * scale */
111 /* Scaling and results are stored in the destination buffer. */
112 in1 = pIn[0];
113 in2 = pIn[1];
114 in3 = pIn[2];
115 in4 = pIn[3];
116
117 out1 = in1 * scale;
118 out2 = in2 * scale;
119 out3 = in3 * scale;
120 out4 = in4 * scale;
121
122
123 pOut[0] = out1;
124 pOut[1] = out2;
125 pOut[2] = out3;
126 pOut[3] = out4;
127
128 /* update pointers to process next sampels */
129 pIn += 4U;
130 pOut += 4U;
131
132 /* Decrement the numSamples loop counter */
133 blkCnt--;
134 }
135
136 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
137 ** No loop unrolling is used. */
138 blkCnt = numSamples % 0x4U;
139
140#else
141
142 /* Run the below code for Cortex-M0 */
143
144 /* Initialize blkCnt with number of samples */
145 blkCnt = numSamples;
146
147#endif /* #if defined (ARM_MATH_DSP) */
148
149 while (blkCnt > 0U)
150 {
151 /* C(m,n) = A(m,n) * scale */
152 /* The results are stored in the destination buffer. */
153 *pOut++ = (*pIn++) * scale;
154
155 /* Decrement the loop counter */
156 blkCnt--;
157 }
158
159 /* Set status as ARM_MATH_SUCCESS */
160 status = ARM_MATH_SUCCESS;
161 }
162
163 /* Return to application */
164 return (status);
165}
166
167/**
168 * @} end of MatrixScale group
169 */
Note: See TracBrowser for help on using the repository browser.