maix.tensor

maix.tensor module

You can use maix.tensor to access this module with MaixPy
This module is generated from MaixCDK

Module

No module

Enum

DType

item doc
brief Tensor data types
values UINT8:
INT8:
UINT16:
INT16:
UINT32:
INT32:
FLOAT16:
FLOAT32:
FLOAT64:
BOOL:
DTYPE_MAX:

C++ defination code:

enum DType
        {
            UINT8 = 0,
            INT8,
            UINT16,
            INT16,
            UINT32,
            INT32,
            FLOAT16,
            FLOAT32,
            FLOAT64,
            BOOL,
            // STRING,
            // OBJECT,
            DTYPE_MAX
        }

Variable

dtype_size

item doc
brief Tensor data type size in bytes
attention It's a copy of this variable in MaixPy,
so change it in C++ (e.g. update var in hello function) will not take effect the var inMaixPy.
So we add const for this var to avoid this mistake.
value {
1, // UINT8
1, // INT8
2, // UINT16
2, // INT16
4, // UINT32
4, // INT32
2, // FLOAT16
4, // FLOAT32
8, // FLOAT64
1, // BOOL
// 1, // STRING
// 1, // OBJECT
0
}
readonly True

C++ defination code:

const std::vector<int> dtype_size = {
            1, // UINT8
            1, // INT8
            2, // UINT16
            2, // INT16
            4, // UINT32
            4, // INT32
            2, // FLOAT16
            4, // FLOAT32
            8, // FLOAT64
            1, // BOOL
            // 1, // STRING
            // 1, // OBJECT
            0
        }

dtype_name

item doc
brief Tensor data type name
value {
"uint8",
"int8",
"uint16",
"int16",
"uint32",
"int32",
"float16",
"float32",
"float64",
"bool",
// "string",
// "object",
"invalid"
}
readonly True

C++ defination code:

const std::vector<std::string> dtype_name = {
            "uint8",
            "int8",
            "uint16",
            "int16",
            "uint32",
            "int32",
            "float16",
            "float32",
            "float64",
            "bool",
            // "string",
            // "object",
            "invalid"
        }

Function

Class

Tensor

item doc
brief Tensor class

C++ defination code:

class Tensor

__init__

item doc
type func
brief Tensor constructor
param shape: tensor shape, a int list
dtype: tensor element data type, see DType of this module
data: pointer to data content, can be nullptr, it will automatically alloc memory
and detroy it when this object is destroyed
static False

C++ defination code:

Tensor(std::vector<int> shape, tensor::DType dtype, void *data = nullptr)

to_str

item doc
type func
brief To string
static False

C++ defination code:

std::string to_str()

__str__

item doc
type func
brief To string
static False

C++ defination code:

std::string __str__()

shape

item doc
type func
brief get tensor shape
return tensor shape, a int list
static False

C++ defination code:

std::vector<int> shape()

expand_dims

item doc
type func
brief expand tensor shape
param axis: axis to expand
static False

C++ defination code:

void expand_dims(int axis)

reshape

item doc
type func
brief reshape tensor shape, if size not match, it will throw an err::Exception
param shape: new shape
static False

C++ defination code:

void reshape(std::vector<int> shape)

flatten

item doc
type func
brief Flatten tensor shape to 1D
static False

C++ defination code:

void flatten()

dtype

item doc
type func
brief get tensor data type
return tensor data type, see DType of this module
static False

C++ defination code:

tensor::DType  dtype()

to_float_list

item doc
type func
brief get tensor data and return a list
return list type data
static False

C++ defination code:

std::valarray<float>* to_float_list()

argmax

item doc
type func
brief argmax of tensor
param axis: By default, the index is into the flattened array, otherwise along the specified axis., wrong axis will throw an err::Exception
return argmax result, you need to delete it after use in C++.
static False

C++ defination code:

tensor::Tensor *argmax(int axis = 0xffff)

argmax1

item doc
type func
brief argmax1, flattened data max index
return argmax result, int type
static False

C++ defination code:

int argmax1()

Tensors

item doc
brief Tensors

C++ defination code:

class Tensors

__init__

def __init__(self) -> None
item doc
type func
brief Constructor of Tensors
static False

C++ defination code:

Tensors()

add_tensor

def add_tensor(self, key: str, tensor: Tensor, copy: bool, auto_delete: bool) -> None
item doc
type func
brief Add tensor
static False

C++ defination code:

void add_tensor(const std::string &key, tensor::Tensor *tensor, bool copy, bool auto_delete)

rm_tensor

def rm_tensor(self, key: str) -> None
item doc
type func
brief Remove tensor
static False

C++ defination code:

void rm_tensor(const std::string &key)

get_tensor

def get_tensor(self, key: str) -> Tensor
item doc
type func
brief Get tensor by key
static False

C++ defination code:

tensor::Tensor *get_tensor(const std::string &key)

__getitem__

def __getitem__(self, key: str) -> Tensor
item doc
type func
brief Operator []
static False

C++ defination code:

tensor::Tensor *operator[](const std::string &key)

__len__

def __len__(self) -> int
item doc
type func
brief Size
static False

C++ defination code:

size_t size()

get_names

def get_names(self) -> list[str]
item doc
type func
brief Get names
static False

C++ defination code:

std::vector<std::string> get_names()

tensors

item doc
type var
brief Tensors data, dict type
static False
readonly False

C++ defination code:

std::map<std::string, tensor::Tensor*> tensors