-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain_unit.C
170 lines (120 loc) · 5.54 KB
/
main_unit.C
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <iostream>
#include "metaphysicl/dualshadowvector.h"
#include "metaphysicl/dualshadowsparsevector.h"
#include "metaphysicl/dualshadowsparsestruct.h"
#include "metaphysicl/metaphysicl_asserts.h"
using namespace MetaPhysicL;
struct print_functor {
template <typename T>
void operator()(const T& i) const { std::cout << i << std::endl; }
};
int main(void)
{
const RawType<const ShadowNumber<double, long double> >::value_type testin = 0;
double testout = testin;
if (testout)
metaphysicl_error();
DualNumber<double, double> dndd = 1.;
2. * dndd;
typedef SetConstructor<IntType<1>, IntType<7>, IntType<9>, IntType<5>, IntType<7> >::type SType;
typedef SetConstructor<IntType<9>, IntType<7> >::type SType2;
typedef SetConstructor<IntType<10,SType>, IntType<11,SType2> >::type SSType;
typedef SetConstructor<IntType<1> >::type DumbType1;
typedef SetConstructor<IntType<1,DumbType1> >::type DumbType2;
ctassert<TypesEqual<SetOfSetsUnion<SSType>::type, SType>::value>::apply();
typedef SetConstructor<UnsignedIntType<2,double>, UnsignedIntType<9,double> >::type SType3;
typedef SetConstructor<IntType<3,double> >::type SType4;
typedef SetConstructor<UnsignedIntType<0>, UnsignedIntType<1> >::type IS2D;
std::cout << "sizeof(NullContainer) = " << sizeof(NullContainer<IntType<0> >) << std::endl;
std::cout << "sizeof(IntType) = " << sizeof(IntType<0>) << std::endl;
std::cout << "sizeof(IntDbl) = " << sizeof(IntType<0,double>) << std::endl;
std::cout << "sizeof(SType) = " << sizeof(SType) << std::endl;
std::cout << "sizeof(STypeDbl)= " << sizeof(SType::rebind<double>::other) << std::endl;
std::cout << "sizeof(SType2) = " << sizeof(SType2) << std::endl;
std::cout << "sizeof(SType3) = " << sizeof(SType3) << std::endl;
std::cout << "sizeof(SType4) = " << sizeof(SType4) << std::endl;
std::cout << "sizeof(DumbType2) = " << sizeof(DumbType2) << std::endl;
std::cout << "sizeof(IS2D) = " << sizeof(IS2D) << std::endl;
SType4 s4;
s4.element<IntType<3> >();
SType2 s;
s.element<IntType<9> >();
SparseNumberStruct<SType3> a3 = 2, b3 = 3, c3 = 0;
a3.get<9>() = 1;
b3.get<9>() = 5;
a3.get<2>() = 7;
std::cout << "a3Xb3 = " << a3.outerproduct(b3) << std::endl;
std::cout << "(a3Xb3)' = " << transpose(a3.outerproduct(b3)) << std::endl;
std::cout << "(a3Xb3)'[2] = " << (transpose(a3.outerproduct(b3))).get<2>() << std::endl;
std::cout << "(a3Xb3)'[2][2] = " << (transpose(a3.outerproduct(b3))).get<2>().get<2>() << std::endl;
SType::RuntimeForEach()(print_functor());
SparseNumberVector<double, SType2> a2(0), b2(0), c2(0);
SparseNumberVector<double, SType> a(0), b(0), c(0);
SparseNumberVector<SparseNumberVector<double, SType>, SType> T(0);
std::cout << "Found 8 = " << SType::Contains<IntType<8> >::value << std::endl;
a2.raw_at(1) = 2.;
a = a2;
T.raw_at(2).raw_at(2) = 5.;
b[5] = 3.;
c = 2*a;
c = a / 3 + b;
if (T)
std::cout << "T is non-zero" << std::endl;
std::cout << "c = " << c << std::endl;
std::cout << "a = " << a << std::endl;
std::cout << "T = " << T << std::endl;
std::cout << "c.dot(a) = " << c.dot(a) << std::endl;
std::cout << "T.dot(a) = " << T.dot(a) << std::endl;
const unsigned int NDIM = 2;
typedef double RawScalar;
typedef SparseNumberStructUnitVector<NDIM,0,RawScalar>::type XVector;
XVector xvec = SparseNumberStructUnitVector<NDIM,0,RawScalar>::value();
typedef SparseNumberStructFullVector<NDIM,RawScalar>::type FullVector;
/*
typedef SparseNumberVectorUnitVector<NDIM,0,RawScalar>::type XVector;
XVector xvec = SparseNumberVectorUnitVector<NDIM,0,RawScalar>::value();
typedef SparseNumberVectorFullVector<NDIM,RawScalar>::type FullVector;
*/
/*
typedef NumberVectorUnitVector<NDIM,0,RawScalar>::type XVector;
XVector xvec = NumberVectorUnitVector<NDIM,0,RawScalar>::value();
typedef NumberVector<NDIM,RawScalar> FullVector;
*/
typedef DualNumber<RawScalar, XVector> XFirstDerivType;
typedef DualNumber<RawScalar, FullVector> FullFirstDerivType;
typedef DualNumber<XFirstDerivType, XVector::rebind<XFirstDerivType>::other> XSecondDerivType;
typedef DualNumber<FullFirstDerivType, FullVector::rebind<FullFirstDerivType>::other> FullSecondDerivType;
typedef DualNumberConstructor<FullFirstDerivType, FullVector::rebind<FullFirstDerivType>::other> FSDTConstructor;
std::cout << "sizeof(FSDTC) = " << sizeof(FSDTConstructor) << std::endl;
FullFirstDerivType ffdt = XFirstDerivType(1.,xvec);
FullSecondDerivType fsdt = 0;
XSecondDerivType xsdt = XSecondDerivType(1.,xvec);
FullVector::rebind<FullFirstDerivType>::other first_deriv_vector;
fsdt = xsdt;
fsdt.derivatives() /= fsdt.value();
fsdt.value()/(fsdt.value()*fsdt.value());
ffdt = fsdt.value();
first_deriv_vector = fsdt.derivatives();
// ctprint<FullFirstDerivType,FullVector::rebind<FullFirstDerivType>::other>::apply();
ffdt * first_deriv_vector;
// ffdt * fsdt.derivatives();
// fsdt.value()/(fsdt.value()*fsdt.value()) * fsdt.derivatives();
// fsdt.derivatives() -= fsdt.value()/(fsdt.value()*fsdt.value()) * fsdt.derivatives();
fsdt.value() /= fsdt.value();
fsdt / fsdt;
long int divl = 1;
long long int divll = 1;
unsigned long int udivl = 1;
unsigned long long int udivll = 1;
std::size_t sdiv = 1;
std::ptrdiff_t pdiv = 1;
FullFirstDerivType dbl = 2.0;
FullFirstDerivType r1 = dbl/divl;
FullFirstDerivType r2 = dbl/divll;
FullFirstDerivType r3 = dbl/udivl;
FullFirstDerivType r4 = dbl/udivll;
FullFirstDerivType r5 = dbl/sdiv;
FullFirstDerivType r6 = dbl/pdiv;
r1 + r2 + r3 + r4 + r5 + r6;
return 0;
}