arm_mat_cmplx_trans_f32.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. \image html MatrixTranspose.gif "Transpose of a 3 x 3 matrix"
  37. */
  38. /**
  39. @addtogroup MatrixComplexTrans
  40. @{
  41. */
  42. /**
  43. @brief Floating-point matrix transpose.
  44. @param[in] pSrc points to input matrix
  45. @param[out] pDst points to output matrix
  46. @return execution status
  47. - \ref ARM_MATH_SUCCESS : Operation successful
  48. - \ref ARM_MATH_SIZE_MISMATCH : Matrix size check failed
  49. */
  50. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  51. #include "arm_helium_utils.h"
  52. arm_status arm_mat_cmplx_trans_f32(const arm_matrix_instance_f32 * pSrc, arm_matrix_instance_f32 * pDst)
  53. {
  54. return arm_mat_cmplx_trans_32bit(pSrc->numRows, pSrc->numCols, (uint32_t *) pSrc->pData,
  55. pDst->numRows, pDst->numCols, (uint32_t *) pDst->pData);
  56. }
  57. #else
  58. arm_status arm_mat_cmplx_trans_f32(
  59. const arm_matrix_instance_f32 * pSrc,
  60. arm_matrix_instance_f32 * pDst)
  61. {
  62. float32_t *pIn = pSrc->pData; /* input data matrix pointer */
  63. float32_t *pOut = pDst->pData; /* output data matrix pointer */
  64. float32_t *px; /* Temporary output data matrix pointer */
  65. uint16_t nRows = pSrc->numRows; /* number of rows */
  66. uint16_t nColumns = pSrc->numCols; /* number of columns */
  67. uint16_t col, i = 0U, row = nRows; /* loop counters */
  68. arm_status status; /* status of matrix transpose */
  69. #ifdef ARM_MATH_MATRIX_CHECK
  70. /* Check for matrix mismatch condition */
  71. if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
  72. {
  73. /* Set status as ARM_MATH_SIZE_MISMATCH */
  74. status = ARM_MATH_SIZE_MISMATCH;
  75. }
  76. else
  77. #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
  78. {
  79. /* Matrix transpose by exchanging the rows with columns */
  80. /* row loop */
  81. do
  82. {
  83. /* The pointer px is set to starting address of the column being processed */
  84. px = pOut + CMPLX_DIM * i;
  85. /* Initialize column loop counter */
  86. col = nColumns;
  87. while (col > 0U)
  88. {
  89. /* Read and store the input element in the destination */
  90. px[0] = *pIn++; // real
  91. px[1] = *pIn++; // imag
  92. /* Update the pointer px to point to the next row of the transposed matrix */
  93. px += CMPLX_DIM * nRows;
  94. /* Decrement the column loop counter */
  95. col--;
  96. }
  97. i++;
  98. /* Decrement the row loop counter */
  99. row--;
  100. } while (row > 0U); /* row loop end */
  101. /* Set status as ARM_MATH_SUCCESS */
  102. status = ARM_MATH_SUCCESS;
  103. }
  104. /* Return to application */
  105. return (status);
  106. }
  107. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  108. /**
  109. * @} end of MatrixTrans group
  110. */