arm_mat_cmplx_trans_f32.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. #include "dsp/matrix_functions.h"
  29. /**
  30. @ingroup groupMatrix
  31. */
  32. /**
  33. @defgroup MatrixComplexTrans Complex Matrix Transpose
  34. Tranposes a complex matrix.
  35. Transposing an <code>M x N</code> matrix flips it around the center diagonal and results in an <code>N x M</code> matrix.
  36. @par Transpose of a 3 x 3 matrix
  37. \f[
  38. \begin{pmatrix}
  39. a_{1,1} & a_{1,2} & a_{1,3} \\
  40. a_{2,1} & a_{2,2} & a_{2,3} \\
  41. a_{3,1} & a_{3,2} & a_{3,3} \\
  42. \end{pmatrix}^T
  43. =
  44. \begin{pmatrix}
  45. a_{1,1} & a_{2,1} & a_{3,1} \\
  46. a_{1,2} & a_{2,2} & a_{3,2} \\
  47. a_{1,3} & a_{2,3} & a_{3,3} \\
  48. \end{pmatrix}
  49. \f]
  50. */
  51. /**
  52. @addtogroup MatrixComplexTrans
  53. @{
  54. */
  55. /**
  56. @brief Floating-point matrix transpose.
  57. @param[in] pSrc points to input matrix
  58. @param[out] pDst points to output matrix
  59. @return execution status
  60. - \ref ARM_MATH_SUCCESS : Operation successful
  61. - \ref ARM_MATH_SIZE_MISMATCH : Matrix size check failed
  62. */
  63. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  64. #include "arm_helium_utils.h"
  65. arm_status arm_mat_cmplx_trans_f32(const arm_matrix_instance_f32 * pSrc, arm_matrix_instance_f32 * pDst)
  66. {
  67. return arm_mat_cmplx_trans_32bit(pSrc->numRows, pSrc->numCols, (uint32_t *) pSrc->pData,
  68. pDst->numRows, pDst->numCols, (uint32_t *) pDst->pData);
  69. }
  70. #else
  71. arm_status arm_mat_cmplx_trans_f32(
  72. const arm_matrix_instance_f32 * pSrc,
  73. arm_matrix_instance_f32 * pDst)
  74. {
  75. float32_t *pIn = pSrc->pData; /* input data matrix pointer */
  76. float32_t *pOut = pDst->pData; /* output data matrix pointer */
  77. float32_t *px; /* Temporary output data matrix pointer */
  78. uint16_t nRows = pSrc->numRows; /* number of rows */
  79. uint16_t nColumns = pSrc->numCols; /* number of columns */
  80. uint16_t col, i = 0U, row = nRows; /* loop counters */
  81. arm_status status; /* status of matrix transpose */
  82. #ifdef ARM_MATH_MATRIX_CHECK
  83. /* Check for matrix mismatch condition */
  84. if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
  85. {
  86. /* Set status as ARM_MATH_SIZE_MISMATCH */
  87. status = ARM_MATH_SIZE_MISMATCH;
  88. }
  89. else
  90. #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
  91. {
  92. /* Matrix transpose by exchanging the rows with columns */
  93. /* row loop */
  94. do
  95. {
  96. /* The pointer px is set to starting address of the column being processed */
  97. px = pOut + CMPLX_DIM * i;
  98. /* Initialize column loop counter */
  99. col = nColumns;
  100. while (col > 0U)
  101. {
  102. /* Read and store the input element in the destination */
  103. px[0] = *pIn++; // real
  104. px[1] = *pIn++; // imag
  105. /* Update the pointer px to point to the next row of the transposed matrix */
  106. px += CMPLX_DIM * nRows;
  107. /* Decrement the column loop counter */
  108. col--;
  109. }
  110. i++;
  111. /* Decrement the row loop counter */
  112. row--;
  113. } while (row > 0U); /* row loop end */
  114. /* Set status as ARM_MATH_SUCCESS */
  115. status = ARM_MATH_SUCCESS;
  116. }
  117. /* Return to application */
  118. return (status);
  119. }
  120. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  121. /**
  122. * @} end of MatrixTrans group
  123. */