Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
arm_mat_trans_f32.c
00001 /* ---------------------------------------------------------------------- 00002 * Project: CMSIS DSP Library 00003 * Title: arm_mat_trans_f32.c 00004 * Description: Floating-point matrix transpose 00005 * 00006 * $Date: 27. January 2017 00007 * $Revision: V.1.5.1 00008 * 00009 * Target Processor: Cortex-M cores 00010 * -------------------------------------------------------------------- */ 00011 /* 00012 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 00013 * 00014 * SPDX-License-Identifier: Apache-2.0 00015 * 00016 * Licensed under the Apache License, Version 2.0 (the License); you may 00017 * not use this file except in compliance with the License. 00018 * You may obtain a copy of the License at 00019 * 00020 * www.apache.org/licenses/LICENSE-2.0 00021 * 00022 * Unless required by applicable law or agreed to in writing, software 00023 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00024 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00025 * See the License for the specific language governing permissions and 00026 * limitations under the License. 00027 */ 00028 00029 /** 00030 * @defgroup MatrixTrans Matrix Transpose 00031 * 00032 * Tranposes a matrix. 00033 * Transposing an <code>M x N</code> matrix flips it around the center diagonal and results in an <code>N x M</code> matrix. 00034 * \image html MatrixTranspose.gif "Transpose of a 3 x 3 matrix" 00035 */ 00036 00037 #include "arm_math.h" 00038 00039 /** 00040 * @ingroup groupMatrix 00041 */ 00042 00043 /** 00044 * @addtogroup MatrixTrans 00045 * @{ 00046 */ 00047 00048 /** 00049 * @brief Floating-point matrix transpose. 00050 * @param[in] *pSrc points to the input matrix 00051 * @param[out] *pDst points to the output matrix 00052 * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> 00053 * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. 00054 */ 00055 00056 00057 arm_status arm_mat_trans_f32( 00058 const arm_matrix_instance_f32 * pSrc, 00059 arm_matrix_instance_f32 * pDst) 00060 { 00061 float32_t *pIn = pSrc->pData; /* input data matrix pointer */ 00062 float32_t *pOut = pDst->pData; /* output data matrix pointer */ 00063 float32_t *px; /* Temporary output data matrix pointer */ 00064 uint16_t nRows = pSrc->numRows; /* number of rows */ 00065 uint16_t nColumns = pSrc->numCols; /* number of columns */ 00066 00067 #if defined (ARM_MATH_DSP) 00068 00069 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00070 00071 uint16_t blkCnt, i = 0U, row = nRows; /* loop counters */ 00072 arm_status status; /* status of matrix transpose */ 00073 00074 00075 #ifdef ARM_MATH_MATRIX_CHECK 00076 00077 00078 /* Check for matrix mismatch condition */ 00079 if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows)) 00080 { 00081 /* Set status as ARM_MATH_SIZE_MISMATCH */ 00082 status = ARM_MATH_SIZE_MISMATCH; 00083 } 00084 else 00085 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */ 00086 00087 { 00088 /* Matrix transpose by exchanging the rows with columns */ 00089 /* row loop */ 00090 do 00091 { 00092 /* Loop Unrolling */ 00093 blkCnt = nColumns >> 2; 00094 00095 /* The pointer px is set to starting address of the column being processed */ 00096 px = pOut + i; 00097 00098 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00099 ** a second loop below computes the remaining 1 to 3 samples. */ 00100 while (blkCnt > 0U) /* column loop */ 00101 { 00102 /* Read and store the input element in the destination */ 00103 *px = *pIn++; 00104 00105 /* Update the pointer px to point to the next row of the transposed matrix */ 00106 px += nRows; 00107 00108 /* Read and store the input element in the destination */ 00109 *px = *pIn++; 00110 00111 /* Update the pointer px to point to the next row of the transposed matrix */ 00112 px += nRows; 00113 00114 /* Read and store the input element in the destination */ 00115 *px = *pIn++; 00116 00117 /* Update the pointer px to point to the next row of the transposed matrix */ 00118 px += nRows; 00119 00120 /* Read and store the input element in the destination */ 00121 *px = *pIn++; 00122 00123 /* Update the pointer px to point to the next row of the transposed matrix */ 00124 px += nRows; 00125 00126 /* Decrement the column loop counter */ 00127 blkCnt--; 00128 } 00129 00130 /* Perform matrix transpose for last 3 samples here. */ 00131 blkCnt = nColumns % 0x4U; 00132 00133 while (blkCnt > 0U) 00134 { 00135 /* Read and store the input element in the destination */ 00136 *px = *pIn++; 00137 00138 /* Update the pointer px to point to the next row of the transposed matrix */ 00139 px += nRows; 00140 00141 /* Decrement the column loop counter */ 00142 blkCnt--; 00143 } 00144 00145 #else 00146 00147 /* Run the below code for Cortex-M0 */ 00148 00149 uint16_t col, i = 0U, row = nRows; /* loop counters */ 00150 arm_status status; /* status of matrix transpose */ 00151 00152 00153 #ifdef ARM_MATH_MATRIX_CHECK 00154 00155 /* Check for matrix mismatch condition */ 00156 if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows)) 00157 { 00158 /* Set status as ARM_MATH_SIZE_MISMATCH */ 00159 status = ARM_MATH_SIZE_MISMATCH; 00160 } 00161 else 00162 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */ 00163 00164 { 00165 /* Matrix transpose by exchanging the rows with columns */ 00166 /* row loop */ 00167 do 00168 { 00169 /* The pointer px is set to starting address of the column being processed */ 00170 px = pOut + i; 00171 00172 /* Initialize column loop counter */ 00173 col = nColumns; 00174 00175 while (col > 0U) 00176 { 00177 /* Read and store the input element in the destination */ 00178 *px = *pIn++; 00179 00180 /* Update the pointer px to point to the next row of the transposed matrix */ 00181 px += nRows; 00182 00183 /* Decrement the column loop counter */ 00184 col--; 00185 } 00186 00187 #endif /* #if defined (ARM_MATH_DSP) */ 00188 00189 i++; 00190 00191 /* Decrement the row loop counter */ 00192 row--; 00193 00194 } while (row > 0U); /* row loop end */ 00195 00196 /* Set status as ARM_MATH_SUCCESS */ 00197 status = ARM_MATH_SUCCESS; 00198 } 00199 00200 /* Return to application */ 00201 return (status); 00202 } 00203 00204 /** 00205 * @} end of MatrixTrans group 00206 */ 00207
Generated on Tue Jul 12 2022 16:47:27 by
