Skip to content

Commit ce62e84

Browse files
authored
Merge pull request #38 from McMasterU/matrix_multiplication
Matrix multiplication
2 parents 3d8be52 + 1ccc99a commit ce62e84

File tree

16 files changed

+445
-592
lines changed

16 files changed

+445
-592
lines changed

algorithms/ipopt/ipopt.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ extern const int var_size[NUM_VARIABLES];
2020
extern const int var_offset[NUM_VARIABLES];
2121
extern const int partial_derivative_offset[NUM_VARIABLES];
2222
extern const int objective_offset;
23-
extern double ptr[MEM_SIZE];
23+
24+
extern double ptr[MEMORY_NUM_DOUBLES];
25+
extern complex double ptr_c[MEMORY_NUM_COMPLEX_DOUBLES];
2426

2527
extern const int bound_pos[NUM_VARIABLES];
2628
extern double lower_bound[NUM_ACTUAL_VARIABLES];

algorithms/lbfgs-b/lbfgs-b.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdlib.h>
77
#include <stdbool.h>
88
#include <string.h>
9+
#include <complex.h>
910

1011
#define M 10
1112

@@ -18,7 +19,9 @@ extern const int var_size[NUM_VARIABLES];
1819
extern const int var_offset[NUM_VARIABLES];
1920
extern const int partial_derivative_offset[NUM_VARIABLES];
2021
extern const int objective_offset;
21-
extern double ptr[MEM_SIZE];
22+
23+
extern double ptr[MEMORY_NUM_DOUBLES];
24+
extern complex double ptr_c[MEMORY_NUM_COMPLEX_DOUBLES];
2225

2326
extern void assign_values();
2427
extern void evaluate_partial_derivatives_and_objective();

algorithms/lbfgs/lbfgs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ extern const int var_size[NUM_VARIABLES];
1414
extern const int var_offset[NUM_VARIABLES];
1515
extern const int partial_derivative_offset[NUM_VARIABLES];
1616
extern const int objective_offset;
17-
extern double ptr[MEM_SIZE];
17+
18+
extern double ptr[MEMORY_NUM_DOUBLES];
19+
extern complex double ptr_c[MEMORY_NUM_COMPLEX_DOUBLES];
1820

1921
extern void assign_values();
2022
extern void evaluate_partial_derivatives_and_objective();

embed/fftw.c

Lines changed: 13 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,72 +6,31 @@
66

77
#include <fftw3.h>
88

9-
// For simplicity, just use the dft for complex by adding 0 to the input complex part
10-
// We will use the special version for computing dft real later
11-
void dft_1d(int N, double *in, double *out, int forward_or_backward) {
12-
fftw_complex *aux;
13-
fftw_plan p;
14-
int i;
15-
aux = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
16-
p = fftw_plan_dft_1d(N, aux, aux, forward_or_backward, FFTW_MEASURE);
17-
for (i = 0; i < N; i++) {
18-
aux[i][0] = in[i];
19-
aux[i][1] = in[i + N];
20-
}
21-
fftw_execute(p); /* repeat as needed */
22-
23-
24-
if (forward_or_backward == FFTW_FORWARD) {
25-
for (i = 0; i < N; i++) {
26-
out[i] = aux[i][0];
27-
out[i + N] = aux[i][1];
28-
}
29-
} else {
9+
void dft_1d(int N, double complex *in, double complex *out, int forward_or_backward) {
10+
fftw_plan p = fftw_plan_dft_1d(N, in, out, forward_or_backward, FFTW_ESTIMATE);
11+
fftw_execute(p);
12+
if (forward_or_backward == FFTW_BACKWARD) {
13+
int i;
3014
for (i = 0; i < N; i++) {
31-
out[i] = aux[i][0] / N;
32-
out[i + N] = aux[i][1] / N;
15+
out[i] = out[i] / N;
3316
}
3417
}
3518

3619
fftw_destroy_plan(p);
37-
fftw_free(aux);
3820
}
3921

40-
// For simplicity, just use the dft for complex by adding 0 to the input complex part
41-
// We will use the special version for computing dft real later
42-
void dft_2d(int ROW, int COLUMN, double *in, double *out, int forward_or_backward) {
43-
fftw_complex *aux;
44-
fftw_plan p;
45-
int i, j;
22+
void dft_2d(int ROW, int COLUMN, double complex *in, double complex *out, int forward_or_backward) {
4623
int size = ROW * COLUMN;
47-
aux = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * size);
48-
p = fftw_plan_dft_2d(ROW, COLUMN, aux, aux, forward_or_backward, FFTW_MEASURE);
49-
for (i = 0; i < ROW; i++) {
50-
for (j = 0; j < COLUMN; j++) {
51-
aux[i * COLUMN + j][0] = in[i * COLUMN + j];
52-
aux[i * COLUMN + j][1] = in[i * COLUMN + j + size];
53-
}
54-
}
55-
fftw_execute(p); /* repeat as needed */
56-
57-
if (forward_or_backward == FFTW_FORWARD) {
58-
for (i = 0; i < ROW; i++) {
59-
for (j = 0; j < COLUMN; j++) {
60-
out[i * COLUMN + j] = aux[i * COLUMN + j][0];
61-
out[i * COLUMN + j + size] = aux[i * COLUMN + j][1];
62-
}
63-
}
64-
} else {
65-
for (i = 0; i < ROW; i++) {
66-
for (j = 0; j < COLUMN; j++) {
67-
out[i * COLUMN + j] = aux[i * COLUMN + j][0] / size;
68-
out[i * COLUMN + j + size] = aux[i * COLUMN + j][1] / size;
69-
}
24+
fftw_plan p = fftw_plan_dft_2d(ROW, COLUMN, in, out, forward_or_backward, FFTW_ESTIMATE);
25+
fftw_execute(p);
26+
if (forward_or_backward == FFTW_BACKWARD) {
27+
int i;
28+
for (i = 0; i < size; i++) {
29+
out[i] = out[i] / size;
7030
}
7131
}
7232

7333
fftw_destroy_plan(p);
74-
fftw_free(aux);
7534
}
7635

7736
/**

0 commit comments

Comments
 (0)