-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper_library.cpp
More file actions
216 lines (189 loc) · 5.2 KB
/
Copy pathhelper_library.cpp
File metadata and controls
216 lines (189 loc) · 5.2 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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include<stdio.h>
#include<math.h>
extern "C" {
void print(double Val) {
printf("Print: %g\n",Val);
}
void printi(int Val) {
printf("Print: %d\n",Val);
}
int lengthf(double* vec) {
long int N = lround(vec[0]);
return N;
}
int lengthi(int* vec) {
return vec[0];
}
double* makeVectorFloat(int length) {
return new double[length];
}
double* makeEnumeratedVectorFloat(double start, double step, double end) {
int i;
int count = floor((end-start)/step)+1;
double* vector = new double[count+1];
vector[0] = count;
for(i=0;i<count;i++) {
vector[i+1]=start+i*step;
}
return vector;
}
int* makeEnumeratedVectorInteger(int start, int step, int end) {
int i;
int count = floor((end-start)/step)+1;
int* vector = new int[count+1];
vector[0] = count;
for(i=0;i<count;i++) {
vector[i+1]=start+i*step;
}
return vector;
}
void addDoubleDoubleVectors(double** c_ptr, double* a, double* b) {
// the length of the array is stored in the first slot
long int N = lround(a[0]);
*c_ptr = new double[N+1];
double* c = *c_ptr;
c[0] = (double)N;
for(long int i=1;i<=N;i++) {
c[i] = a[i] + b[i];
}
}
void addIntDoubleVectors(double** c_ptr, int* a, double* b) {
// the length of the array is stored in the first slot
long int N = a[0];
*c_ptr = new double[N+1];
double* c = *c_ptr;
c[0] = (double)N;
for(long int i=1;i<=N;i++) {
c[i] = a[i] + b[i];
}
}
void addDoubleIntVectors(double** c_ptr, double* a, int* b) {
addIntDoubleVectors(c_ptr,b,a);
}
void addIntIntVectors(int** c_ptr, int* a, int* b) {
// the length of the array is stored in the first slot
int N = a[0];
*c_ptr = new int[N+1];
int* c = *c_ptr;
c[0] = N;
for(int i=1;i<=N;i++) {
c[i] = a[i] + b[i];
}
}
void aMinusBDoubleDoubleVectors(double** c_ptr, double* a, double* b) {
// the length of the array is stored in the first slot
long int N = lround(a[0]);
*c_ptr = new double[N+1];
double* c = *c_ptr;
c[0] = (double)N;
for(long int i=1;i<=N;i++) {
c[i] = a[i] - b[i];
}
}
void aMinusBIntDoubleVectors(double** c_ptr, int* a, double* b) {
// the length of the array is stored in the first slot
long int N = a[0];
*c_ptr = new double[N+1];
double* c = *c_ptr;
c[0] = (double)N;
for(long int i=1;i<=N;i++) {
c[i] = a[i] - b[i];
}
}
void aMinusBDoubleIntVectors(double** c_ptr, double* a, int* b) {
// the length of the array is stored in the first slot
long int N = a[0];
*c_ptr = new double[N+1];
double* c = *c_ptr;
c[0] = (double)N;
for(long int i=1;i<=N;i++) {
c[i] = a[i] - b[i];
}
}
void aMinusBIntIntVectors(int** c_ptr, int* a, int* b) {
// the length of the array is stored in the first slot
int N = a[0];
*c_ptr = new int[N+1];
int* c = *c_ptr;
c[0] = N;
for(int i=1;i<=N;i++) {
c[i] = a[i] - b[i];
}
}
void mulDoubleDoubleVectors(double** c_ptr, double* a, double* b) {
// the length of the array is stored in the first slot
long int N = lround(a[0]);
*c_ptr = new double[N+1];
double* c = *c_ptr;
c[0] = (double)N;
for(long int i=1;i<=N;i++) {
c[i] = a[i] * b[i];
}
}
void mulIntDoubleVectors(double** c_ptr, int* a, double* b) {
// the length of the array is stored in the first slot
long int N = a[0];
*c_ptr = new double[N+1];
double* c = *c_ptr;
c[0] = (double)N;
for(long int i=1;i<=N;i++) {
c[i] = a[i] * b[i];
}
}
void mulDoubleIntVectors(double** c_ptr, double* a, int* b) {
mulIntDoubleVectors(c_ptr,b,a);
}
void mulIntIntVectors(int** c_ptr, int* a, int* b) {
// the length of the array is stored in the first slot
int N = a[0];
*c_ptr = new int[N+1];
int* c = *c_ptr;
c[0] = N;
for(int i=1;i<=N;i++) {
c[i] = a[i] * b[i];
}
}
void aDivBDoubleDoubleVectors(double** c_ptr, double* a, double* b) {
// the length of the array is stored in the first slot
long int N = lround(a[0]);
*c_ptr = new double[N+1];
double* c = *c_ptr;
c[0] = (double)N;
for(long int i=1;i<=N;i++) {
c[i] = a[i] / b[i];
}
}
void aDivBIntDoubleVectors(double** c_ptr, int* a, double* b) {
// the length of the array is stored in the first slot
long int N = a[0];
*c_ptr = new double[N+1];
double* c = *c_ptr;
c[0] = (double)N;
for(long int i=1;i<=N;i++) {
c[i] = ((double)a[i]) / b[i];
}
}
void aDivBDoubleIntVectors(double** c_ptr, double* a, int* b) {
// the length of the array is stored in the first slot
long int N = a[0];
*c_ptr = new double[N+1];
double* c = *c_ptr;
c[0] = (double)N;
for(long int i=1;i<=N;i++) {
c[i] = a[i] / ((double)b[i]);
}
}
void aDivBIntIntVectors(double** c_ptr, int* a, int* b) {
// the length of the array is stored in the first slot
int N = a[0];
*c_ptr = new double[N+1];
double* c = *c_ptr;
c[0] = N;
for(int i=1;i<=N;i++) {
c[i] = ((double)a[i]) / ((double)b[i]);
}
}
void makeEmptyVector(int** a) {
*a = new int[10];
}
}