aboutsummaryrefslogtreecommitdiff
path: root/nerv/lib/matrix/matrix.h
blob: 35b698fd84a5f74e157633b3d5fa93f7e4c1ba3b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef NERV_GENERIC_MATRIX_H
#define NERV_GENERIC_MATRIX_H

#include <stddef.h>

typedef struct Matrix {
    size_t stride;              /* size of a row */
    long ncol, nrow, nmax;    /* dimension of the matrix */
    int dim; /* dim == 2 for a matrix, dim == 1 for row vector */
    union {
        float *f;
        double *d;
        long *i;
    } data;                   /* pointer to actual storage */
    unsigned long offset;              /* the actual beginning of the matrix */
    long *data_ref;
} Matrix;

#define MATRIX_ROW_PTR(self, row) \
    (MATRIX_ELEM *)((char *)MATRIX_ELEM_PTR(self) + (row) * (self)->stride)
#define MATRIX_NEXT_ROW_PTR(self, stride) \
    (MATRIX_ELEM *)((char *)self + stride)
#endif