Set blackbox file handler to NULL after closing file
[inav.git] / lib / main / CMSIS / DSP / Source / MatrixFunctions / arm_mat_trans_f32.c
blob84165ce2effe793408940a1cb4c9552993a50d21
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_mat_trans_f32.c
4 * Description: Floating-point matrix transpose
6 * $Date: 27. January 2017
7 * $Revision: V.1.5.1
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.
29 /**
30 * @defgroup MatrixTrans Matrix Transpose
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"
37 #include "arm_math.h"
39 /**
40 * @ingroup groupMatrix
43 /**
44 * @addtogroup MatrixTrans
45 * @{
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.
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;
84 else
85 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
88 /* Matrix transpose by exchanging the rows with columns */
89 /* row loop */
92 /* Loop Unrolling */
93 blkCnt = nColumns >> 2;
95 /* The pointer px is set to starting address of the column being processed */
96 px = pOut + i;
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 */
103 *px = *pIn++;
105 /* Update the pointer px to point to the next row of the transposed matrix */
106 px += nRows;
108 /* Read and store the input element in the destination */
109 *px = *pIn++;
111 /* Update the pointer px to point to the next row of the transposed matrix */
112 px += nRows;
114 /* Read and store the input element in the destination */
115 *px = *pIn++;
117 /* Update the pointer px to point to the next row of the transposed matrix */
118 px += nRows;
120 /* Read and store the input element in the destination */
121 *px = *pIn++;
123 /* Update the pointer px to point to the next row of the transposed matrix */
124 px += nRows;
126 /* Decrement the column loop counter */
127 blkCnt--;
130 /* Perform matrix transpose for last 3 samples here. */
131 blkCnt = nColumns % 0x4U;
133 while (blkCnt > 0U)
135 /* Read and store the input element in the destination */
136 *px = *pIn++;
138 /* Update the pointer px to point to the next row of the transposed matrix */
139 px += nRows;
141 /* Decrement the column loop counter */
142 blkCnt--;
145 #else
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;
161 else
162 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
165 /* Matrix transpose by exchanging the rows with columns */
166 /* row loop */
169 /* The pointer px is set to starting address of the column being processed */
170 px = pOut + i;
172 /* Initialize column loop counter */
173 col = nColumns;
175 while (col > 0U)
177 /* Read and store the input element in the destination */
178 *px = *pIn++;
180 /* Update the pointer px to point to the next row of the transposed matrix */
181 px += nRows;
183 /* Decrement the column loop counter */
184 col--;
187 #endif /* #if defined (ARM_MATH_DSP) */
189 i++;
191 /* Decrement the row loop counter */
192 row--;
194 } while (row > 0U); /* row loop end */
196 /* Set status as ARM_MATH_SUCCESS */
197 status = ARM_MATH_SUCCESS;
200 /* Return to application */
201 return (status);
205 * @} end of MatrixTrans group