maix::tensor

maix.tensor module

This is maix::tensor module of MaixCDK.
All of these elements are in namespace maix::tensor.

For MaixCDK developer: DO NOT edit this doc file manually, this doc is auto generated!

Module

No module

Enum

DType

Tensor data types

item describe
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

Tensor data type size in bytes

item description
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

Tensor data type name

item description
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

Tensor class

C++ defination code:

class Tensor

__init__

Tensor constructor

item description
type func
param shape: tensor shape, a int list
dtype: tensor element data type, see DType of this module
static False

C++ defination code:

Tensor(std::vector<int> shape, tensor::DType dtype)

Tensor

Tensor constructor

item description
type func
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
copy: defalt true to alloc new memory and copy from data.
static False

C++ defination code:

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

to_str

To string

item description
type func
static False

C++ defination code:

std::string to_str()

__str__

To string

item description
type func
static False

C++ defination code:

std::string __str__()

shape

get tensor shape

item description
type func
return tensor shape, a int list
static False

C++ defination code:

std::vector<int> shape()

expand_dims

expand tensor shape

item description
type func
param axis: axis to expand
static False

C++ defination code:

void expand_dims(int axis)

reshape

reshape tensor shape, if size not match, it will throw an err::Exception

item description
type func
param shape: new shape
static False

C++ defination code:

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

flatten

Flatten tensor shape to 1D

item description
type func
static False

C++ defination code:

void flatten()

dtype

get tensor data type

item description
type func
return tensor data type, see DType of this module
static False

C++ defination code:

tensor::DType  dtype()

to_float_list

get tensor data and return a list

item description
type func
return list type data
static False

C++ defination code:

std::valarray<float>* to_float_list()

argmax

argmax of tensor

item description
type func
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

argmax1, flattened data max index

item description
type func
return argmax result, int type
static False

C++ defination code:

int argmax1()

Tensors

Tensors

C++ defination code:

class Tensors

Tensors

Constructor of Tensors

item description
type func
static False

C++ defination code:

Tensors()

add_tensor

Add tensor

item description
type func
static False

C++ defination code:

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

rm_tensor

Remove tensor

item description
type func
static False

C++ defination code:

void rm_tensor(const std::string &key)

clear

Clear tensors

item description
type func
static False

C++ defination code:

void clear()

begin

Begin of tensors

item description
type func
static False

C++ defination code:

std::map<std::string, tensor::Tensor*>::iterator begin()

end

End of tensors

item description
type func
static False

C++ defination code:

std::map<std::string, tensor::Tensor*>::iterator end()

next

next

item description
type func
static False

C++ defination code:

std::map<std::string, tensor::Tensor*>::iterator next(std::map<std::string, tensor::Tensor*>::iterator it)

get_tensor

Get tensor by key

item description
type func
static False

C++ defination code:

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

[]

Operator []

item description
type func
static False

C++ defination code:

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

size

Size

item description
type func
static False

C++ defination code:

size_t size()

keys

Get names

item description
type func
static False

C++ defination code:

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

tensors

Tensors data, dict type

item description
type var
static False
readonly False

C++ defination code:

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