1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010-2013 ARM Limited. All rights reserved.
4 * $Date: 17. January 2013
7 * Project: CMSIS DSP Library
8 * Title: arm_mat_trans_f32.c
10 * Description: Floating-point matrix transpose.
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * - Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * - Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
23 * - Neither the name of ARM LIMITED nor the names of its contributors
24 * may be used to endorse or promote products derived from this
25 * software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 * -------------------------------------------------------------------- */
42 * @defgroup MatrixTrans Matrix Transpose
45 * Transposing an <code>M x N</code> matrix flips it around the center diagonal and results in an <code>N x M</code> matrix.
46 * \image html MatrixTranspose.gif "Transpose of a 3 x 3 matrix"
52 * @ingroup groupMatrix
56 * @addtogroup MatrixTrans
61 * @brief Floating-point matrix transpose.
62 * @param[in] *pSrc points to the input matrix
63 * @param[out] *pDst points to the output matrix
64 * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
65 * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
69 arm_status arm_mat_trans_f32(
70 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 float32_t *px; /* Temporary output data matrix pointer */
76 uint16_t nRows = pSrc->numRows; /* number of rows */
77 uint16_t nColumns = pSrc->numCols; /* number of columns */
79 #ifndef ARM_MATH_CM0_FAMILY
81 /* Run the below code for Cortex-M4 and Cortex-M3 */
83 uint16_t blkCnt, i = 0u, row = nRows; /* loop counters */
84 arm_status status; /* status of matrix transpose */
87 #ifdef ARM_MATH_MATRIX_CHECK
90 /* Check for matrix mismatch condition */
91 if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
93 /* Set status as ARM_MATH_SIZE_MISMATCH */
94 status = ARM_MATH_SIZE_MISMATCH;
97 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
100 /* Matrix transpose by exchanging the rows with columns */
105 blkCnt = nColumns >> 2;
107 /* The pointer px is set to starting address of the column being processed */
110 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
111 ** a second loop below computes the remaining 1 to 3 samples. */
112 while(blkCnt > 0u) /* column loop */
114 /* Read and store the input element in the destination */
117 /* Update the pointer px to point to the next row of the transposed matrix */
120 /* Read and store the input element in the destination */
123 /* Update the pointer px to point to the next row of the transposed matrix */
126 /* Read and store the input element in the destination */
129 /* Update the pointer px to point to the next row of the transposed matrix */
132 /* Read and store the input element in the destination */
135 /* Update the pointer px to point to the next row of the transposed matrix */
138 /* Decrement the column loop counter */
142 /* Perform matrix transpose for last 3 samples here. */
143 blkCnt = nColumns % 0x4u;
147 /* Read and store the input element in the destination */
150 /* Update the pointer px to point to the next row of the transposed matrix */
153 /* Decrement the column loop counter */
159 /* Run the below code for Cortex-M0 */
161 uint16_t col, i = 0u, row = nRows; /* loop counters */
162 arm_status status; /* status of matrix transpose */
165 #ifdef ARM_MATH_MATRIX_CHECK
167 /* Check for matrix mismatch condition */
168 if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
170 /* Set status as ARM_MATH_SIZE_MISMATCH */
171 status = ARM_MATH_SIZE_MISMATCH;
174 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
177 /* Matrix transpose by exchanging the rows with columns */
181 /* The pointer px is set to starting address of the column being processed */
184 /* Initialize column loop counter */
189 /* Read and store the input element in the destination */
192 /* Update the pointer px to point to the next row of the transposed matrix */
195 /* Decrement the column loop counter */
199 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
203 /* Decrement the row loop counter */
206 } while(row > 0u); /* row loop end */
208 /* Set status as ARM_MATH_SUCCESS */
209 status = ARM_MATH_SUCCESS;
212 /* Return to application */
217 * @} end of MatrixTrans group