Skip to content

Commit

Permalink
Merge pull request #388 from v923z/gc-fix
Browse files Browse the repository at this point in the history
fix garbage collection problem
  • Loading branch information
v923z authored May 13, 2021
2 parents 90824d2 + c08cba3 commit 05e2c57
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions code/ndarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ ndarray_obj_t *ndarray_new_ndarray(uint8_t ndim, size_t *shape, int32_t *strides
// we could, perhaps, leave this step out, and initialise the array only, when needed
memset(array, 0, len);
ndarray->array = array;
ndarray->origin = array;
return ndarray;
}

Expand Down Expand Up @@ -781,6 +782,7 @@ ndarray_obj_t *ndarray_new_view(ndarray_obj_t *source, uint8_t ndim, size_t *sha
uint8_t *pointer = (uint8_t *)source->array;
pointer += offset;
ndarray->array = pointer;
ndarray->origin = source->origin;
return ndarray;
}

Expand Down
1 change: 1 addition & 0 deletions code/ndarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typedef struct _ndarray_obj_t {
size_t shape[ULAB_MAX_DIMS];
int32_t strides[ULAB_MAX_DIMS];
void *array;
void *origin;
} ndarray_obj_t;

#if ULAB_HAS_DTYPE_OBJECT
Expand Down
2 changes: 1 addition & 1 deletion code/ulab.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "user/user.h"
#include "utils/utils.h"

#define ULAB_VERSION 2.7.0
#define ULAB_VERSION 2.7.1
#define xstr(s) str(s)
#define str(s) #s
#define ULAB_VERSION_STRING xstr(ULAB_VERSION) xstr(-) xstr(ULAB_MAX_DIMS) xstr(D)
Expand Down
6 changes: 6 additions & 0 deletions docs/ulab-change-log.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Thu, 13 May 2021

version 2.7.1

fix garbage collection problem

Wed, 5 May 2021

version 2.7.0
Expand Down
11 changes: 11 additions & 0 deletions tests/numpy/gc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from ulab import numpy as np
import gc

data = np.ones(1000)[6:-6]
print(sum(data))
print(data)

gc.collect()

print(sum(data))
print(data)
4 changes: 4 additions & 0 deletions tests/numpy/gc.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
988.0000000000001
array([1.0, 1.0, 1.0, ..., 1.0, 1.0, 1.0], dtype=float64)
988.0000000000001
array([1.0, 1.0, 1.0, ..., 1.0, 1.0, 1.0], dtype=float64)

0 comments on commit 05e2c57

Please sign in to comment.