2016-11-12 21:53:11 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2016-11-13 11:06:05 +01:00
|
|
|
double *create_sa_matrix(int rows, int cols) {
|
|
|
|
double *x;
|
|
|
|
|
|
|
|
x = (double *) malloc(rows * cols * sizeof(double));
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroy_sa_matrix(double *x) {
|
|
|
|
free(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sa_index(int cols, int r, int c) {
|
|
|
|
return r * cols + c;
|
|
|
|
}
|
2016-11-12 21:53:11 +01:00
|
|
|
|
2016-11-13 13:11:24 +01:00
|
|
|
|
|
|
|
void print_sa_matrix(double *x, int rows, int cols) {
|
|
|
|
int i, j;
|
|
|
|
for (i = 0; i < rows; i++) {
|
|
|
|
for (j = 0; j < cols; j++) {
|
|
|
|
printf("%f\t", x[sa_index(cols, i, j)]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2016-11-12 21:53:11 +01:00
|
|
|
double **create_matrix(int rows, int cols) {
|
|
|
|
int i;
|
|
|
|
double **x;
|
|
|
|
|
|
|
|
x = (double **) malloc(rows * sizeof(double));
|
|
|
|
for (i = 0; i < rows; i++) {
|
|
|
|
x[i] = (double *) malloc(cols * sizeof(double));
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroy_matrix(double **x, int rows) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < rows; i++) {
|
|
|
|
free(x[i]);
|
|
|
|
}
|
|
|
|
free(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_matrix(double **x, int rows, int cols) {
|
|
|
|
int i, j;
|
|
|
|
for (i = 0; i < rows; i++) {
|
|
|
|
for (j = 0; j < cols; j++) {
|
|
|
|
printf("%f\t", x[i][j]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
}
|