From daf999ac9921e3aeb4a1879db8879c91264348c9 Mon Sep 17 00:00:00 2001 From: Clonkk Date: Mon, 17 Jun 2024 19:49:31 +0200 Subject: [PATCH] fix strides calc --- examples/numpyarrays/examply.nims | 1 + examples/numpyarrays/examply.py | 4 ++-- scinim/numpyarrays.nim | 4 ++-- tests/config.nims | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/numpyarrays/examply.nims b/examples/numpyarrays/examply.nims index 1fa247a..ae94235 100644 --- a/examples/numpyarrays/examply.nims +++ b/examples/numpyarrays/examply.nims @@ -5,3 +5,4 @@ --define:openmp --define:danger --app:lib +--define:useMalloc diff --git a/examples/numpyarrays/examply.py b/examples/numpyarrays/examply.py index 7784bd3..b9c4b2c 100644 --- a/examples/numpyarrays/examply.py +++ b/examples/numpyarrays/examply.py @@ -18,7 +18,7 @@ def fLoop(ar): def main(): print("Python => main()") MAX_X = int(3*1e3) - MAX_Y = int(3*1e3) + MAX_Y = int(4*1e4) MAX_LEN = int(MAX_X*MAX_Y) print("CPU COUNT=", multiprocessing.cpu_count()) print("MAX_X=", MAX_X) @@ -31,7 +31,7 @@ def main(): print(ar) print("1)") - timePythonLoop = False + timePythonLoop = True # Toggle - CAREFUL it takes a long time since Python is slow if timePythonLoop: start = timer() diff --git a/scinim/numpyarrays.nim b/scinim/numpyarrays.nim index 151b9b3..b2ddaec 100644 --- a/scinim/numpyarrays.nim +++ b/scinim/numpyarrays.nim @@ -136,8 +136,8 @@ proc initNumpyArray*[T](ar: sink PyObject): NumpyArray[T] = result.pyBuf = newSharedPtr(PyBuffer()) let f = sizeof(T) div sizeof(byte) - - result.strides = nimpy.getAttr(ar, "strides".cstring).to(seq[int]).map(x => (x div f)) + # result.strides = nimpy.getAttr(ar, "strides".cstring).to(seq[int]).map(x => (x div f)) + result.strides = ar.data.strides.to(seq[int]).map(x => (x div f)) ar.getBuffer(result.pyBuf.raw, PyBUF_WRITABLE or PyBUF_ND) let shapear = cast[ptr UncheckedArray[Py_ssize_t]](result.pyBuf.raw.shape) for i in 0 ..< result.pyBuf.raw.ndim: diff --git a/tests/config.nims b/tests/config.nims index 42c863d..77e6e34 100644 --- a/tests/config.nims +++ b/tests/config.nims @@ -1,3 +1,4 @@ switch("path", "$projectDir/../src") switch("threads", "on") switch("define", "openmp") +switch("define", "useMalloc")