Skip to content

Commit a6f937a

Browse files
authored
Merge pull request #5 from SciNim/feat_fix_deprecated_warning_dtype
Fix deprecated warning
2 parents f97967c + 2318a6c commit a6f937a

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

scinim.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Package
2-
version = "0.2.2"
2+
version = "0.2.3"
33
author = "SciNim"
44
description = "The core types and functions of the SciNim ecosystem"
55
license = "MIT"

scinim/numpyarrays.nim

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import arraymancer
99
import nimpy
1010
import nimpy/[raw_buffers, py_types]
1111

12+
{.push gcsafe.}
13+
1214
proc dtype*(t: PyObject): PyObject =
1315
nimpy.getAttr(t, "dtype")
1416

@@ -22,13 +24,13 @@ proc nptypes(name: string): PyObject =
2224

2325
template dtype*(T: typedesc[int8]): PyObject = nptypes("byte")
2426
template dtype*(T: typedesc[int16]): PyObject = nptypes("short")
25-
template dtype*(T: typedesc[int32]): PyObject = nptypes("intc")
26-
template dtype*(T: typedesc[int64]): PyObject = nptypes("int")
27+
template dtype*(T: typedesc[int32]): PyObject = nptypes("int32")
28+
template dtype*(T: typedesc[int64]): PyObject = nptypes("int64")
2729

2830
template dtype*(T: typedesc[uint8]): PyObject = nptypes("ubyte")
2931
template dtype*(T: typedesc[uint16]): PyObject = nptypes("ushort")
30-
template dtype*(T: typedesc[uint32]): PyObject = nptypes("uintc")
31-
template dtype*(T: typedesc[uint64]): PyObject = nptypes("uint")
32+
template dtype*(T: typedesc[uint32]): PyObject = nptypes("uint32")
33+
template dtype*(T: typedesc[uint64]): PyObject = nptypes("uint64")
3234

3335
proc dtype*(T: typedesc[int]): PyObject =
3436
when sizeof(T) == sizeof(int64):
@@ -99,19 +101,19 @@ proc release*(b: var PyBuffer) =
99101
proc `=destroy`*(b: var PyBuffer) =
100102
b.release()
101103

102-
proc raw(x: SharedPtr[PyBuffer]) : RawPyBuffer =
104+
proc raw(x: SharedPtr[PyBuffer]): RawPyBuffer =
103105
x[].raw
104106

105-
proc raw(x: var SharedPtr[PyBuffer]) : var RawPyBuffer =
107+
proc raw(x: var SharedPtr[PyBuffer]): var RawPyBuffer =
106108
x[].raw
107109

108-
proc obj*[T](x: NumpyArray[T]) : PyObject =
110+
proc obj*[T](x: NumpyArray[T]): PyObject =
109111
pyValueToNim(x.pyBuf.raw.obj, result)
110112

111-
proc dtype*[T](ar: NumpyArray[T]) : PyObject =
113+
proc dtype*[T](ar: NumpyArray[T]): PyObject =
112114
return dtype(T)
113115

114-
proc nimValueToPy*[T](v: NumpyArray[T]) : PPyObject {.inline.} =
116+
proc nimValueToPy*[T](v: NumpyArray[T]): PPyObject {.inline.} =
115117
nimValueToPy(v.obj())
116118

117119
proc pyprint*[T](ar: NumpyArray[T]) =
@@ -152,7 +154,7 @@ proc ndArrayFromPtr*[T](t: ptr T, shape: seq[int]): NumpyArray[T] =
152154
var bsizes = result.len*(sizeof(T) div sizeof(uint8))
153155
copyMem(addr(result.data[0]), t, bsizes)
154156

155-
proc toUnsafeView*[T](ndArray: NumpyArray[T]) : ptr UncheckedArray[T] =
157+
proc toUnsafeView*[T](ndArray: NumpyArray[T]): ptr UncheckedArray[T] =
156158
ndArray.data
157159

158160
# Arraymancer only
@@ -173,6 +175,7 @@ proc ndArrayFromTensor[T](t: Tensor[T]): NumpyArray[T] =
173175
# Reshape PyObject to Arraymancer Tensor
174176
let np = pyImport("numpy")
175177
var shape = t.shape.toSeq()
178+
var t = asContiguous(t, rowMajor)
176179
var buf = cast[ptr T](toUnsafeView(t))
177180
result = ndArrayFromPtr[T](buf, shape)
178181

@@ -181,3 +184,5 @@ proc toNdArray*[T](t: Tensor[T]): NumpyArray[T] =
181184

182185
proc pyValueToNim*[T](ar: NumpyArray[T], o: var Tensor[T]) {.inline.} =
183186
o = toTensor(ar)
187+
188+
{.pop.}

0 commit comments

Comments
 (0)