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 fd5d28f..004d9aa 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);
curandDestroyGenerator(*(self->curand_gen));
free(self->curand_gen);
free(self->data_ref);
@@ -31,7 +30,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)
@@ -46,6 +45,7 @@ Matrix *nerv_matrix_(create)(long nrow, long ncol, Status *status) {
curandCreateGenerator(self->curand_gen, CURAND_RNG_PSEUDO_DEFAULT);
curandSetPseudoRandomGeneratorSeed(*(self->curand_gen), time(NULL));
+ self->offset = 0;
nerv_matrix_(data_retain)(self);
NERV_SET_STATUS(status, NERV_NORMAL, 0);
return self;
@@ -62,9 +62,10 @@ 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->curand_gen = self->curand_gen;
+ prow->offset = row * self->stride;
nerv_matrix_(data_retain)(prow);
return prow;
}