-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·81 lines (57 loc) · 2.25 KB
/
main.cpp
File metadata and controls
executable file
·81 lines (57 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <cmath>
#include <iostream>
#include "athena/athena.h"
#include "hephaestus/hephaestus.cpp"
#include "hephaestus/Heph_Utils.h"
/**
* Use
#include "hephaestus.cpp"
#include "Heph_Utils.h"
* if you work in the same folder
*/
USE_HEPHAESTUS_CPP
using namespace std;
int main() {
LET A = TENSOR(bigreal)({1, 2, 3,
4, 5, 6,
7, 1, 0}, MATRIX_3X3) DONE
LET B = TENSOR(bigreal)({0, 1, 1,
1, 1, 1,
0, 1, 0}, MATRIX_3X3) DONE
LET A_einstein = __(A, "^alpha_beta") DONE
LET B_einstein = __(B, "^beta_gamma") DONE
LET AxB_matrix_prod = __m(A_einstein, B_einstein) DONE
LOG "Tensor matrix product:\n" DONE
FOREACH(i, indices, IN_TENSOR, AxB_matrix_prod.tensor,
LOG AxB_matrix_prod.at(indices) ALSO SPACE DONE
)
LOG_ALONE("")
// OR JUST DO
AxB_matrix_prod = __m(A, "^alpha_beta", B, "^beta_gamma") DONE
LOG "Same tensor matrix product:\n" DONE
FOREACH(i, indices, IN_TENSOR, AxB_matrix_prod.tensor,
LOG AxB_matrix_prod.at(indices) ALSO SPACE DONE
)
LOG_ALONE("")
// OR DEFINE A PRODUCT
DEF_TENSOR_PRODUCT_TO_INDEXED_TENSOR( matrixprod, bigreal, _x, "^alpha_beta", _y, "^beta_gamma", _x.dim() == 2 && _y.dim() == 2);
DEF_TENSOR_PRODUCT_TO_INDEXED_TENSOR( dblmatrixprod, long double, _x, "^alpha_beta", _y, "^beta_gamma", _x.dim() == 2 && _y.dim() == 2);
AxB_matrix_prod = DEFN_matrixprod(A, B) DONE
LOG "Same tensor matrix product but defined:\n" DONE
FOREACH(i, indices, IN_TENSOR, AxB_matrix_prod.tensor,
LOG AxB_matrix_prod.at(indices) ALSO SPACE DONE
)
LOG_ALONE("")
srand (time(NULL));
auto rnd = [] () -> long double {
return rand() % 10 + 1;
};
LET Rando = HTensor<long double>::random_distribution(rnd, HShape({6, 6}));
LET Rando1 = HTensor<long double>::random_distribution(rnd, HShape({6, 6}));
LET Rando_sq = DEFN_dblmatrixprod(Rando, Rando1) DONE
LOG "Random tensor with random values\n" DONE
FOREACH(i, indices, IN_TENSOR, Rando_sq.tensor,
LOG Rando_sq.at(indices) ALSO SPACE DONE
)
return 0;
}