1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_mat_trans_f32.c
4 * Description: Floating-point matrix transpose
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.
30 * @defgroup MatrixTrans Matrix Transpose
33 * Transposing an <code>M x N</code> matrix flips it around the center diagonal and results in an <code>N x M</code> matrix.
34 * \image html MatrixTranspose.gif "Transpose of a 3 x 3 matrix"
40 * @ingroup groupMatrix
44 * @addtogroup MatrixTrans
49 * @brief Floating-point matrix transpose.
50 * @param[in] *pSrc points to the input matrix
51 * @param[out] *pDst points to the output matrix
52 * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
53 * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
57 arm_status
arm_mat_trans_f32(
58 const arm_matrix_instance_f32
* pSrc
,
59 arm_matrix_instance_f32
* pDst
)
61 float32_t
*pIn
= pSrc
->pData
; /* input data matrix pointer */
62 float32_t
*pOut
= pDst
->pData
; /* output data matrix pointer */
63 float32_t
*px
; /* Temporary output data matrix pointer */
64 uint16_t nRows
= pSrc
->numRows
; /* number of rows */
65 uint16_t nColumns
= pSrc
->numCols
; /* number of columns */
67 #if defined (ARM_MATH_DSP)
69 /* Run the below code for Cortex-M4 and Cortex-M3 */
71 uint16_t blkCnt
, i
= 0U, row
= nRows
; /* loop counters */
72 arm_status status
; /* status of matrix transpose */
75 #ifdef ARM_MATH_MATRIX_CHECK
78 /* Check for matrix mismatch condition */
79 if ((pSrc
->numRows
!= pDst
->numCols
) || (pSrc
->numCols
!= pDst
->numRows
))
81 /* Set status as ARM_MATH_SIZE_MISMATCH */
82 status
= ARM_MATH_SIZE_MISMATCH
;
85 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
88 /* Matrix transpose by exchanging the rows with columns */
93 blkCnt
= nColumns
>> 2;
95 /* The pointer px is set to starting address of the column being processed */
98 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
99 ** a second loop below computes the remaining 1 to 3 samples. */
100 while (blkCnt
> 0U) /* column loop */
102 /* Read and store the input element in the destination */
105 /* Update the pointer px to point to the next row of the transposed matrix */
108 /* Read and store the input element in the destination */
111 /* Update the pointer px to point to the next row of the transposed matrix */
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 /* Decrement the column loop counter */
130 /* Perform matrix transpose for last 3 samples here. */
131 blkCnt
= nColumns
% 0x4U
;
135 /* Read and store the input element in the destination */
138 /* Update the pointer px to point to the next row of the transposed matrix */
141 /* Decrement the column loop counter */
147 /* Run the below code for Cortex-M0 */
149 uint16_t col
, i
= 0U, row
= nRows
; /* loop counters */
150 arm_status status
; /* status of matrix transpose */
153 #ifdef ARM_MATH_MATRIX_CHECK
155 /* Check for matrix mismatch condition */
156 if ((pSrc
->numRows
!= pDst
->numCols
) || (pSrc
->numCols
!= pDst
->numRows
))
158 /* Set status as ARM_MATH_SIZE_MISMATCH */
159 status
= ARM_MATH_SIZE_MISMATCH
;
162 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
165 /* Matrix transpose by exchanging the rows with columns */
169 /* The pointer px is set to starting address of the column being processed */
172 /* Initialize column loop counter */
177 /* Read and store the input element in the destination */
180 /* Update the pointer px to point to the next row of the transposed matrix */
183 /* Decrement the column loop counter */
187 #endif /* #if defined (ARM_MATH_DSP) */
191 /* Decrement the row loop counter */
194 } while (row
> 0U); /* row loop end */
196 /* Set status as ARM_MATH_SUCCESS */
197 status
= ARM_MATH_SUCCESS
;
200 /* Return to application */
205 * @} end of MatrixTrans group