1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010 ARM Limited. All rights reserved.
7 * Project: CMSIS DSP Library
8 * Title: arm_mat_scale_f32.c
10 * Description: Multiplies a floating-point matrix by a scalar.
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
14 * Version 1.0.10 2011/7/15
15 * Big Endian support added and Merged M0 and M3/M4 Source code.
17 * Version 1.0.3 2010/11/29
18 * Re-organized the CMSIS folders and updated documentation.
20 * Version 1.0.2 2010/11/11
21 * Documentation updated.
23 * Version 1.0.1 2010/10/05
24 * Production release and review comments incorporated.
26 * Version 1.0.0 2010/09/20
27 * Production release and review comments incorporated.
29 * Version 0.0.5 2010/04/26
30 * incorporated review comments and updated with latest CMSIS layer
32 * Version 0.0.3 2010/03/10
34 * -------------------------------------------------------------------- */
39 * @ingroup groupMatrix
43 * @defgroup MatrixScale Matrix Scale
45 * Multiplies a matrix by a scalar. This is accomplished by multiplying each element in the
46 * matrix by the scalar. For example:
47 * \image html MatrixScale.gif "Matrix Scaling of a 3 x 3 matrix"
49 * The function checks to make sure that the input and output matrices are of the same size.
51 * In the fixed-point Q15 and Q31 functions, <code>scale</code> is represented by
52 * a fractional multiplication <code>scaleFract</code> and an arithmetic shift <code>shift</code>.
53 * The shift allows the gain of the scaling operation to exceed 1.0.
54 * The overall scale factor applied to the fixed-point data is
56 * scale = scaleFract * 2^shift.
61 * @addtogroup MatrixScale
66 * @brief Floating-point matrix scaling.
67 * @param[in] *pSrc points to input matrix structure
68 * @param[in] scale scale factor to be applied
69 * @param[out] *pDst points to output matrix structure
70 * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
71 * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
75 arm_status arm_mat_scale_f32(
76 const arm_matrix_instance_f32 * pSrc,
78 arm_matrix_instance_f32 * pDst)
80 float32_t *pIn = pSrc->pData; /* input data matrix pointer */
81 float32_t *pOut = pDst->pData; /* output data matrix pointer */
82 uint32_t numSamples; /* total number of elements in the matrix */
83 uint32_t blkCnt; /* loop counters */
84 arm_status status; /* status of matrix scaling */
86 #ifdef ARM_MATH_MATRIX_CHECK
89 /* Check for matrix mismatch condition */
90 if((pSrc->numRows != pDst->numRows) || (pSrc->numCols != pDst->numCols))
92 /* Set status as ARM_MATH_SIZE_MISMATCH */
93 status = ARM_MATH_SIZE_MISMATCH;
96 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
99 /* Total number of samples in the input matrix */
100 numSamples = (uint32_t) pSrc->numRows * pSrc->numCols;
104 /* Run the below code for Cortex-M4 and Cortex-M3 */
107 blkCnt = numSamples >> 2;
109 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
110 ** a second loop below computes the remaining 1 to 3 samples. */
113 /* C(m,n) = A(m,n) * scale */
114 /* Scaling and results are stored in the destination buffer. */
115 *pOut++ = (*pIn++) * scale;
116 *pOut++ = (*pIn++) * scale;
117 *pOut++ = (*pIn++) * scale;
118 *pOut++ = (*pIn++) * scale;
120 /* Decrement the numSamples loop counter */
124 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
125 ** No loop unrolling is used. */
126 blkCnt = numSamples % 0x4u;
130 /* Run the below code for Cortex-M0 */
132 /* Initialize blkCnt with number of samples */
135 #endif /* #ifndef ARM_MATH_CM0 */
139 /* C(m,n) = A(m,n) * scale */
140 /* The results are stored in the destination buffer. */
141 *pOut++ = (*pIn++) * scale;
143 /* Decrement the loop counter */
146 /* Set status as ARM_MATH_SUCCESS */
147 status = ARM_MATH_SUCCESS;
150 /* Return to application */
155 * @} end of MatrixScale group