File tree Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -58,14 +58,17 @@ func `@`*[T](arr: PyArray[T]): seq[T]{.inline.} = @(PyList[T](arr))
58
58
59
59
template itemsize*[T](arr: PyArray[T]): int = sizeof(T)
60
60
61
- func newPyArray*[T](len=0): PyArray[T] = PyArray[T] newPyList[T](len)
61
+ func newPyArray*[T](len=0): PyArray[T]{.inline.} = PyArray[T] newPyList[T](len)
62
62
func newPyArray*[T](x: Iterable[T]): PyArray[T]{.inline.} =
63
63
## unlike `array`_, when `x` is a literal, type conversion is always needed.
64
64
runnableExamples:
65
65
discard newPyArray[cint ]([1.cint , 2])
66
66
# or write: array('i', [1, 2])
67
67
PyArray[T] list[T](x)
68
68
69
+ func newPyArrayOfCap*[T](cap: int ): PyArray[T]{.inline.} =
70
+ PyArray[T] newPyListOfCap[T](cap)
71
+
69
72
func fromlist*[T](arr: var PyArray[T], ls: PyList[T]) =
70
73
arr.extend ls
71
74
Original file line number Diff line number Diff line change @@ -22,12 +22,11 @@ func repr*[T: set|string|openArray](self: PyList[T]): string =
22
22
system.repr self.data.toOpenArray(0, len(self)-1)
23
23
# `repr` defined for other elements' type is in about L160
24
24
25
- func newPyList*[T](s: seq [T]): PyList[T] =
26
- result = PyList[T](data: s)
27
- func newPyList*[T](a: openArray [T]): PyList[T] =
28
- result = PyList[T](data: @a)
29
- func newPyList*[T](len=0): PyList[T] = newPyList newSeq[T](len)
30
- func newPyListOfCap*[T](cap=0): PyList[T] = newPyList newSeqOfCap[T](cap)
25
+ func newPyList*[T](s: seq [T]): PyList[T]{.inline.} = PyList[T](data: s)
26
+ func newPyList*[T](a: openArray [T]): PyList[T]{.inline.} = PyList[T](data: @a)
27
+ func newPyList*[T](len=0): PyList[T]{.inline.} = newPyList newSeq[T](len)
28
+ func newPyListOfCap*[T](cap=0): PyList[T]{.inline.} =
29
+ newPyList newSeqOfCap[T](cap)
31
30
32
31
iterator items*[T](self: PyList[T]): T =
33
32
for i in self.data: yield i
You can’t perform that action at this time.
0 commit comments