1 |
|
|
/*************************************** |
2 |
|
|
Auteur : Pierre Aubert |
3 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
4 |
|
|
Licence : CeCILL-C |
5 |
|
|
****************************************/ |
6 |
|
|
|
7 |
|
|
#include <string.h> |
8 |
|
|
#include "template_alloc.h" |
9 |
|
|
|
10 |
|
|
///Get the fulle size of the tensor |
11 |
|
|
/** @param tabDim : table of the dimensions of the tensor |
12 |
|
|
* @param nbDim : number of dimensions of the tensor |
13 |
|
|
* @return size of the tensor |
14 |
|
|
*/ |
15 |
|
3622 |
size_t tensor_getFullSize(const size_t * tabDim, size_t nbDim){ |
16 |
|
3622 |
size_t fullSize(1lu); |
17 |
✓✓ |
11506 |
for(size_t i(0lu); i < nbDim; ++i){ |
18 |
|
7884 |
fullSize *= tabDim[i]; |
19 |
|
|
} |
20 |
|
3622 |
return fullSize; |
21 |
|
|
} |
22 |
|
|
|
23 |
|
|
///Copy a shape of a tensor into an other |
24 |
|
|
/** @param[out] destTabDim : copy of the table of the size of each dimension |
25 |
|
|
* @param[out] destNbDim : copy of the number of dimensions |
26 |
|
|
* @param tabDim : table of the size of each dimension |
27 |
|
|
* @param nbDim : number of dimensions |
28 |
|
|
*/ |
29 |
|
3696 |
void tensor_copyShape(size_t *& destTabDim, size_t & destNbDim, const size_t * tabDim, size_t nbDim){ |
30 |
|
3696 |
destNbDim = nbDim; |
31 |
✗✓ |
3696 |
if(destTabDim != NULL){ |
32 |
|
|
delete [] destTabDim; |
33 |
|
|
destTabDim = NULL; |
34 |
|
|
} |
35 |
✓✗✗✓
|
3696 |
if(nbDim == 0lu || tabDim == NULL){ |
36 |
|
|
destTabDim = NULL; |
37 |
|
|
destNbDim = 0lu; |
38 |
|
|
return; |
39 |
|
|
} |
40 |
✓✗ |
3696 |
destTabDim = new size_t[nbDim]; |
41 |
|
3696 |
memcpy(destTabDim, tabDim, nbDim*sizeof(size_t)); |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
///Copy a shape of a tensor into an other |
45 |
|
|
/** @param[out] destTabDim : copy of the table of the size of each dimension |
46 |
|
|
* @param tabDim : table of the size of each dimension |
47 |
|
|
* @param nbDim : number of dimensions |
48 |
|
|
*/ |
49 |
|
|
void tensor_copyShape(size_t *& destTabDim, const size_t * tabDim, size_t nbDim){ |
50 |
|
|
if(destTabDim != NULL){ |
51 |
|
|
delete [] destTabDim; |
52 |
|
|
destTabDim = NULL; |
53 |
|
|
} |
54 |
|
|
if(nbDim == 0lu || tabDim == NULL){ |
55 |
|
|
destTabDim = NULL; |
56 |
|
|
return; |
57 |
|
|
} |
58 |
|
|
destTabDim = new size_t[nbDim]; |
59 |
|
|
memcpy(destTabDim, tabDim, nbDim*sizeof(size_t)); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
///Say if two shapes are the same or not |
63 |
|
|
/** @param tabDim1 : table of the size of each dimension |
64 |
|
|
* @param nbDim1 : number of dimensions |
65 |
|
|
* @param tabDim2 : table of the size of each dimension |
66 |
|
|
* @param nbDim2 : number of dimensions |
67 |
|
|
* @return true if the shapes are equal, false otherwise |
68 |
|
|
*/ |
69 |
|
3550 |
bool tensor_isSameShape(const size_t * tabDim1, size_t nbDim1, const size_t * tabDim2, size_t nbDim2){ |
70 |
✓✓✗✓
|
3550 |
if(tabDim1 == NULL && tabDim2 == NULL){return true;} |
71 |
✓✓✓✗ ✗✓ |
3550 |
if(nbDim1 != nbDim2 || tabDim1 == NULL || tabDim2 == NULL){return false;} |
72 |
|
2 |
bool isSameSize(true); |
73 |
|
2 |
size_t i(0lu); |
74 |
✓✗✓✓
|
6 |
while(isSameSize && i < nbDim1){ |
75 |
|
4 |
isSameSize = tabDim1[i] == tabDim2[i]; |
76 |
|
4 |
++i; |
77 |
|
|
} |
78 |
|
2 |
return isSameSize; |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
|