aboutsummaryrefslogtreecommitdiff
path: root/nerv/lib/matrix/generic/matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'nerv/lib/matrix/generic/matrix.c')
-rw-r--r--nerv/lib/matrix/generic/matrix.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/nerv/lib/matrix/generic/matrix.c b/nerv/lib/matrix/generic/matrix.c
index 4246751..998d107 100644
--- a/nerv/lib/matrix/generic/matrix.c
+++ b/nerv/lib/matrix/generic/matrix.c
@@ -4,12 +4,11 @@
/* FIXME: malloc failure detection */
void nerv_matrix_(data_free)(Matrix *self, Status *status) {
- if(*self->data_ref == 0) return; /* FIXME: repeat free memory */
assert(*self->data_ref > 0);
if (--(*self->data_ref) == 0)
{
/* free matrix data */
- MATRIX_DATA_FREE(MATRIX_ELEM_PTR(self), status);
+ MATRIX_DATA_FREE(MATRIX_ELEM_PTR_BASE(self), status);
free(self->data_ref);
free(self);
}
@@ -29,7 +28,7 @@ Matrix *nerv_matrix_(create)(long nrow, long ncol, Status *status) {
self->ncol = ncol;
self->nmax = self->nrow * self->ncol;
self->dim = 2;
- MATRIX_DATA_ALLOC(&MATRIX_ELEM_PTR(self), &self->stride,
+ MATRIX_DATA_ALLOC(&MATRIX_ELEM_PTR_BASE(self), &self->stride,
sizeof(MATRIX_ELEM) * self->ncol, self->nrow,
status);
if (status->err_code != NERV_NORMAL)
@@ -39,6 +38,7 @@ Matrix *nerv_matrix_(create)(long nrow, long ncol, Status *status) {
}
self->data_ref = (long *)malloc(sizeof(long));
*self->data_ref = 0;
+ self->offset = 0;
nerv_matrix_(data_retain)(self);
NERV_SET_STATUS(status, NERV_NORMAL, 0);
return self;
@@ -55,8 +55,9 @@ Matrix *nerv_matrix_(getrow)(Matrix *self, int row) {
prow->dim = 1;
prow->stride = self->stride;
prow->nmax = prow->ncol;
- MATRIX_ELEM_PTR(prow) = MATRIX_ROW_PTR(self, row);
+ prow->data = self->data;
prow->data_ref = self->data_ref;
+ prow->offset = row * self->stride;
nerv_matrix_(data_retain)(prow);
return prow;
}