Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
arm_mat_scale_f32.c
00001 /* ---------------------------------------------------------------------- 00002 * Project: CMSIS DSP Library 00003 * Title: arm_mat_scale_f32.c 00004 * Description: Multiplies a floating-point matrix by a scalar 00005 * 00006 * $Date: 27. January 2017 00007 * $Revision: V.1.5.1 00008 * 00009 * Target Processor: Cortex-M cores 00010 * -------------------------------------------------------------------- */ 00011 /* 00012 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 00013 * 00014 * SPDX-License-Identifier: Apache-2.0 00015 * 00016 * Licensed under the Apache License, Version 2.0 (the License); you may 00017 * not use this file except in compliance with the License. 00018 * You may obtain a copy of the License at 00019 * 00020 * www.apache.org/licenses/LICENSE-2.0 00021 * 00022 * Unless required by applicable law or agreed to in writing, software 00023 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00024 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00025 * See the License for the specific language governing permissions and 00026 * limitations under the License. 00027 */ 00028 00029 #include "arm_math.h" 00030 00031 /** 00032 * @ingroup groupMatrix 00033 */ 00034 00035 /** 00036 * @defgroup MatrixScale Matrix Scale 00037 * 00038 * Multiplies a matrix by a scalar. This is accomplished by multiplying each element in the 00039 * matrix by the scalar. For example: 00040 * \image html MatrixScale.gif "Matrix Scaling of a 3 x 3 matrix" 00041 * 00042 * The function checks to make sure that the input and output matrices are of the same size. 00043 * 00044 * In the fixed-point Q15 and Q31 functions, <code>scale</code> is represented by 00045 * a fractional multiplication <code>scaleFract</code> and an arithmetic shift <code>shift</code>. 00046 * The shift allows the gain of the scaling operation to exceed 1.0. 00047 * The overall scale factor applied to the fixed-point data is 00048 * <pre> 00049 * scale = scaleFract * 2^shift. 00050 * </pre> 00051 */ 00052 00053 /** 00054 * @addtogroup MatrixScale 00055 * @{ 00056 */ 00057 00058 /** 00059 * @brief Floating-point matrix scaling. 00060 * @param[in] *pSrc points to input matrix structure 00061 * @param[in] scale scale factor to be applied 00062 * @param[out] *pDst points to output matrix structure 00063 * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> 00064 * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. 00065 * 00066 */ 00067 00068 arm_status arm_mat_scale_f32( 00069 const arm_matrix_instance_f32 * pSrc, 00070 float32_t scale, 00071 arm_matrix_instance_f32 * pDst) 00072 { 00073 float32_t *pIn = pSrc->pData; /* input data matrix pointer */ 00074 float32_t *pOut = pDst->pData; /* output data matrix pointer */ 00075 uint32_t numSamples; /* total number of elements in the matrix */ 00076 uint32_t blkCnt; /* loop counters */ 00077 arm_status status; /* status of matrix scaling */ 00078 00079 #if defined (ARM_MATH_DSP) 00080 00081 float32_t in1, in2, in3, in4; /* temporary variables */ 00082 float32_t out1, out2, out3, out4; /* temporary variables */ 00083 00084 #endif // #if defined (ARM_MATH_DSP) 00085 00086 #ifdef ARM_MATH_MATRIX_CHECK 00087 /* Check for matrix mismatch condition */ 00088 if ((pSrc->numRows != pDst->numRows) || (pSrc->numCols != pDst->numCols)) 00089 { 00090 /* Set status as ARM_MATH_SIZE_MISMATCH */ 00091 status = ARM_MATH_SIZE_MISMATCH; 00092 } 00093 else 00094 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */ 00095 { 00096 /* Total number of samples in the input matrix */ 00097 numSamples = (uint32_t) pSrc->numRows * pSrc->numCols; 00098 00099 #if defined (ARM_MATH_DSP) 00100 00101 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00102 00103 /* Loop Unrolling */ 00104 blkCnt = numSamples >> 2; 00105 00106 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00107 ** a second loop below computes the remaining 1 to 3 samples. */ 00108 while (blkCnt > 0U) 00109 { 00110 /* C(m,n) = A(m,n) * scale */ 00111 /* Scaling and results are stored in the destination buffer. */ 00112 in1 = pIn[0]; 00113 in2 = pIn[1]; 00114 in3 = pIn[2]; 00115 in4 = pIn[3]; 00116 00117 out1 = in1 * scale; 00118 out2 = in2 * scale; 00119 out3 = in3 * scale; 00120 out4 = in4 * scale; 00121 00122 00123 pOut[0] = out1; 00124 pOut[1] = out2; 00125 pOut[2] = out3; 00126 pOut[3] = out4; 00127 00128 /* update pointers to process next sampels */ 00129 pIn += 4U; 00130 pOut += 4U; 00131 00132 /* Decrement the numSamples loop counter */ 00133 blkCnt--; 00134 } 00135 00136 /* If the numSamples is not a multiple of 4, compute any remaining output samples here. 00137 ** No loop unrolling is used. */ 00138 blkCnt = numSamples % 0x4U; 00139 00140 #else 00141 00142 /* Run the below code for Cortex-M0 */ 00143 00144 /* Initialize blkCnt with number of samples */ 00145 blkCnt = numSamples; 00146 00147 #endif /* #if defined (ARM_MATH_DSP) */ 00148 00149 while (blkCnt > 0U) 00150 { 00151 /* C(m,n) = A(m,n) * scale */ 00152 /* The results are stored in the destination buffer. */ 00153 *pOut++ = (*pIn++) * scale; 00154 00155 /* Decrement the loop counter */ 00156 blkCnt--; 00157 } 00158 00159 /* Set status as ARM_MATH_SUCCESS */ 00160 status = ARM_MATH_SUCCESS; 00161 } 00162 00163 /* Return to application */ 00164 return (status); 00165 } 00166 00167 /** 00168 * @} end of MatrixScale group 00169 */ 00170
Generated on Tue Jul 12 2022 16:47:27 by
