1 |
|
|
/*************************************** |
2 |
|
|
Auteur : Pierre Aubert |
3 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
4 |
|
|
Licence : CeCILL-C |
5 |
|
|
****************************************/ |
6 |
|
|
|
7 |
|
|
#ifndef __PHOENIX_TRANSPOSE_IMPL_H__ |
8 |
|
|
#define __PHOENIX_TRANSPOSE_IMPL_H__ |
9 |
|
|
|
10 |
|
|
#include <algorithm> |
11 |
|
|
#include "phoenix_transpose.h" |
12 |
|
|
|
13 |
|
|
///Convert the table of U into a table of T |
14 |
|
|
/** @param[out] ptabOutput : output table |
15 |
|
|
* @param ptabInput : table of input |
16 |
|
|
* @param nbRowOut : number of rows of the output table |
17 |
|
|
* @param nbColOut : number of columns of the output table |
18 |
|
|
* @param outputPadding : padding of the output matrix |
19 |
|
|
* @param isTransposed : true if the input matrix of short has to be has to be transposed, false if not |
20 |
|
|
*/ |
21 |
|
|
template<typename T, typename U> |
22 |
|
2 |
void phoenix_transpose_copy(T* __restrict__ ptabOutput, const U * __restrict__ ptabInput, |
23 |
|
|
size_t nbRowOut, size_t nbColOut, size_t outputPadding, bool isTransposed) |
24 |
|
|
{ |
25 |
|
2 |
T* tabOutput = phoenix_assume_aligned(ptabOutput); |
26 |
|
2 |
const U* tabInput = phoenix_assume_aligned(ptabInput); |
27 |
|
2 |
size_t outputRowSize(nbColOut + outputPadding); |
28 |
✓✓ |
2 |
if(!isTransposed){ |
29 |
✓✓ |
6 |
for(size_t i(0lu); i < nbRowOut; ++i){ |
30 |
✓✓ |
25 |
for(size_t j(0lu); j < nbColOut; ++j){ |
31 |
|
20 |
tabOutput[i*outputRowSize + j] = tabInput[i*nbColOut + j]; |
32 |
|
|
} |
33 |
|
|
} |
34 |
|
|
}else{ //The bad slices rejection from real data have to be done here !!!!! |
35 |
✓✓ |
6 |
for(size_t j(0lu); j < nbColOut; ++j){ |
36 |
✓✓ |
25 |
for(size_t i(0lu); i < nbRowOut; ++i){ |
37 |
|
20 |
tabOutput[i*outputRowSize + j] = tabInput[i + j*nbRowOut]; |
38 |
|
|
} |
39 |
|
|
} |
40 |
|
|
} |
41 |
|
2 |
} |
42 |
|
|
|
43 |
|
|
///Transpose and convert the table of U into a table of T |
44 |
|
|
/** @param[out] ptabOutput : output table |
45 |
|
|
* @param ptabInput : table of input |
46 |
|
|
* @param nbRowOut : number of rows of the output table |
47 |
|
|
* @param nbColOut : number of columns of the output table |
48 |
|
|
* @param nbBlockRowOut : block size on slice |
49 |
|
|
* @param nbBlockColOut : block size on pixel |
50 |
|
|
* @param outputPadding : padding of the output matrix |
51 |
|
|
*/ |
52 |
|
|
template<typename T, typename U> |
53 |
|
10 |
void phoenix_transpose_block(T* __restrict__ ptabOutput, const U * __restrict__ ptabInput, |
54 |
|
|
size_t nbRowOut, size_t nbColOut, size_t nbBlockRowOut, size_t nbBlockColOut, size_t outputPadding) |
55 |
|
|
{ |
56 |
|
10 |
T* tabOutput = phoenix_assume_aligned(ptabOutput); |
57 |
|
10 |
const U* tabInput = phoenix_assume_aligned(ptabInput); |
58 |
|
|
// T* tabOutput = ptabOutput; |
59 |
|
|
// const U* tabInput = ptabInput; |
60 |
|
|
// std::cerr << "phoenix_transpose_block : nbRowOut = " << nbRowOut << ", nbColOut = " << nbColOut << ", nbBlockRowOut = " << nbBlockRowOut << ", nbBlockColOut = " << nbBlockColOut << std::endl; |
61 |
|
10 |
size_t outputRowSize(nbColOut + outputPadding); |
62 |
✓✓ |
40 |
for(size_t i(0lu); i < nbColOut; i += nbBlockColOut){ |
63 |
✓✓ |
116 |
for(size_t j(0lu); j < nbRowOut; j += nbBlockRowOut){ |
64 |
|
|
// transpose the block beginning at [i,j] |
65 |
✓✓ |
304 |
for(size_t k(i); k < std::min(i + nbBlockColOut, nbColOut); ++k){ |
66 |
✓✓ |
756 |
for(size_t l(j); l < std::min(j + nbBlockRowOut, nbRowOut); ++l){ |
67 |
|
|
// std::cerr << "phoenix_transpose_block : (i = "<<i<<", j = "<<j<<") tabOutput["<<k<<" + "<<l<<"*"<<outputRowSize<<"] = tabInput["<<l<<" + "<<k<<"*"<<nbRowOut<<"]" << std::endl; |
68 |
|
538 |
tabOutput[l*outputRowSize + k] = tabInput[k*nbRowOut + l]; |
69 |
|
|
} |
70 |
|
|
} |
71 |
|
|
} |
72 |
|
|
} |
73 |
|
10 |
} |
74 |
|
|
|
75 |
|
|
///Convert the table of U into a table of T |
76 |
|
|
/** @param[out] ptabOutput : output table |
77 |
|
|
* @param ptabInput : table of input |
78 |
|
|
* @param nbRowOut : number of rows of the output table |
79 |
|
|
* @param nbColOut : number of columns of the output table |
80 |
|
|
* @param nbBlockRowOut : block size on slice |
81 |
|
|
* @param nbBlockColOut : block size on pixel |
82 |
|
|
* @param outputPadding : padding of the output matrix |
83 |
|
|
* @param isTransposed : true if the input matrix of short has to be has to be transposed, false if not |
84 |
|
|
*/ |
85 |
|
|
template<typename T, typename U> |
86 |
|
2 |
void phoenix_transpose_block_copy(T* __restrict__ ptabOutput, const U * __restrict__ ptabInput, |
87 |
|
|
size_t nbRowOut, size_t nbColOut, size_t nbBlockRowOut, size_t nbBlockColOut, size_t outputPadding, bool isTransposed) |
88 |
|
|
{ |
89 |
✓✓ |
2 |
if(!isTransposed){ |
90 |
|
1 |
T* tabOutput = phoenix_assume_aligned(ptabOutput); |
91 |
|
1 |
const U* tabInput = phoenix_assume_aligned(ptabInput); |
92 |
|
1 |
size_t outputRowSize(nbColOut + outputPadding); |
93 |
✓✓ |
3 |
for(size_t i(0lu); i < nbColOut; i += nbBlockColOut){ |
94 |
✓✓ |
8 |
for(size_t j(0lu); j < nbRowOut; j += nbBlockRowOut){ |
95 |
|
|
// transpose the block beginning at [i,j] |
96 |
✓✓ |
18 |
for(size_t k(i); k < std::min(i + nbBlockColOut, nbColOut); ++k){ |
97 |
✓✓ |
32 |
for(size_t l(j); l < std::min(j + nbBlockRowOut, nbRowOut); ++l){ |
98 |
|
20 |
tabOutput[l*outputRowSize + k] = tabInput[l*nbRowOut + k]; |
99 |
|
|
} |
100 |
|
|
} |
101 |
|
|
} |
102 |
|
|
} |
103 |
|
|
}else{ //The bad slices rejection from real data have to be done here !!!!! |
104 |
|
1 |
phoenix_transpose_block(ptabOutput, ptabInput, |
105 |
|
|
nbRowOut, nbColOut, nbBlockRowOut, nbBlockColOut, outputPadding); |
106 |
|
|
} |
107 |
|
2 |
} |
108 |
|
|
|
109 |
|
|
|
110 |
|
|
#endif |
111 |
|
|
|