Skip to main content

Mojo struct

EngineNumpyView

A register_passable view of a numpy array.

Keeps its own reference to the NumPy PythonObject, so there is no need to manually keep the Python object alive after construction.

Implemented traits

AnyType, Copyable, Movable

Methods

__init__

__init__(inout self: Self, tensor: PythonObject)

Creates a non-owning view of given numpy array.

Args:

  • tensor (PythonObject): Numpy Array backing the view.

unsafe_ptr

unsafe_ptr(self: Self) -> UnsafePointer[NoneType, 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1]

Returns type erased pointer to the start of numpy array.

Returns:

UnsafePointer of given type.

dtype

dtype(self: Self) -> DType

Get DataType of the array backing the view.

Returns:

DataType of the array backing the view.

spec

spec(self: Self) -> TensorSpec

Returns the spec of numpy array backing the view.

Returns:

Numpy array spec in format of Stdlib TensorSpec.