Skip to content

Commit

Permalink
fix strides calc
Browse files Browse the repository at this point in the history
  • Loading branch information
Clonkk committed Jun 17, 2024
1 parent 08fd0f1 commit daf999a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/numpyarrays/examply.nims
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
--define:openmp
--define:danger
--app:lib
--define:useMalloc
4 changes: 2 additions & 2 deletions examples/numpyarrays/examply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions scinim/numpyarrays.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/config.nims
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
switch("path", "$projectDir/../src")
switch("threads", "on")
switch("define", "openmp")
switch("define", "useMalloc")

0 comments on commit daf999a

Please sign in to comment.