The CMSIS DSP 5 library
Dependents: Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more
functions/MatrixFunctions/arm_mat_scale_f32.c@3:4098b9d3d571, 2018-06-21 (annotated)
- Committer:
- xorjoep
- Date:
- Thu Jun 21 11:56:27 2018 +0000
- Revision:
- 3:4098b9d3d571
- Parent:
- 1:24714b45cd1b
headers is a folder not a library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xorjoep | 1:24714b45cd1b | 1 | /* ---------------------------------------------------------------------- |
xorjoep | 1:24714b45cd1b | 2 | * Project: CMSIS DSP Library |
xorjoep | 1:24714b45cd1b | 3 | * Title: arm_mat_scale_f32.c |
xorjoep | 1:24714b45cd1b | 4 | * Description: Multiplies a floating-point matrix by a scalar |
xorjoep | 1:24714b45cd1b | 5 | * |
xorjoep | 1:24714b45cd1b | 6 | * $Date: 27. January 2017 |
xorjoep | 1:24714b45cd1b | 7 | * $Revision: V.1.5.1 |
xorjoep | 1:24714b45cd1b | 8 | * |
xorjoep | 1:24714b45cd1b | 9 | * Target Processor: Cortex-M cores |
xorjoep | 1:24714b45cd1b | 10 | * -------------------------------------------------------------------- */ |
xorjoep | 1:24714b45cd1b | 11 | /* |
xorjoep | 1:24714b45cd1b | 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. |
xorjoep | 1:24714b45cd1b | 13 | * |
xorjoep | 1:24714b45cd1b | 14 | * SPDX-License-Identifier: Apache-2.0 |
xorjoep | 1:24714b45cd1b | 15 | * |
xorjoep | 1:24714b45cd1b | 16 | * Licensed under the Apache License, Version 2.0 (the License); you may |
xorjoep | 1:24714b45cd1b | 17 | * not use this file except in compliance with the License. |
xorjoep | 1:24714b45cd1b | 18 | * You may obtain a copy of the License at |
xorjoep | 1:24714b45cd1b | 19 | * |
xorjoep | 1:24714b45cd1b | 20 | * www.apache.org/licenses/LICENSE-2.0 |
xorjoep | 1:24714b45cd1b | 21 | * |
xorjoep | 1:24714b45cd1b | 22 | * Unless required by applicable law or agreed to in writing, software |
xorjoep | 1:24714b45cd1b | 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
xorjoep | 1:24714b45cd1b | 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
xorjoep | 1:24714b45cd1b | 25 | * See the License for the specific language governing permissions and |
xorjoep | 1:24714b45cd1b | 26 | * limitations under the License. |
xorjoep | 1:24714b45cd1b | 27 | */ |
xorjoep | 1:24714b45cd1b | 28 | |
xorjoep | 1:24714b45cd1b | 29 | #include "arm_math.h" |
xorjoep | 1:24714b45cd1b | 30 | |
xorjoep | 1:24714b45cd1b | 31 | /** |
xorjoep | 1:24714b45cd1b | 32 | * @ingroup groupMatrix |
xorjoep | 1:24714b45cd1b | 33 | */ |
xorjoep | 1:24714b45cd1b | 34 | |
xorjoep | 1:24714b45cd1b | 35 | /** |
xorjoep | 1:24714b45cd1b | 36 | * @defgroup MatrixScale Matrix Scale |
xorjoep | 1:24714b45cd1b | 37 | * |
xorjoep | 1:24714b45cd1b | 38 | * Multiplies a matrix by a scalar. This is accomplished by multiplying each element in the |
xorjoep | 1:24714b45cd1b | 39 | * matrix by the scalar. For example: |
xorjoep | 1:24714b45cd1b | 40 | * \image html MatrixScale.gif "Matrix Scaling of a 3 x 3 matrix" |
xorjoep | 1:24714b45cd1b | 41 | * |
xorjoep | 1:24714b45cd1b | 42 | * The function checks to make sure that the input and output matrices are of the same size. |
xorjoep | 1:24714b45cd1b | 43 | * |
xorjoep | 1:24714b45cd1b | 44 | * In the fixed-point Q15 and Q31 functions, <code>scale</code> is represented by |
xorjoep | 1:24714b45cd1b | 45 | * a fractional multiplication <code>scaleFract</code> and an arithmetic shift <code>shift</code>. |
xorjoep | 1:24714b45cd1b | 46 | * The shift allows the gain of the scaling operation to exceed 1.0. |
xorjoep | 1:24714b45cd1b | 47 | * The overall scale factor applied to the fixed-point data is |
xorjoep | 1:24714b45cd1b | 48 | * <pre> |
xorjoep | 1:24714b45cd1b | 49 | * scale = scaleFract * 2^shift. |
xorjoep | 1:24714b45cd1b | 50 | * </pre> |
xorjoep | 1:24714b45cd1b | 51 | */ |
xorjoep | 1:24714b45cd1b | 52 | |
xorjoep | 1:24714b45cd1b | 53 | /** |
xorjoep | 1:24714b45cd1b | 54 | * @addtogroup MatrixScale |
xorjoep | 1:24714b45cd1b | 55 | * @{ |
xorjoep | 1:24714b45cd1b | 56 | */ |
xorjoep | 1:24714b45cd1b | 57 | |
xorjoep | 1:24714b45cd1b | 58 | /** |
xorjoep | 1:24714b45cd1b | 59 | * @brief Floating-point matrix scaling. |
xorjoep | 1:24714b45cd1b | 60 | * @param[in] *pSrc points to input matrix structure |
xorjoep | 1:24714b45cd1b | 61 | * @param[in] scale scale factor to be applied |
xorjoep | 1:24714b45cd1b | 62 | * @param[out] *pDst points to output matrix structure |
xorjoep | 1:24714b45cd1b | 63 | * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> |
xorjoep | 1:24714b45cd1b | 64 | * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. |
xorjoep | 1:24714b45cd1b | 65 | * |
xorjoep | 1:24714b45cd1b | 66 | */ |
xorjoep | 1:24714b45cd1b | 67 | |
xorjoep | 1:24714b45cd1b | 68 | arm_status arm_mat_scale_f32( |
xorjoep | 1:24714b45cd1b | 69 | const arm_matrix_instance_f32 * pSrc, |
xorjoep | 1:24714b45cd1b | 70 | float32_t scale, |
xorjoep | 1:24714b45cd1b | 71 | arm_matrix_instance_f32 * pDst) |
xorjoep | 1:24714b45cd1b | 72 | { |
xorjoep | 1:24714b45cd1b | 73 | float32_t *pIn = pSrc->pData; /* input data matrix pointer */ |
xorjoep | 1:24714b45cd1b | 74 | float32_t *pOut = pDst->pData; /* output data matrix pointer */ |
xorjoep | 1:24714b45cd1b | 75 | uint32_t numSamples; /* total number of elements in the matrix */ |
xorjoep | 1:24714b45cd1b | 76 | uint32_t blkCnt; /* loop counters */ |
xorjoep | 1:24714b45cd1b | 77 | arm_status status; /* status of matrix scaling */ |
xorjoep | 1:24714b45cd1b | 78 | |
xorjoep | 1:24714b45cd1b | 79 | #if defined (ARM_MATH_DSP) |
xorjoep | 1:24714b45cd1b | 80 | |
xorjoep | 1:24714b45cd1b | 81 | float32_t in1, in2, in3, in4; /* temporary variables */ |
xorjoep | 1:24714b45cd1b | 82 | float32_t out1, out2, out3, out4; /* temporary variables */ |
xorjoep | 1:24714b45cd1b | 83 | |
xorjoep | 1:24714b45cd1b | 84 | #endif // #if defined (ARM_MATH_DSP) |
xorjoep | 1:24714b45cd1b | 85 | |
xorjoep | 1:24714b45cd1b | 86 | #ifdef ARM_MATH_MATRIX_CHECK |
xorjoep | 1:24714b45cd1b | 87 | /* Check for matrix mismatch condition */ |
xorjoep | 1:24714b45cd1b | 88 | if ((pSrc->numRows != pDst->numRows) || (pSrc->numCols != pDst->numCols)) |
xorjoep | 1:24714b45cd1b | 89 | { |
xorjoep | 1:24714b45cd1b | 90 | /* Set status as ARM_MATH_SIZE_MISMATCH */ |
xorjoep | 1:24714b45cd1b | 91 | status = ARM_MATH_SIZE_MISMATCH; |
xorjoep | 1:24714b45cd1b | 92 | } |
xorjoep | 1:24714b45cd1b | 93 | else |
xorjoep | 1:24714b45cd1b | 94 | #endif /* #ifdef ARM_MATH_MATRIX_CHECK */ |
xorjoep | 1:24714b45cd1b | 95 | { |
xorjoep | 1:24714b45cd1b | 96 | /* Total number of samples in the input matrix */ |
xorjoep | 1:24714b45cd1b | 97 | numSamples = (uint32_t) pSrc->numRows * pSrc->numCols; |
xorjoep | 1:24714b45cd1b | 98 | |
xorjoep | 1:24714b45cd1b | 99 | #if defined (ARM_MATH_DSP) |
xorjoep | 1:24714b45cd1b | 100 | |
xorjoep | 1:24714b45cd1b | 101 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
xorjoep | 1:24714b45cd1b | 102 | |
xorjoep | 1:24714b45cd1b | 103 | /* Loop Unrolling */ |
xorjoep | 1:24714b45cd1b | 104 | blkCnt = numSamples >> 2; |
xorjoep | 1:24714b45cd1b | 105 | |
xorjoep | 1:24714b45cd1b | 106 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
xorjoep | 1:24714b45cd1b | 107 | ** a second loop below computes the remaining 1 to 3 samples. */ |
xorjoep | 1:24714b45cd1b | 108 | while (blkCnt > 0U) |
xorjoep | 1:24714b45cd1b | 109 | { |
xorjoep | 1:24714b45cd1b | 110 | /* C(m,n) = A(m,n) * scale */ |
xorjoep | 1:24714b45cd1b | 111 | /* Scaling and results are stored in the destination buffer. */ |
xorjoep | 1:24714b45cd1b | 112 | in1 = pIn[0]; |
xorjoep | 1:24714b45cd1b | 113 | in2 = pIn[1]; |
xorjoep | 1:24714b45cd1b | 114 | in3 = pIn[2]; |
xorjoep | 1:24714b45cd1b | 115 | in4 = pIn[3]; |
xorjoep | 1:24714b45cd1b | 116 | |
xorjoep | 1:24714b45cd1b | 117 | out1 = in1 * scale; |
xorjoep | 1:24714b45cd1b | 118 | out2 = in2 * scale; |
xorjoep | 1:24714b45cd1b | 119 | out3 = in3 * scale; |
xorjoep | 1:24714b45cd1b | 120 | out4 = in4 * scale; |
xorjoep | 1:24714b45cd1b | 121 | |
xorjoep | 1:24714b45cd1b | 122 | |
xorjoep | 1:24714b45cd1b | 123 | pOut[0] = out1; |
xorjoep | 1:24714b45cd1b | 124 | pOut[1] = out2; |
xorjoep | 1:24714b45cd1b | 125 | pOut[2] = out3; |
xorjoep | 1:24714b45cd1b | 126 | pOut[3] = out4; |
xorjoep | 1:24714b45cd1b | 127 | |
xorjoep | 1:24714b45cd1b | 128 | /* update pointers to process next sampels */ |
xorjoep | 1:24714b45cd1b | 129 | pIn += 4U; |
xorjoep | 1:24714b45cd1b | 130 | pOut += 4U; |
xorjoep | 1:24714b45cd1b | 131 | |
xorjoep | 1:24714b45cd1b | 132 | /* Decrement the numSamples loop counter */ |
xorjoep | 1:24714b45cd1b | 133 | blkCnt--; |
xorjoep | 1:24714b45cd1b | 134 | } |
xorjoep | 1:24714b45cd1b | 135 | |
xorjoep | 1:24714b45cd1b | 136 | /* If the numSamples is not a multiple of 4, compute any remaining output samples here. |
xorjoep | 1:24714b45cd1b | 137 | ** No loop unrolling is used. */ |
xorjoep | 1:24714b45cd1b | 138 | blkCnt = numSamples % 0x4U; |
xorjoep | 1:24714b45cd1b | 139 | |
xorjoep | 1:24714b45cd1b | 140 | #else |
xorjoep | 1:24714b45cd1b | 141 | |
xorjoep | 1:24714b45cd1b | 142 | /* Run the below code for Cortex-M0 */ |
xorjoep | 1:24714b45cd1b | 143 | |
xorjoep | 1:24714b45cd1b | 144 | /* Initialize blkCnt with number of samples */ |
xorjoep | 1:24714b45cd1b | 145 | blkCnt = numSamples; |
xorjoep | 1:24714b45cd1b | 146 | |
xorjoep | 1:24714b45cd1b | 147 | #endif /* #if defined (ARM_MATH_DSP) */ |
xorjoep | 1:24714b45cd1b | 148 | |
xorjoep | 1:24714b45cd1b | 149 | while (blkCnt > 0U) |
xorjoep | 1:24714b45cd1b | 150 | { |
xorjoep | 1:24714b45cd1b | 151 | /* C(m,n) = A(m,n) * scale */ |
xorjoep | 1:24714b45cd1b | 152 | /* The results are stored in the destination buffer. */ |
xorjoep | 1:24714b45cd1b | 153 | *pOut++ = (*pIn++) * scale; |
xorjoep | 1:24714b45cd1b | 154 | |
xorjoep | 1:24714b45cd1b | 155 | /* Decrement the loop counter */ |
xorjoep | 1:24714b45cd1b | 156 | blkCnt--; |
xorjoep | 1:24714b45cd1b | 157 | } |
xorjoep | 1:24714b45cd1b | 158 | |
xorjoep | 1:24714b45cd1b | 159 | /* Set status as ARM_MATH_SUCCESS */ |
xorjoep | 1:24714b45cd1b | 160 | status = ARM_MATH_SUCCESS; |
xorjoep | 1:24714b45cd1b | 161 | } |
xorjoep | 1:24714b45cd1b | 162 | |
xorjoep | 1:24714b45cd1b | 163 | /* Return to application */ |
xorjoep | 1:24714b45cd1b | 164 | return (status); |
xorjoep | 1:24714b45cd1b | 165 | } |
xorjoep | 1:24714b45cd1b | 166 | |
xorjoep | 1:24714b45cd1b | 167 | /** |
xorjoep | 1:24714b45cd1b | 168 | * @} end of MatrixScale group |
xorjoep | 1:24714b45cd1b | 169 | */ |