The CMSIS DSP 5 library
Dependents: Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more
functions/MatrixFunctions/arm_mat_trans_f32.c@3:4098b9d3d571, 2018-06-21 (annotated)
- Committer:
- xorjoep
- Date:
- Thu Jun 21 11:56:27 2018 +0000
- Revision:
- 3:4098b9d3d571
- Parent:
- 1:24714b45cd1b
headers is a folder not a library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xorjoep | 1:24714b45cd1b | 1 | /* ---------------------------------------------------------------------- |
xorjoep | 1:24714b45cd1b | 2 | * Project: CMSIS DSP Library |
xorjoep | 1:24714b45cd1b | 3 | * Title: arm_mat_trans_f32.c |
xorjoep | 1:24714b45cd1b | 4 | * Description: Floating-point matrix transpose |
xorjoep | 1:24714b45cd1b | 5 | * |
xorjoep | 1:24714b45cd1b | 6 | * $Date: 27. January 2017 |
xorjoep | 1:24714b45cd1b | 7 | * $Revision: V.1.5.1 |
xorjoep | 1:24714b45cd1b | 8 | * |
xorjoep | 1:24714b45cd1b | 9 | * Target Processor: Cortex-M cores |
xorjoep | 1:24714b45cd1b | 10 | * -------------------------------------------------------------------- */ |
xorjoep | 1:24714b45cd1b | 11 | /* |
xorjoep | 1:24714b45cd1b | 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. |
xorjoep | 1:24714b45cd1b | 13 | * |
xorjoep | 1:24714b45cd1b | 14 | * SPDX-License-Identifier: Apache-2.0 |
xorjoep | 1:24714b45cd1b | 15 | * |
xorjoep | 1:24714b45cd1b | 16 | * Licensed under the Apache License, Version 2.0 (the License); you may |
xorjoep | 1:24714b45cd1b | 17 | * not use this file except in compliance with the License. |
xorjoep | 1:24714b45cd1b | 18 | * You may obtain a copy of the License at |
xorjoep | 1:24714b45cd1b | 19 | * |
xorjoep | 1:24714b45cd1b | 20 | * www.apache.org/licenses/LICENSE-2.0 |
xorjoep | 1:24714b45cd1b | 21 | * |
xorjoep | 1:24714b45cd1b | 22 | * Unless required by applicable law or agreed to in writing, software |
xorjoep | 1:24714b45cd1b | 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
xorjoep | 1:24714b45cd1b | 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
xorjoep | 1:24714b45cd1b | 25 | * See the License for the specific language governing permissions and |
xorjoep | 1:24714b45cd1b | 26 | * limitations under the License. |
xorjoep | 1:24714b45cd1b | 27 | */ |
xorjoep | 1:24714b45cd1b | 28 | |
xorjoep | 1:24714b45cd1b | 29 | /** |
xorjoep | 1:24714b45cd1b | 30 | * @defgroup MatrixTrans Matrix Transpose |
xorjoep | 1:24714b45cd1b | 31 | * |
xorjoep | 1:24714b45cd1b | 32 | * Tranposes a matrix. |
xorjoep | 1:24714b45cd1b | 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. |
xorjoep | 1:24714b45cd1b | 34 | * \image html MatrixTranspose.gif "Transpose of a 3 x 3 matrix" |
xorjoep | 1:24714b45cd1b | 35 | */ |
xorjoep | 1:24714b45cd1b | 36 | |
xorjoep | 1:24714b45cd1b | 37 | #include "arm_math.h" |
xorjoep | 1:24714b45cd1b | 38 | |
xorjoep | 1:24714b45cd1b | 39 | /** |
xorjoep | 1:24714b45cd1b | 40 | * @ingroup groupMatrix |
xorjoep | 1:24714b45cd1b | 41 | */ |
xorjoep | 1:24714b45cd1b | 42 | |
xorjoep | 1:24714b45cd1b | 43 | /** |
xorjoep | 1:24714b45cd1b | 44 | * @addtogroup MatrixTrans |
xorjoep | 1:24714b45cd1b | 45 | * @{ |
xorjoep | 1:24714b45cd1b | 46 | */ |
xorjoep | 1:24714b45cd1b | 47 | |
xorjoep | 1:24714b45cd1b | 48 | /** |
xorjoep | 1:24714b45cd1b | 49 | * @brief Floating-point matrix transpose. |
xorjoep | 1:24714b45cd1b | 50 | * @param[in] *pSrc points to the input matrix |
xorjoep | 1:24714b45cd1b | 51 | * @param[out] *pDst points to the output matrix |
xorjoep | 1:24714b45cd1b | 52 | * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> |
xorjoep | 1:24714b45cd1b | 53 | * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. |
xorjoep | 1:24714b45cd1b | 54 | */ |
xorjoep | 1:24714b45cd1b | 55 | |
xorjoep | 1:24714b45cd1b | 56 | |
xorjoep | 1:24714b45cd1b | 57 | arm_status arm_mat_trans_f32( |
xorjoep | 1:24714b45cd1b | 58 | const arm_matrix_instance_f32 * pSrc, |
xorjoep | 1:24714b45cd1b | 59 | arm_matrix_instance_f32 * pDst) |
xorjoep | 1:24714b45cd1b | 60 | { |
xorjoep | 1:24714b45cd1b | 61 | float32_t *pIn = pSrc->pData; /* input data matrix pointer */ |
xorjoep | 1:24714b45cd1b | 62 | float32_t *pOut = pDst->pData; /* output data matrix pointer */ |
xorjoep | 1:24714b45cd1b | 63 | float32_t *px; /* Temporary output data matrix pointer */ |
xorjoep | 1:24714b45cd1b | 64 | uint16_t nRows = pSrc->numRows; /* number of rows */ |
xorjoep | 1:24714b45cd1b | 65 | uint16_t nColumns = pSrc->numCols; /* number of columns */ |
xorjoep | 1:24714b45cd1b | 66 | |
xorjoep | 1:24714b45cd1b | 67 | #if defined (ARM_MATH_DSP) |
xorjoep | 1:24714b45cd1b | 68 | |
xorjoep | 1:24714b45cd1b | 69 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
xorjoep | 1:24714b45cd1b | 70 | |
xorjoep | 1:24714b45cd1b | 71 | uint16_t blkCnt, i = 0U, row = nRows; /* loop counters */ |
xorjoep | 1:24714b45cd1b | 72 | arm_status status; /* status of matrix transpose */ |
xorjoep | 1:24714b45cd1b | 73 | |
xorjoep | 1:24714b45cd1b | 74 | |
xorjoep | 1:24714b45cd1b | 75 | #ifdef ARM_MATH_MATRIX_CHECK |
xorjoep | 1:24714b45cd1b | 76 | |
xorjoep | 1:24714b45cd1b | 77 | |
xorjoep | 1:24714b45cd1b | 78 | /* Check for matrix mismatch condition */ |
xorjoep | 1:24714b45cd1b | 79 | if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows)) |
xorjoep | 1:24714b45cd1b | 80 | { |
xorjoep | 1:24714b45cd1b | 81 | /* Set status as ARM_MATH_SIZE_MISMATCH */ |
xorjoep | 1:24714b45cd1b | 82 | status = ARM_MATH_SIZE_MISMATCH; |
xorjoep | 1:24714b45cd1b | 83 | } |
xorjoep | 1:24714b45cd1b | 84 | else |
xorjoep | 1:24714b45cd1b | 85 | #endif /* #ifdef ARM_MATH_MATRIX_CHECK */ |
xorjoep | 1:24714b45cd1b | 86 | |
xorjoep | 1:24714b45cd1b | 87 | { |
xorjoep | 1:24714b45cd1b | 88 | /* Matrix transpose by exchanging the rows with columns */ |
xorjoep | 1:24714b45cd1b | 89 | /* row loop */ |
xorjoep | 1:24714b45cd1b | 90 | do |
xorjoep | 1:24714b45cd1b | 91 | { |
xorjoep | 1:24714b45cd1b | 92 | /* Loop Unrolling */ |
xorjoep | 1:24714b45cd1b | 93 | blkCnt = nColumns >> 2; |
xorjoep | 1:24714b45cd1b | 94 | |
xorjoep | 1:24714b45cd1b | 95 | /* The pointer px is set to starting address of the column being processed */ |
xorjoep | 1:24714b45cd1b | 96 | px = pOut + i; |
xorjoep | 1:24714b45cd1b | 97 | |
xorjoep | 1:24714b45cd1b | 98 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
xorjoep | 1:24714b45cd1b | 99 | ** a second loop below computes the remaining 1 to 3 samples. */ |
xorjoep | 1:24714b45cd1b | 100 | while (blkCnt > 0U) /* column loop */ |
xorjoep | 1:24714b45cd1b | 101 | { |
xorjoep | 1:24714b45cd1b | 102 | /* Read and store the input element in the destination */ |
xorjoep | 1:24714b45cd1b | 103 | *px = *pIn++; |
xorjoep | 1:24714b45cd1b | 104 | |
xorjoep | 1:24714b45cd1b | 105 | /* Update the pointer px to point to the next row of the transposed matrix */ |
xorjoep | 1:24714b45cd1b | 106 | px += nRows; |
xorjoep | 1:24714b45cd1b | 107 | |
xorjoep | 1:24714b45cd1b | 108 | /* Read and store the input element in the destination */ |
xorjoep | 1:24714b45cd1b | 109 | *px = *pIn++; |
xorjoep | 1:24714b45cd1b | 110 | |
xorjoep | 1:24714b45cd1b | 111 | /* Update the pointer px to point to the next row of the transposed matrix */ |
xorjoep | 1:24714b45cd1b | 112 | px += nRows; |
xorjoep | 1:24714b45cd1b | 113 | |
xorjoep | 1:24714b45cd1b | 114 | /* Read and store the input element in the destination */ |
xorjoep | 1:24714b45cd1b | 115 | *px = *pIn++; |
xorjoep | 1:24714b45cd1b | 116 | |
xorjoep | 1:24714b45cd1b | 117 | /* Update the pointer px to point to the next row of the transposed matrix */ |
xorjoep | 1:24714b45cd1b | 118 | px += nRows; |
xorjoep | 1:24714b45cd1b | 119 | |
xorjoep | 1:24714b45cd1b | 120 | /* Read and store the input element in the destination */ |
xorjoep | 1:24714b45cd1b | 121 | *px = *pIn++; |
xorjoep | 1:24714b45cd1b | 122 | |
xorjoep | 1:24714b45cd1b | 123 | /* Update the pointer px to point to the next row of the transposed matrix */ |
xorjoep | 1:24714b45cd1b | 124 | px += nRows; |
xorjoep | 1:24714b45cd1b | 125 | |
xorjoep | 1:24714b45cd1b | 126 | /* Decrement the column loop counter */ |
xorjoep | 1:24714b45cd1b | 127 | blkCnt--; |
xorjoep | 1:24714b45cd1b | 128 | } |
xorjoep | 1:24714b45cd1b | 129 | |
xorjoep | 1:24714b45cd1b | 130 | /* Perform matrix transpose for last 3 samples here. */ |
xorjoep | 1:24714b45cd1b | 131 | blkCnt = nColumns % 0x4U; |
xorjoep | 1:24714b45cd1b | 132 | |
xorjoep | 1:24714b45cd1b | 133 | while (blkCnt > 0U) |
xorjoep | 1:24714b45cd1b | 134 | { |
xorjoep | 1:24714b45cd1b | 135 | /* Read and store the input element in the destination */ |
xorjoep | 1:24714b45cd1b | 136 | *px = *pIn++; |
xorjoep | 1:24714b45cd1b | 137 | |
xorjoep | 1:24714b45cd1b | 138 | /* Update the pointer px to point to the next row of the transposed matrix */ |
xorjoep | 1:24714b45cd1b | 139 | px += nRows; |
xorjoep | 1:24714b45cd1b | 140 | |
xorjoep | 1:24714b45cd1b | 141 | /* Decrement the column loop counter */ |
xorjoep | 1:24714b45cd1b | 142 | blkCnt--; |
xorjoep | 1:24714b45cd1b | 143 | } |
xorjoep | 1:24714b45cd1b | 144 | |
xorjoep | 1:24714b45cd1b | 145 | #else |
xorjoep | 1:24714b45cd1b | 146 | |
xorjoep | 1:24714b45cd1b | 147 | /* Run the below code for Cortex-M0 */ |
xorjoep | 1:24714b45cd1b | 148 | |
xorjoep | 1:24714b45cd1b | 149 | uint16_t col, i = 0U, row = nRows; /* loop counters */ |
xorjoep | 1:24714b45cd1b | 150 | arm_status status; /* status of matrix transpose */ |
xorjoep | 1:24714b45cd1b | 151 | |
xorjoep | 1:24714b45cd1b | 152 | |
xorjoep | 1:24714b45cd1b | 153 | #ifdef ARM_MATH_MATRIX_CHECK |
xorjoep | 1:24714b45cd1b | 154 | |
xorjoep | 1:24714b45cd1b | 155 | /* Check for matrix mismatch condition */ |
xorjoep | 1:24714b45cd1b | 156 | if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows)) |
xorjoep | 1:24714b45cd1b | 157 | { |
xorjoep | 1:24714b45cd1b | 158 | /* Set status as ARM_MATH_SIZE_MISMATCH */ |
xorjoep | 1:24714b45cd1b | 159 | status = ARM_MATH_SIZE_MISMATCH; |
xorjoep | 1:24714b45cd1b | 160 | } |
xorjoep | 1:24714b45cd1b | 161 | else |
xorjoep | 1:24714b45cd1b | 162 | #endif /* #ifdef ARM_MATH_MATRIX_CHECK */ |
xorjoep | 1:24714b45cd1b | 163 | |
xorjoep | 1:24714b45cd1b | 164 | { |
xorjoep | 1:24714b45cd1b | 165 | /* Matrix transpose by exchanging the rows with columns */ |
xorjoep | 1:24714b45cd1b | 166 | /* row loop */ |
xorjoep | 1:24714b45cd1b | 167 | do |
xorjoep | 1:24714b45cd1b | 168 | { |
xorjoep | 1:24714b45cd1b | 169 | /* The pointer px is set to starting address of the column being processed */ |
xorjoep | 1:24714b45cd1b | 170 | px = pOut + i; |
xorjoep | 1:24714b45cd1b | 171 | |
xorjoep | 1:24714b45cd1b | 172 | /* Initialize column loop counter */ |
xorjoep | 1:24714b45cd1b | 173 | col = nColumns; |
xorjoep | 1:24714b45cd1b | 174 | |
xorjoep | 1:24714b45cd1b | 175 | while (col > 0U) |
xorjoep | 1:24714b45cd1b | 176 | { |
xorjoep | 1:24714b45cd1b | 177 | /* Read and store the input element in the destination */ |
xorjoep | 1:24714b45cd1b | 178 | *px = *pIn++; |
xorjoep | 1:24714b45cd1b | 179 | |
xorjoep | 1:24714b45cd1b | 180 | /* Update the pointer px to point to the next row of the transposed matrix */ |
xorjoep | 1:24714b45cd1b | 181 | px += nRows; |
xorjoep | 1:24714b45cd1b | 182 | |
xorjoep | 1:24714b45cd1b | 183 | /* Decrement the column loop counter */ |
xorjoep | 1:24714b45cd1b | 184 | col--; |
xorjoep | 1:24714b45cd1b | 185 | } |
xorjoep | 1:24714b45cd1b | 186 | |
xorjoep | 1:24714b45cd1b | 187 | #endif /* #if defined (ARM_MATH_DSP) */ |
xorjoep | 1:24714b45cd1b | 188 | |
xorjoep | 1:24714b45cd1b | 189 | i++; |
xorjoep | 1:24714b45cd1b | 190 | |
xorjoep | 1:24714b45cd1b | 191 | /* Decrement the row loop counter */ |
xorjoep | 1:24714b45cd1b | 192 | row--; |
xorjoep | 1:24714b45cd1b | 193 | |
xorjoep | 1:24714b45cd1b | 194 | } while (row > 0U); /* row loop end */ |
xorjoep | 1:24714b45cd1b | 195 | |
xorjoep | 1:24714b45cd1b | 196 | /* Set status as ARM_MATH_SUCCESS */ |
xorjoep | 1:24714b45cd1b | 197 | status = ARM_MATH_SUCCESS; |
xorjoep | 1:24714b45cd1b | 198 | } |
xorjoep | 1:24714b45cd1b | 199 | |
xorjoep | 1:24714b45cd1b | 200 | /* Return to application */ |
xorjoep | 1:24714b45cd1b | 201 | return (status); |
xorjoep | 1:24714b45cd1b | 202 | } |
xorjoep | 1:24714b45cd1b | 203 | |
xorjoep | 1:24714b45cd1b | 204 | /** |
xorjoep | 1:24714b45cd1b | 205 | * @} end of MatrixTrans group |
xorjoep | 1:24714b45cd1b | 206 | */ |