Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
56 | mjames | 1 | /* ---------------------------------------------------------------------- |
2 | * Project: CMSIS DSP Library |
||
3 | * Title: arm_mat_trans_f32.c |
||
4 | * Description: Floating-point matrix transpose |
||
5 | * |
||
6 | * $Date: 27. January 2017 |
||
7 | * $Revision: V.1.5.1 |
||
8 | * |
||
9 | * Target Processor: Cortex-M cores |
||
10 | * -------------------------------------------------------------------- */ |
||
11 | /* |
||
12 | * Copyright (C) 2010-2017 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 | /** |
||
30 | * @defgroup MatrixTrans Matrix Transpose |
||
31 | * |
||
32 | * Tranposes a matrix. |
||
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" |
||
35 | */ |
||
36 | |||
37 | #include "arm_math.h" |
||
38 | |||
39 | /** |
||
40 | * @ingroup groupMatrix |
||
41 | */ |
||
42 | |||
43 | /** |
||
44 | * @addtogroup MatrixTrans |
||
45 | * @{ |
||
46 | */ |
||
47 | |||
48 | /** |
||
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. |
||
54 | */ |
||
55 | |||
56 | |||
57 | arm_status arm_mat_trans_f32( |
||
58 | const arm_matrix_instance_f32 * pSrc, |
||
59 | arm_matrix_instance_f32 * pDst) |
||
60 | { |
||
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 */ |
||
66 | |||
67 | #if defined (ARM_MATH_DSP) |
||
68 | |||
69 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
||
70 | |||
71 | uint16_t blkCnt, i = 0U, row = nRows; /* loop counters */ |
||
72 | arm_status status; /* status of matrix transpose */ |
||
73 | |||
74 | |||
75 | #ifdef ARM_MATH_MATRIX_CHECK |
||
76 | |||
77 | |||
78 | /* Check for matrix mismatch condition */ |
||
79 | if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows)) |
||
80 | { |
||
81 | /* Set status as ARM_MATH_SIZE_MISMATCH */ |
||
82 | status = ARM_MATH_SIZE_MISMATCH; |
||
83 | } |
||
84 | else |
||
85 | #endif /* #ifdef ARM_MATH_MATRIX_CHECK */ |
||
86 | |||
87 | { |
||
88 | /* Matrix transpose by exchanging the rows with columns */ |
||
89 | /* row loop */ |
||
90 | do |
||
91 | { |
||
92 | /* Loop Unrolling */ |
||
93 | blkCnt = nColumns >> 2; |
||
94 | |||
95 | /* The pointer px is set to starting address of the column being processed */ |
||
96 | px = pOut + i; |
||
97 | |||
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 */ |
||
101 | { |
||
102 | /* Read and store the input element in the destination */ |
||
103 | *px = *pIn++; |
||
104 | |||
105 | /* Update the pointer px to point to the next row of the transposed matrix */ |
||
106 | px += nRows; |
||
107 | |||
108 | /* Read and store the input element in the destination */ |
||
109 | *px = *pIn++; |
||
110 | |||
111 | /* Update the pointer px to point to the next row of the transposed matrix */ |
||
112 | px += nRows; |
||
113 | |||
114 | /* Read and store the input element in the destination */ |
||
115 | *px = *pIn++; |
||
116 | |||
117 | /* Update the pointer px to point to the next row of the transposed matrix */ |
||
118 | px += nRows; |
||
119 | |||
120 | /* Read and store the input element in the destination */ |
||
121 | *px = *pIn++; |
||
122 | |||
123 | /* Update the pointer px to point to the next row of the transposed matrix */ |
||
124 | px += nRows; |
||
125 | |||
126 | /* Decrement the column loop counter */ |
||
127 | blkCnt--; |
||
128 | } |
||
129 | |||
130 | /* Perform matrix transpose for last 3 samples here. */ |
||
131 | blkCnt = nColumns % 0x4U; |
||
132 | |||
133 | while (blkCnt > 0U) |
||
134 | { |
||
135 | /* Read and store the input element in the destination */ |
||
136 | *px = *pIn++; |
||
137 | |||
138 | /* Update the pointer px to point to the next row of the transposed matrix */ |
||
139 | px += nRows; |
||
140 | |||
141 | /* Decrement the column loop counter */ |
||
142 | blkCnt--; |
||
143 | } |
||
144 | |||
145 | #else |
||
146 | |||
147 | /* Run the below code for Cortex-M0 */ |
||
148 | |||
149 | uint16_t col, i = 0U, row = nRows; /* loop counters */ |
||
150 | arm_status status; /* status of matrix transpose */ |
||
151 | |||
152 | |||
153 | #ifdef ARM_MATH_MATRIX_CHECK |
||
154 | |||
155 | /* Check for matrix mismatch condition */ |
||
156 | if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows)) |
||
157 | { |
||
158 | /* Set status as ARM_MATH_SIZE_MISMATCH */ |
||
159 | status = ARM_MATH_SIZE_MISMATCH; |
||
160 | } |
||
161 | else |
||
162 | #endif /* #ifdef ARM_MATH_MATRIX_CHECK */ |
||
163 | |||
164 | { |
||
165 | /* Matrix transpose by exchanging the rows with columns */ |
||
166 | /* row loop */ |
||
167 | do |
||
168 | { |
||
169 | /* The pointer px is set to starting address of the column being processed */ |
||
170 | px = pOut + i; |
||
171 | |||
172 | /* Initialize column loop counter */ |
||
173 | col = nColumns; |
||
174 | |||
175 | while (col > 0U) |
||
176 | { |
||
177 | /* Read and store the input element in the destination */ |
||
178 | *px = *pIn++; |
||
179 | |||
180 | /* Update the pointer px to point to the next row of the transposed matrix */ |
||
181 | px += nRows; |
||
182 | |||
183 | /* Decrement the column loop counter */ |
||
184 | col--; |
||
185 | } |
||
186 | |||
187 | #endif /* #if defined (ARM_MATH_DSP) */ |
||
188 | |||
189 | i++; |
||
190 | |||
191 | /* Decrement the row loop counter */ |
||
192 | row--; |
||
193 | |||
194 | } while (row > 0U); /* row loop end */ |
||
195 | |||
196 | /* Set status as ARM_MATH_SUCCESS */ |
||
197 | status = ARM_MATH_SUCCESS; |
||
198 | } |
||
199 | |||
200 | /* Return to application */ |
||
201 | return (status); |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * @} end of MatrixTrans group |
||
206 | */ |