Skip to content

utils

LiteRT Utility API

This module provides utility functions for working with the LiteRT schema.

Classes:

  • BuiltinOperatorMap

    Mapping of builtin operator codes to their names.

  • BuiltinOptionsMap

    Mapping of builtin options codes to their names.

Functions:

Copyright 2025 Ambiq. All Rights Reserved.

Classes

Functions

get_builtin_code

get_builtin_code(opcode: OperatorCodeT | OperatorCode) -> int

Return the builtin code of the given operator code.

This function serves as a workaround for older versions of LiteRT that do not support/populate the BuiltinCode property.

Parameters:

  • opcode

    (OperatorCodeT | OperatorCode) –

    Operator code.

Returns:

  • int ( int ) –

    Builtin code.

compute_tensor_bytes

compute_tensor_bytes(tensor: TensorT) -> int

Compute the number of bytes for a tensor based on its type and shape.

Parameters:

  • tensor

    (TensorT) –

    Tensor object.

Returns:

  • int ( int ) –

    Number of bytes for the tensor.

compute_tensor_ctype

compute_tensor_ctype(tensor: TensorT) -> str

Compute the C type for a tensor based on its type.

Parameters:

  • tensor

    (TensorT) –

    Tensor object.

Returns:

  • str ( str ) –

    C type of the tensor.

get_tensor_dtype

get_tensor_dtype(tensor: TensorT) -> np.dtype

Get the numpy dtype of a tensor.

Parameters:

  • tensor

    (TensorT) –

    Tensor object.

Returns:

  • dtype

    np.dtype: Numpy dtype of the tensor.

is_constant_tensor

is_constant_tensor(tensor: TensorT, model: ModelT, subgraph: SubGraphT) -> bool

Check if a tensor is a constant tensor in the LiteRT model.

Parameters:

  • tensor

    (TensorT) –

    Tensor object.

  • model

    (ModelT) –

    LiteRT model object.

  • subgraph

    (SubGraphT) –

    Subgraph object from LiteRT model.

Returns:

  • bool ( bool ) –

    True if the tensor is constant, False otherwise.

load_tensor_data

load_tensor_data(tensor: TensorT, model: ModelT) -> np.ndarray

Load the data of a tensor from the LiteRT model.

Parameters:

  • tensor

    (TensorT) –

    Tensor object.

  • model

    (ModelT) –

    LiteRT model object.

Returns:

  • ndarray

    np.ndarray: Numpy array containing the tensor data.