1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_mat_scale_f32.c
4 * Description: Multiplies a floating-point matrix by a scalar
6 * $Date: 27. January 2017
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
14 * SPDX-License-Identifier: Apache-2.0
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
20 * www.apache.org/licenses/LICENSE-2.0
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.
32 * @ingroup groupMatrix
36 * @defgroup MatrixScale Matrix Scale
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"
42 * The function checks to make sure that the input and output matrices are of the same size.
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
49 * scale = scaleFract * 2^shift.
54 * @addtogroup MatrixScale
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.
68 arm_status
arm_mat_scale_f32(
69 const arm_matrix_instance_f32
* pSrc
,
71 arm_matrix_instance_f32
* pDst
)
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 */
79 #if defined (ARM_MATH_DSP)
81 float32_t in1
, in2
, in3
, in4
; /* temporary variables */
82 float32_t out1
, out2
, out3
, out4
; /* temporary variables */
84 #endif // #if defined (ARM_MATH_DSP)
86 #ifdef ARM_MATH_MATRIX_CHECK
87 /* Check for matrix mismatch condition */
88 if ((pSrc
->numRows
!= pDst
->numRows
) || (pSrc
->numCols
!= pDst
->numCols
))
90 /* Set status as ARM_MATH_SIZE_MISMATCH */
91 status
= ARM_MATH_SIZE_MISMATCH
;
94 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
96 /* Total number of samples in the input matrix */
97 numSamples
= (uint32_t) pSrc
->numRows
* pSrc
->numCols
;
99 #if defined (ARM_MATH_DSP)
101 /* Run the below code for Cortex-M4 and Cortex-M3 */
104 blkCnt
= numSamples
>> 2;
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. */
110 /* C(m,n) = A(m,n) * scale */
111 /* Scaling and results are stored in the destination buffer. */
128 /* update pointers to process next sampels */
132 /* Decrement the numSamples loop counter */
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
;
142 /* Run the below code for Cortex-M0 */
144 /* Initialize blkCnt with number of samples */
147 #endif /* #if defined (ARM_MATH_DSP) */
151 /* C(m,n) = A(m,n) * scale */
152 /* The results are stored in the destination buffer. */
153 *pOut
++ = (*pIn
++) * scale
;
155 /* Decrement the loop counter */
159 /* Set status as ARM_MATH_SUCCESS */
160 status
= ARM_MATH_SUCCESS
;
163 /* Return to application */
168 * @} end of MatrixScale group