1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_mat_cmplx_trans_f32.c
4  * Description:  Floating-point complex matrix transpose
5  *
6  * $Date:        23 April 2021
7  * $Revision:    V1.9.0
8  *
9  * Target Processor: Cortex-M and Cortex-A cores
10  * -------------------------------------------------------------------- */
11 /*
12  * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
13  *
14  * SPDX-License-Identifier: Apache-2.0
15  *
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
19  *
20  * www.apache.org/licenses/LICENSE-2.0
21  *
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.
27  */
28 
29 #include "dsp/matrix_functions.h"
30 
31 /**
32   @ingroup groupMatrix
33  */
34 
35 /**
36   @defgroup MatrixComplexTrans Complex Matrix Transpose
37 
38   Tranposes a complex matrix.
39 
40   Transposing an <code>M x N</code> matrix flips it around the center diagonal and results in an <code>N x M</code> matrix.
41 
42   @par Transpose of a 3 x 3 matrix
43 
44   \f[
45   \begin{pmatrix}
46    a_{1,1} & a_{1,2} & a_{1,3} \\
47    a_{2,1} & a_{2,2} & a_{2,3} \\
48    a_{3,1} & a_{3,2} & a_{3,3} \\
49   \end{pmatrix}^T
50    =
51   \begin{pmatrix}
52    a_{1,1} & a_{2,1} & a_{3,1} \\
53    a_{1,2} & a_{2,2} & a_{3,2} \\
54    a_{1,3} & a_{2,3} & a_{3,3} \\
55   \end{pmatrix}
56   \f]
57 
58  */
59 
60 /**
61   @addtogroup MatrixComplexTrans
62   @{
63  */
64 
65 /**
66   @brief         Floating-point matrix transpose.
67   @param[in]     pSrc      points to input matrix
68   @param[out]    pDst      points to output matrix
69   @return        execution status
70                    - \ref ARM_MATH_SUCCESS       : Operation successful
71                    - \ref ARM_MATH_SIZE_MISMATCH : Matrix size check failed
72  */
73 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
74 
75 #include "arm_helium_utils.h"
76 
arm_mat_cmplx_trans_f32(const arm_matrix_instance_f32 * pSrc,arm_matrix_instance_f32 * pDst)77 ARM_DSP_ATTRIBUTE arm_status arm_mat_cmplx_trans_f32(const arm_matrix_instance_f32 * pSrc, arm_matrix_instance_f32 * pDst)
78 {
79     return arm_mat_cmplx_trans_32bit(pSrc->numRows, pSrc->numCols, (uint32_t *) pSrc->pData,
80                                    pDst->numRows, pDst->numCols, (uint32_t *) pDst->pData);
81 }
82 
83 #else
arm_mat_cmplx_trans_f32(const arm_matrix_instance_f32 * pSrc,arm_matrix_instance_f32 * pDst)84 ARM_DSP_ATTRIBUTE arm_status arm_mat_cmplx_trans_f32(
85   const arm_matrix_instance_f32 * pSrc,
86   arm_matrix_instance_f32 * pDst)
87 {
88   float32_t *pIn = pSrc->pData;                  /* input data matrix pointer */
89   float32_t *pOut = pDst->pData;                 /* output data matrix pointer */
90   float32_t *px;                                 /* Temporary output data matrix pointer */
91   uint16_t nRows = pSrc->numRows;                /* number of rows */
92   uint16_t nColumns = pSrc->numCols;             /* number of columns */
93   uint16_t col, i = 0U, row = nRows;             /* loop counters */
94   arm_status status;                             /* status of matrix transpose  */
95 
96 
97 #ifdef ARM_MATH_MATRIX_CHECK
98 
99   /* Check for matrix mismatch condition */
100   if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
101   {
102     /* Set status as ARM_MATH_SIZE_MISMATCH */
103     status = ARM_MATH_SIZE_MISMATCH;
104   }
105   else
106 #endif /*      #ifdef ARM_MATH_MATRIX_CHECK    */
107 
108   {
109     /* Matrix transpose by exchanging the rows with columns */
110     /* row loop     */
111     do
112     {
113       /* The pointer px is set to starting address of the column being processed */
114       px = pOut + CMPLX_DIM * i;
115 
116       /* Initialize column loop counter */
117       col = nColumns;
118 
119       while (col > 0U)
120       {
121         /* Read and store the input element in the destination */
122         px[0] = *pIn++; // real
123         px[1] = *pIn++; // imag
124 
125         /* Update the pointer px to point to the next row of the transposed matrix */
126         px += CMPLX_DIM * nRows;
127 
128         /* Decrement the column loop counter */
129         col--;
130       }
131       i++;
132 
133       /* Decrement the row loop counter */
134       row--;
135 
136     } while (row > 0U);          /* row loop end  */
137 
138     /* Set status as ARM_MATH_SUCCESS */
139     status = ARM_MATH_SUCCESS;
140   }
141 
142   /* Return to application */
143   return (status);
144 }
145 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
146 
147 /**
148  * @} end of MatrixTrans group
149  */
150