Skip to content

tenzr::python

Namespaces

Name
tenzr::python::dlpack_abi

Functions

Name
template <typename Nd >
Array
ArrayFromNdarray(const Nd & nd, std::optional< DType > dtype_opt)
Build a Tenzr Array from a contiguous buffer-protocol ndarray view.
bool TryMlDtypeFromName(const std::string & name, DType & out)
Array PyToArray(nb::handle obj, std::optional< DType > dtype_opt =std::nullopt)
nb::object ArrayToNdarray(Array a, nb::handle owner)
DType PromotedBinaryDtype(const Array & a, nb::handle other, bool force_float)
template <typename Op >
Array
BinaryArith(const Array & a, nb::handle other, bool force_float, Op op)
template <typename Cmp >
Array
BinaryCmp(const Array & a, nb::handle other, Cmp cmp)
Array ArrayGetitem(const Array & a_in, nb::handle key)
std::vector< int64_t > ParseAxes(nb::handle axis)
Array TryFromDlpackZerocopy(nb::handle obj)
nb::object ElementToPy(const void * p, DType dt)
Convert one host element to a Python scalar with exact dtype semantics.
nb::object BuildNestedList(const uint8_t * base, const StridedLayout & lay, const Array & a, size_t dim, int64_t offset, size_t elem)
nb::object ArrayTolist(const Array & a_orig)
NumPy-free tolist(): materialize, then build a nested Python list from host memory.
nb::object ArrayScalar(const Array & a)
Read the single element of a 1-element Array as a Python scalar (NumPy/JAX item() semantics; C++ cousin: Array::item()).
std::string ArrayRepr(const Array & a)
void BindDTypeEnum(nb::module_ & m)
void BindShape(nb::module_ & m)
void BindArrayModuleFunctions(nb::module_ & m)
void BindArray(nb::module_ & m)
Register the Array type and its NumPy-style API surface.
void BindTransforms(nb::module_ & m)
Register jit, grad, vjp, jvp, vmap, and related transforms.
void BindPlax(nb::module_ & m)
Register the plax primitive namespace.
void BindRandom(nb::module_ & m)
Register the random namespace and functional PRNG distributions.
void BindSharding(nb::module_ & m)
Register mesh, PartitionSpec, and NamedSharding bindings.
void BindScipy(nb::module_ & m)
Register the scipy special/linalg/optimize namespace.
void BindProfiler(nb::module_ & m)
Register the profiler and trace-export bindings.
nb::dlpack::dtype ToDlpackDtype(DType dt)
DType FromDlpackDtype(nb::dlpack::dtype d)
double ReadScalarAsDouble(const void * ptr, DType dt)
Read the first element of a host buffer as a double (used for the tracing scalar fast-path).
DType PythonScalarDtype(nb::handle obj)
Convert a Python scalar to the "weak" DType used for JAX-style promotion. Python bool -> Bool, int -> Int32, float -> kFloat32 (weak typing).
DType DefaultScalarDtype(nb::handle obj)
DType for a Python scalar when no explicit dtype is requested (NumPy-like defaults: bool->Bool, int->Int64, float->Float64).

Functions Documentation

function ArrayFromNdarray

template <typename Nd >
Array ArrayFromNdarray(
    const Nd & nd,
    std::optional< DType > dtype_opt
)

Build a Tenzr Array from a contiguous buffer-protocol ndarray view.

function TryMlDtypeFromName

bool TryMlDtypeFromName(
    const std::string & name,
    DType & out
)

function PyToArray

Array PyToArray(
    nb::handle obj,
    std::optional< DType > dtype_opt =std::nullopt
)

function ArrayToNdarray

nb::object ArrayToNdarray(
    Array a,
    nb::handle owner
)

function PromotedBinaryDtype

inline DType PromotedBinaryDtype(
    const Array & a,
    nb::handle other,
    bool force_float
)

function BinaryArith

template <typename Op >
inline Array BinaryArith(
    const Array & a,
    nb::handle other,
    bool force_float,
    Op op
)

function BinaryCmp

template <typename Cmp >
inline Array BinaryCmp(
    const Array & a,
    nb::handle other,
    Cmp cmp
)

function ArrayGetitem

inline Array ArrayGetitem(
    const Array & a_in,
    nb::handle key
)

function ParseAxes

inline std::vector< int64_t > ParseAxes(
    nb::handle axis
)

function TryFromDlpackZerocopy

Array TryFromDlpackZerocopy(
    nb::handle obj
)

Try to import a CPU DLPack producer with zero copy. Returns an undefined Array (is_defined() == false) when the tensor cannot be consumed zero-copy, so the caller can fall back to a NumPy-based copy.

function ElementToPy

inline nb::object ElementToPy(
    const void * p,
    DType dt
)

Convert one host element to a Python scalar with exact dtype semantics.

function BuildNestedList

nb::object BuildNestedList(
    const uint8_t * base,
    const StridedLayout & lay,
    const Array & a,
    size_t dim,
    int64_t offset,
    size_t elem
)

function ArrayTolist

nb::object ArrayTolist(
    const Array & a_orig
)

NumPy-free tolist(): materialize, then build a nested Python list from host memory.

function ArrayScalar

nb::object ArrayScalar(
    const Array & a
)

Read the single element of a 1-element Array as a Python scalar (NumPy/JAX item() semantics; C++ cousin: Array::item()).

function ArrayRepr

std::string ArrayRepr(
    const Array & a
)

function BindDTypeEnum

void BindDTypeEnum(
    nb::module_ & m
)

Parameters:

  • m Extension module to populate.

Register the Array type and its NumPy-style operations.

function BindShape

void BindShape(
    nb::module_ & m
)

function BindArrayModuleFunctions

void BindArrayModuleFunctions(
    nb::module_ & m
)

function BindArray

void BindArray(
    nb::module_ & m
)

Register the Array type and its NumPy-style API surface.

Parameters:

  • m Extension module to populate.

Register the Array type and its NumPy-style operations.

function BindTransforms

void BindTransforms(
    nb::module_ & m
)

Register jit, grad, vjp, jvp, vmap, and related transforms.

Parameters:

  • m Extension module to populate.

Register jit, grad, vjp, jvp, vmap, and related transforms.

function BindPlax

void BindPlax(
    nb::module_ & m
)

Register the plax primitive namespace.

Parameters:

  • m Extension module to populate.

Register the plax primitive namespace.

function BindRandom

void BindRandom(
    nb::module_ & m
)

Register the random namespace and functional PRNG distributions.

Parameters:

  • m Extension module to populate.

Register the random namespace and functional PRNG distributions.

function BindSharding

void BindSharding(
    nb::module_ & m
)

Register mesh, PartitionSpec, and NamedSharding bindings.

Parameters:

  • m Extension module to populate.

Register mesh, PartitionSpec, and NamedSharding bindings.

function BindScipy

void BindScipy(
    nb::module_ & m
)

Register the scipy special/linalg/optimize namespace.

Parameters:

  • m Extension module to populate.

Register the scipy special, linalg, and optimize namespaces.

function BindProfiler

void BindProfiler(
    nb::module_ & m
)

Register the profiler and trace-export bindings.

Parameters:

  • m Extension module to populate.

Register the profiler trace export API.

function ToDlpackDtype

inline nb::dlpack::dtype ToDlpackDtype(
    DType dt
)

function FromDlpackDtype

inline DType FromDlpackDtype(
    nb::dlpack::dtype d
)

function ReadScalarAsDouble

inline double ReadScalarAsDouble(
    const void * ptr,
    DType dt
)

Read the first element of a host buffer as a double (used for the tracing scalar fast-path).

function PythonScalarDtype

inline DType PythonScalarDtype(
    nb::handle obj
)

Convert a Python scalar to the "weak" DType used for JAX-style promotion. Python bool -> Bool, int -> Int32, float -> kFloat32 (weak typing).

function DefaultScalarDtype

inline DType DefaultScalarDtype(
    nb::handle obj
)

DType for a Python scalar when no explicit dtype is requested (NumPy-like defaults: bool->Bool, int->Int64, float->Float64).