Used macro instead of function to get the array index
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../utils/utils.h"
|
||||
|
||||
double *create_sa_matrix(int rows, int cols) {
|
||||
double *x;
|
||||
@@ -12,16 +13,11 @@ void destroy_sa_matrix(double *x) {
|
||||
free(x);
|
||||
}
|
||||
|
||||
int sa_index(int cols, int r, int c) {
|
||||
return r * cols + c;
|
||||
}
|
||||
|
||||
|
||||
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("%f\t", x[IDX(cols, i, j)]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
@@ -9,6 +9,13 @@
|
||||
# define LOG(x) (void) 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Macro used with single array matrices to
|
||||
* get the array index given the number of columns,
|
||||
* the row index and the column index.
|
||||
*/
|
||||
#define IDX(cols, r, c) ((r) * (cols) + (c))
|
||||
|
||||
typedef struct borders {
|
||||
double north;
|
||||
double east;
|
||||
@@ -27,10 +34,6 @@ double *create_sa_matrix(int rows, int cols);
|
||||
*/
|
||||
void destroy_sa_matrix(double *x);
|
||||
|
||||
/*
|
||||
* Get the index for the single array matrix
|
||||
* that correspond to the given row and column.
|
||||
*/
|
||||
int sa_index(int cols, int r, int c);
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user