1 |
|
|
/*************************************** |
2 |
|
|
Auteur : Pierre Aubert |
3 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
4 |
|
|
Licence : CeCILL-C |
5 |
|
|
****************************************/ |
6 |
|
|
|
7 |
|
|
#include "PTensor.h" |
8 |
|
|
|
9 |
|
|
|
10 |
|
|
///Test the PTensor |
11 |
|
1 |
void testPTensor(){ |
12 |
|
1 |
size_t nbRow(4lu), nbCol(5lu); |
13 |
✓ |
2 |
PTensor<float> alignedTensor; |
14 |
✓ |
1 |
alignedTensor.resize(AllocMode::ALIGNED, nbRow, nbCol); |
15 |
|
1 |
alignedTensor.fill(1.0f); |
16 |
|
|
|
17 |
✓ |
2 |
PTensor<int> alignedTensorOutput; |
18 |
✓ |
1 |
alignedTensorOutput.resize(AllocMode::ALIGNED, nbCol, nbRow); |
19 |
|
1 |
alignedTensorOutput.fill(1); |
20 |
|
|
|
21 |
✓ |
1 |
phoenix_transpose_copy(alignedTensorOutput.getData(), alignedTensor.getData(), |
22 |
|
|
nbRow, nbCol, alignedTensorOutput.getPadding(), true); |
23 |
✓ |
1 |
phoenix_transpose_copy(alignedTensorOutput.getData(), alignedTensor.getData(), |
24 |
|
|
nbCol, nbRow, alignedTensorOutput.getPadding(), false); |
25 |
|
|
|
26 |
✓ |
1 |
phoenix_transpose_block_copy(alignedTensorOutput.getData(), alignedTensor.getData(), |
27 |
|
|
nbRow, nbCol, 2lu, 2lu, alignedTensorOutput.getPadding(), true); |
28 |
✓ |
1 |
phoenix_transpose_block_copy(alignedTensorOutput.getData(), alignedTensor.getData(), |
29 |
|
|
nbCol, nbRow, 2lu, 2lu, alignedTensorOutput.getPadding(), false); |
30 |
|
|
|
31 |
✓✓ |
1 |
std::cout << "testPTensor : done" << std::endl; |
32 |
|
1 |
} |
33 |
|
|
|
34 |
|
|
///Test the transpose a PTensor by block |
35 |
|
|
/** @param nbRow : number of rows of the input matrix |
36 |
|
|
* @param nbCol : number of columns of the input matrix |
37 |
|
|
* @param nbBlockRow : number of rows of the blocks |
38 |
|
|
* @param nbBlockCol : number of colummns of the blocks |
39 |
|
|
* @return true on success, false otherwise |
40 |
|
|
*/ |
41 |
|
4 |
bool testTransposeBlock(size_t nbRow, size_t nbCol, size_t nbBlockRow, size_t nbBlockCol){ |
42 |
✓✓ |
8 |
PTensor<int> mat(AllocMode::ALIGNED, nbRow, nbCol), matT(AllocMode::ALIGNED, nbCol, nbRow); |
43 |
|
4 |
mat.fill(0); |
44 |
|
4 |
matT.fill(0); |
45 |
✓✓ |
36 |
for(size_t i(0lu); i < nbRow; ++i){ |
46 |
✓✓ |
281 |
for(size_t j(0lu); j < nbCol; ++j){ |
47 |
✓ |
249 |
mat.setValue(i, j, i*nbCol + j); |
48 |
|
|
} |
49 |
|
|
} |
50 |
✓✓✓ |
4 |
std::cout << "testTransposeBlock : mat = " << mat << std::endl; |
51 |
✓ |
4 |
phoenix_transpose_block(matT.getData(), mat.getData(), nbCol, nbRow, nbBlockCol, nbBlockRow, matT.getPadding()); |
52 |
✓✓✓ |
4 |
std::cout << "testTransposeBlock : matT = " << matT << std::endl; |
53 |
|
|
|
54 |
|
4 |
bool b(true); |
55 |
✓✓ |
36 |
for(size_t i(0lu); i < nbRow; ++i){ |
56 |
✓✓ |
281 |
for(size_t j(0lu); j < nbCol; ++j){ |
57 |
✓✓ |
249 |
b &= mat.getValue(i ,j) == matT.getValue(j, i); |
58 |
|
|
} |
59 |
|
|
} |
60 |
|
|
|
61 |
✓✓✓✓ ✓✓✓✓ ✓✓✓ |
4 |
std::cout << "testTransposeBlock ("<<nbRow<<", "<<nbCol<<", "<<nbBlockRow<<", "<<nbBlockCol<<") : b = " << b << std::endl; |
62 |
|
8 |
return b; |
63 |
|
|
} |
64 |
|
|
|
65 |
|
1 |
int main(int argc, char** argv){ |
66 |
|
1 |
bool b(true); |
67 |
|
1 |
testPTensor(); |
68 |
|
1 |
b &= testTransposeBlock(9lu, 9lu, 3lu, 3lu); |
69 |
|
1 |
b &= testTransposeBlock(9lu, 8lu, 3lu, 2lu); |
70 |
|
1 |
b &= testTransposeBlock(8lu, 9lu, 2lu, 3lu); |
71 |
|
1 |
b &= testTransposeBlock(6lu, 4lu, 3lu, 2lu); |
72 |
|
|
|
73 |
|
1 |
std::cout << "Final : b = " << b << std::endl; |
74 |
|
1 |
return b - 1; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
|