GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: TESTS/TEST_TENSOR_BLOCK_LINK/main.cpp Lines: 67 67 100.0 %
Date: 2026-03-27 22:08:32 Branches: 112 112 100.0 %

Line Branch Exec Source
1
/***************************************
2
	Auteur : Pierre Aubert
3
	Mail : pierre.aubert@lapp.in2p3.fr
4
	Licence : CeCILL-C
5
****************************************/
6
7
#include "PTensor.h"
8
9
///Test the PTensor
10
/**	@return true on success, false otherwise
11
*/
12
1
bool testPTensorBlockLink(){
13
1
	size_t nbRow(6lu), nbCol(12lu);
14
2
	PTensor<int> tensor;
15
1
	tensor.resize(AllocMode::NONE, nbRow, nbCol);
16
7
	for(size_t i(0lu); i < nbRow; ++i){
17
78
		for(size_t j(0lu); j < nbCol; ++j){
18
72
			tensor.setValue(i, j, (int)(i*nbCol + j));
19
		}
20
	}
21

1
	std::cout << "testPTensorBlockLink : input tensor : " << std::endl << tensor << std::endl;
22
1
	size_t blockSizeRow(2lu), blockSizeCol(3lu);
23
1
	std::vector<PBlock<int> > vecBlock;
24
1
	tensor.splitBlockLink(vecBlock, blockSizeRow, blockSizeCol, 0lu);
25
26

1
	std::cout << "testPTensorBlockLink : create " << vecBlock.size() << " blocks" << std::endl;
27
1
	bool b(true);
28
1
	b &= vecBlock.size() == 12lu;
29
30
1
	size_t blockIndex(0lu);
31
13
	for(std::vector<PBlock<int> >::iterator it(vecBlock.begin()); it != vecBlock.end(); ++it){
32
12
		PBlock<int> & block = *it;
33


12
		std::cout << "Block " << blockIndex << " ("<<block.getLocationRow()<<", "<<block.getLocationCol()<<") :" << std::endl << block << std::endl;
34
35
36
		for(size_t i(0lu); i < block.getFullNbRow(); ++i){
36
96
			for(size_t j(0lu); j < block.getNbCol(); ++j){
37
72
				b &= block.getValue(i, j) == (int)((i + block.getLocationRow())*nbCol + (j + block.getLocationCol()));
38
			}
39
		}
40

12
		std::cout << "testPTensorBlockLink : Block " << blockIndex << ", b = " << b << std::endl;
41
12
		++blockIndex;
42
	}
43
1
	std::cout << "testPTensorBlockLink : create block b = " << b << std::endl;
44
45
1
	tensor.fill(0);	//Let's clear the tensor and put the block back into it
46

1
	std::cout << "testPTensorBlockLink : merged tensor : " << std::endl << tensor << std::endl;
47
7
	for(size_t i(0lu); i < nbRow; ++i){
48
78
		for(size_t j(0lu); j < nbCol; ++j){
49
72
			b &= tensor.getValue(i, j) == 0;
50
		}
51
	}
52
1
	std::cout << "testPTensorBlockLink : merge block b = " << b << std::endl;
53
2
	return b;
54
}
55
56
///Test the PTensor
57
/**	@return true on success, false otherwise
58
*/
59
1
bool testPTensorBlockLinkNeighbourRing(){
60
1
	std::cout << "testPTensorBlockLinkNeighbourRing =================== START ====================" << std::endl;
61
1
	size_t nbRow(6lu), nbCol(10lu);
62
2
	PTensor<int> tensor;
63
1
	tensor.resize(AllocMode::NONE, nbRow, nbCol);
64
7
	for(size_t i(0lu); i < nbRow; ++i){
65
66
		for(size_t j(0lu); j < nbCol; ++j){
66
60
			tensor.setValue(i, j, (int)(i*nbCol + j));
67
		}
68
	}
69

1
	std::cout << "testPTensorBlockLinkNeighbourRing : input tensor : " << std::endl << tensor << std::endl;
70
1
	size_t blockSizeRow(4lu), blockSizeCol(6lu);
71
1
	std::vector<PBlock<int> > vecBlock;
72
1
	tensor.splitBlockLink(vecBlock, blockSizeRow, blockSizeCol, 1lu);
73
74

1
	std::cout << "testPTensorBlockLinkNeighbourRing : create " << vecBlock.size() << " blocks" << std::endl;
75
1
	bool b(true);
76
1
	b &= vecBlock.size() == 4lu;
77
78
1
	size_t blockIndex(0lu);
79
5
	for(std::vector<PBlock<int> >::iterator it(vecBlock.begin()); it != vecBlock.end(); ++it){
80
4
		PBlock<int> & block = *it;
81


4
		std::cout << "Block " << blockIndex << " ("<<block.getLocationRow()<<", "<<block.getLocationCol()<<") :" << std::endl << block << std::endl;
82
83
20
		for(size_t i(0lu); i < block.getFullNbRow(); ++i){
84
112
			for(size_t j(0lu); j < block.getNbCol(); ++j){
85
96
				b &= block.getValue(i, j) == (int)((i + block.getLocationRow())*nbCol + (j + block.getLocationCol()));
86
			}
87
		}
88

4
		std::cout << "testPTensorBlockLinkNeighbourRing : Block " << blockIndex << ", b = " << b << std::endl;
89
4
		++blockIndex;
90
	}
91
1
	std::cout << "testPTensorBlockLinkNeighbourRing : split block b = " << b << std::endl;
92
1
	tensor.fill(0);				//Let's reset the tensor to clearly see the padding of 0
93
94

1
	std::cout << "testPTensorBlockLink : merged tensor : " << std::endl << tensor << std::endl;
95
5
	for(size_t i(1lu); i < nbRow - 1lu; ++i){
96
36
		for(size_t j(1lu); j < nbCol - 1lu; ++j){
97
32
			b &= tensor.getValue(i, j) == 0;
98
		}
99
	}
100
1
	std::cout << "testPTensorBlockLinkNeighbourRing : merge block b = " << b << std::endl;
101
2
	return b;
102
}
103
104
1
int main(int argc, char** argv){
105
1
	bool b(testPTensorBlockLink());
106
1
	b &= testPTensorBlockLinkNeighbourRing();
107
1
	return b - 1;
108
}
109
110