arm_mat_trans_f64.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mat_trans_f64.c
  4. * Description: Floating-point matrix transpose
  5. *
  6. * $Date: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2017 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 MatrixTrans Matrix Transpose
  34. Tranposes a 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 MatrixTrans
  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. arm_status arm_mat_trans_f64(
  51. const arm_matrix_instance_f64 * pSrc,
  52. arm_matrix_instance_f64 * pDst)
  53. {
  54. float64_t *pIn = pSrc->pData; /* input data matrix pointer */
  55. float64_t *pOut = pDst->pData; /* output data matrix pointer */
  56. float64_t *px; /* Temporary output data matrix pointer */
  57. uint16_t nRows = pSrc->numRows; /* number of rows */
  58. uint16_t nCols = pSrc->numCols; /* number of columns */
  59. uint64_t col, row = nRows, i = 0U; /* Loop counters */
  60. arm_status status; /* status of matrix transpose */
  61. #ifdef ARM_MATH_MATRIX_CHECK
  62. /* Check for matrix mismatch condition */
  63. if ((pSrc->numRows != pDst->numCols) ||
  64. (pSrc->numCols != pDst->numRows) )
  65. {
  66. /* Set status as ARM_MATH_SIZE_MISMATCH */
  67. status = ARM_MATH_SIZE_MISMATCH;
  68. }
  69. else
  70. #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
  71. {
  72. /* Matrix transpose by exchanging the rows with columns */
  73. /* row loop */
  74. do
  75. {
  76. /* Pointer px is set to starting address of column being processed */
  77. px = pOut + i;
  78. #if defined (ARM_MATH_LOOPUNROLL)
  79. /* Loop unrolling: Compute 4 outputs at a time */
  80. col = nCols >> 2U;
  81. while (col > 0U) /* column loop */
  82. {
  83. /* Read and store input element in destination */
  84. *px = *pIn++;
  85. /* Update pointer px to point to next row of transposed matrix */
  86. px += nRows;
  87. *px = *pIn++;
  88. px += nRows;
  89. *px = *pIn++;
  90. px += nRows;
  91. *px = *pIn++;
  92. px += nRows;
  93. /* Decrement column loop counter */
  94. col--;
  95. }
  96. /* Loop unrolling: Compute remaining outputs */
  97. col = nCols % 0x4U;
  98. #else
  99. /* Initialize col with number of samples */
  100. col = nCols;
  101. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  102. while (col > 0U)
  103. {
  104. /* Read and store input element in destination */
  105. *px = *pIn++;
  106. /* Update pointer px to point to next row of transposed matrix */
  107. px += nRows;
  108. /* Decrement column loop counter */
  109. col--;
  110. }
  111. i++;
  112. /* Decrement row loop counter */
  113. row--;
  114. } while (row > 0U); /* row loop end */
  115. /* Set status as ARM_MATH_SUCCESS */
  116. status = ARM_MATH_SUCCESS;
  117. }
  118. /* Return to application */
  119. return (status);
  120. }
  121. /**
  122. * @} end of MatrixTrans group
  123. */