Subversion Repositories LedShow

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/* ----------------------------------------------------------------------    
2
* Copyright (C) 2010-2014 ARM Limited. All rights reserved.    
3
*    
4
* $Date:        19. March 2015
5
* $Revision:    V.1.4.5
6
*    
7
* Project:          CMSIS DSP Library    
8
* Title:            arm_mat_trans_f32.c    
9
*    
10
* Description:  Floating-point matrix transpose.    
11
*    
12
* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
13
*  
14
* Redistribution and use in source and binary forms, with or without
15
* modification, are permitted provided that the following conditions
16
* are met:
17
*   - Redistributions of source code must retain the above copyright
18
*     notice, this list of conditions and the following disclaimer.
19
*   - Redistributions in binary form must reproduce the above copyright
20
*     notice, this list of conditions and the following disclaimer in
21
*     the documentation and/or other materials provided with the
22
*     distribution.
23
*   - Neither the name of ARM LIMITED nor the names of its contributors
24
*     may be used to endorse or promote products derived from this
25
*     software without specific prior written permission.
26
*
27
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
* POSSIBILITY OF SUCH DAMAGE.    
39
* -------------------------------------------------------------------- */
40
 
41
/**    
42
 * @defgroup MatrixTrans Matrix Transpose    
43
 *    
44
 * Tranposes a matrix.    
45
 * Transposing an <code>M x N</code> matrix flips it around the center diagonal and results in an <code>N x M</code> matrix.    
46
 * \image html MatrixTranspose.gif "Transpose of a 3 x 3 matrix"    
47
 */
48
 
49
#include "arm_math.h"
50
 
51
/**    
52
 * @ingroup groupMatrix    
53
 */
54
 
55
/**    
56
 * @addtogroup MatrixTrans    
57
 * @{    
58
 */
59
 
60
/**    
61
  * @brief Floating-point matrix transpose.    
62
  * @param[in]  *pSrc points to the input matrix    
63
  * @param[out] *pDst points to the output matrix    
64
  * @return     The function returns either  <code>ARM_MATH_SIZE_MISMATCH</code>    
65
  * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.    
66
  */
67
 
68
 
69
arm_status arm_mat_trans_f32(
70
  const arm_matrix_instance_f32 * pSrc,
71
  arm_matrix_instance_f32 * pDst)
72
{
73
  float32_t *pIn = pSrc->pData;                  /* input data matrix pointer */
74
  float32_t *pOut = pDst->pData;                 /* output data matrix pointer */
75
  float32_t *px;                                 /* Temporary output data matrix pointer */
76
  uint16_t nRows = pSrc->numRows;                /* number of rows */
77
  uint16_t nColumns = pSrc->numCols;             /* number of columns */
78
 
79
#ifndef ARM_MATH_CM0_FAMILY
80
 
81
  /* Run the below code for Cortex-M4 and Cortex-M3 */
82
 
83
  uint16_t blkCnt, i = 0u, row = nRows;          /* loop counters */
84
  arm_status status;                             /* status of matrix transpose  */
85
 
86
 
87
#ifdef ARM_MATH_MATRIX_CHECK
88
 
89
 
90
  /* Check for matrix mismatch condition */
91
  if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
92
  {
93
    /* Set status as ARM_MATH_SIZE_MISMATCH */
94
    status = ARM_MATH_SIZE_MISMATCH;
95
  }
96
  else
97
#endif /*    #ifdef ARM_MATH_MATRIX_CHECK    */
98
 
99
  {
100
    /* Matrix transpose by exchanging the rows with columns */
101
    /* row loop     */
102
    do
103
    {
104
      /* Loop Unrolling */
105
      blkCnt = nColumns >> 2;
106
 
107
      /* The pointer px is set to starting address of the column being processed */
108
      px = pOut + i;
109
 
110
      /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.    
111
       ** a second loop below computes the remaining 1 to 3 samples. */
112
      while(blkCnt > 0u)        /* column loop */
113
      {
114
        /* Read and store the input element in the destination */
115
        *px = *pIn++;
116
 
117
        /* Update the pointer px to point to the next row of the transposed matrix */
118
        px += nRows;
119
 
120
        /* Read and store the input element in the destination */
121
        *px = *pIn++;
122
 
123
        /* Update the pointer px to point to the next row of the transposed matrix */
124
        px += nRows;
125
 
126
        /* Read and store the input element in the destination */
127
        *px = *pIn++;
128
 
129
        /* Update the pointer px to point to the next row of the transposed matrix */
130
        px += nRows;
131
 
132
        /* Read and store the input element in the destination */
133
        *px = *pIn++;
134
 
135
        /* Update the pointer px to point to the next row of the transposed matrix */
136
        px += nRows;
137
 
138
        /* Decrement the column loop counter */
139
        blkCnt--;
140
      }
141
 
142
      /* Perform matrix transpose for last 3 samples here. */
143
      blkCnt = nColumns % 0x4u;
144
 
145
      while(blkCnt > 0u)
146
      {
147
        /* Read and store the input element in the destination */
148
        *px = *pIn++;
149
 
150
        /* Update the pointer px to point to the next row of the transposed matrix */
151
        px += nRows;
152
 
153
        /* Decrement the column loop counter */
154
        blkCnt--;
155
      }
156
 
157
#else
158
 
159
  /* Run the below code for Cortex-M0 */
160
 
161
  uint16_t col, i = 0u, row = nRows;             /* loop counters */
162
  arm_status status;                             /* status of matrix transpose  */
163
 
164
 
165
#ifdef ARM_MATH_MATRIX_CHECK
166
 
167
  /* Check for matrix mismatch condition */
168
  if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
169
  {
170
    /* Set status as ARM_MATH_SIZE_MISMATCH */
171
    status = ARM_MATH_SIZE_MISMATCH;
172
  }
173
  else
174
#endif /*      #ifdef ARM_MATH_MATRIX_CHECK    */
175
 
176
  {
177
    /* Matrix transpose by exchanging the rows with columns */
178
    /* row loop     */
179
    do
180
    {
181
      /* The pointer px is set to starting address of the column being processed */
182
      px = pOut + i;
183
 
184
      /* Initialize column loop counter */
185
      col = nColumns;
186
 
187
      while(col > 0u)
188
      {
189
        /* Read and store the input element in the destination */
190
        *px = *pIn++;
191
 
192
        /* Update the pointer px to point to the next row of the transposed matrix */
193
        px += nRows;
194
 
195
        /* Decrement the column loop counter */
196
        col--;
197
      }
198
 
199
#endif /* #ifndef ARM_MATH_CM0_FAMILY */
200
 
201
      i++;
202
 
203
      /* Decrement the row loop counter */
204
      row--;
205
 
206
    } while(row > 0u);          /* row loop end  */
207
 
208
    /* Set status as ARM_MATH_SUCCESS */
209
    status = ARM_MATH_SUCCESS;
210
  }
211
 
212
  /* Return to application */
213
  return (status);
214
}
215
 
216
/**    
217
 * @} end of MatrixTrans group    
218
 */