Skip to content

Commit b1ec365

Browse files
committed
Cythonize the shape property
1 parent 1fdb94b commit b1ec365

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

python/tvm/_ffi/_ctypes/ndarray.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ def _copyto(self, target_nd):
9090
check_call(_LIB.TVMArrayCopyFromTo(self.handle, target_nd.handle, None))
9191
return target_nd
9292

93+
@property
94+
def shape(self):
95+
"""Shape of this array"""
96+
return tuple(self.handle.contents.shape[i] for i in range(self.handle.contents.ndim))
97+
9398
def to_dlpack(self):
9499
"""Produce an array from a DLPack Tensor without copying memory
95100

python/tvm/_ffi/_cython/ndarray.pxi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ cdef class NDArrayBase:
6868
def __set__(self, value):
6969
self._set_handle(value)
7070

71+
@property
72+
def shape(self):
73+
"""Shape of this array"""
74+
return tuple(self.chandle.shape[i] for i in range(self.chandle.ndim))
75+
7176
def __init__(self, handle, is_view):
7277
self._set_handle(handle)
7378
self.c_is_view = is_view

python/tvm/_ffi/ndarray.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ def from_dlpack(dltensor):
157157

158158
class NDArrayBase(_NDArrayBase):
159159
"""A simple Device/CPU Array object in runtime."""
160-
@property
161-
def shape(self):
162-
"""Shape of this array"""
163-
return tuple(self.handle.contents.shape[i] for i in range(self.handle.contents.ndim))
164160

165161
@property
166162
def dtype(self):
@@ -240,6 +236,7 @@ def copyfrom(self, source_array):
240236
except:
241237
raise TypeError('array must be an array_like data,' +
242238
'type %s is not supported' % str(type(source_array)))
239+
243240
t = TVMType(self.dtype)
244241
shape, dtype = self.shape, self.dtype
245242
if t.lanes > 1:

0 commit comments

Comments
 (0)