MCPcopy Create free account
hub / github.com/apache/tvm-ffi / Array

Class Array

python/tvm_ffi/container.py:171–268  ·  view source on GitHub ↗

Array container that represents a sequence of values in the FFI. :py:func:`tvm_ffi.convert` will map python list/tuple to this class. Parameters ---------- input_list The list of values to be stored in the array. Examples -------- .. code-block:: python

Source from the content-addressed store, hash-verified

169
170@register_object("ffi.Array")
171class Array(core.CContainerBase, core.Object, Sequence[T]):
172 """Array container that represents a sequence of values in the FFI.
173
174 :py:func:`tvm_ffi.convert` will map python list/tuple to this class.
175
176 Parameters
177 ----------
178 input_list
179 The list of values to be stored in the array.
180
181 Examples
182 --------
183 .. code-block:: python
184
185 import tvm_ffi
186
187 a = tvm_ffi.Array([1, 2, 3])
188 assert tuple(a) == (1, 2, 3)
189
190 Notes
191 -----
192 For structural equality and hashing, use ``structural_equal`` and ``structural_hash`` APIs.
193
194 See Also
195 --------
196 :py:func:`tvm_ffi.convert`
197
198 """
199
200 # tvm-ffi-stubgen(begin): object/ffi.Array
201 # fmt: off
202 # fmt: on
203 # tvm-ffi-stubgen(end)
204
205 def __deepcopy__(self, memo: Any = None) -> Any:
206 return _ffi_api.DeepCopy(self)
207
208 def __init__(self, input_list: Iterable[T]) -> None:
209 """Construct an Array from a Python sequence."""
210 self.__init_handle_by_constructor__(_ffi_api.Array, *input_list)
211
212 @overload
213 def __getitem__(self, idx: SupportsIndex, /) -> T: ...
214
215 @overload
216 def __getitem__(self, idx: slice, /) -> list[T]: ...
217
218 def __getitem__(self, idx: SupportsIndex | slice, /) -> T | list[T]: # ty: ignore[invalid-method-override]
219 """Return one element or a list for a slice."""
220 length = len(self)
221 result = getitem_helper(self, _ffi_api.ArrayGetItem, length, idx)
222 return result
223
224 def __len__(self) -> int:
225 """Return the number of elements in the array."""
226 return _ffi_api.ArraySize(self)
227
228 def __iter__(self) -> Iterator[T]:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected