maix.example
example module, this will be maix.example module in MaixPy, maix::example namespace in MaixCDK
You can use
maix.example
to access this module with MaixPy
This module is generated from MaixPy and MaixCDK
Module
No module
Enum
Kind
Example enum(not recommend! See Kind2)
item | describe |
---|---|
values | KIND_NONE: Kind none, value always 0, other enum value will auto increase KIND_DOG: Kind dog KIND_CAT: Kind cat, value is auto generated according to KING_DOG KIND_BIRD: KIND_MAX: Max Kind quantity You can get max Kind value by KIND_MAX - 1 |
C++ defination code:
enum Kind { KIND_NONE = 0, /** Kind none, value always 0, other enum value will auto increase */ KIND_DOG, /** Kind dog*/ KIND_CAT, // Kind cat, value is auto generated according to KING_DOG KIND_BIRD, KIND_MAX /* Max Kind quantity, You can get max Kind value by KIND_MAX - 1 */ }
Kind2
Example enum class(recommend!)
item | describe |
---|---|
values | NONE: Kind none, value always 0, other enum value will auto increase DOG: Kind dog CAT: Kind cat, value is auto generated according to KING_DOG BIRD: MAX: Max Kind quantity You can get max Kind value by KIND_MAX - 1 |
C++ defination code:
enum class Kind2 { NONE = 0, /** Kind none, value always 0, other enum value will auto increase */ DOG, /** Kind dog*/ CAT, // Kind cat, value is auto generated according to KING_DOG BIRD, MAX /* Max Kind quantity, You can get max Kind value by KIND_MAX - 1 */ }
Variable
var1
Example module variable
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 | "Sipeed" |
readonly | True |
C++ defination code:
const std::string var1 = "Sipeed"
list_var
Tensor data type size in bytes
item | description |
---|---|
attention | 1. DO NOT use C/C++ array directly for python API, the python wrapper not support it. Use std::vector instead. 2. 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 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9} |
readonly | True |
C++ defination code:
const std::vector<int> list_var = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
test_var
Example module variable test_var
item | description |
---|---|
attention | It's a copy of this variable in MaixPy, so if you change it in C++, it will not take effect in MaixPy. And change it in MaixPy will not take effect in C++ as well !!! If you want to use vars shared between C++ and MaixPy, you can create a class and use its member. |
value | 100 |
readonly | False |
C++ defination code:
int test_var = 100
Function
hello
def hello(name: str) -> str
say hello to someone
item | description |
---|---|
param | name: direction [in], name of someone, string type |
return | string type, content is hello + name |
C++ defination code:
std::string hello(std::string name)
change_arg_name
def change_arg_name(e: Example) -> Example
Change arg name example
item | description |
---|---|
param | e: Example object |
return | same as arg |
C++ defination code:
example::Example *change_arg_name(example::Example *e)
change_arg_name2
def change_arg_name2(e: Example) -> None
Change arg name example
item | description |
---|---|
param | e: Example object |
C++ defination code:
void change_arg_name2(example::Example &e)
Class
Test
Test class
C++ defination code:
class Test
__init__
def __init__(self) -> None
Test constructor
item | description |
---|---|
type | func |
static | False |
C++ defination code:
Test()
Example
Example class\nthis class will be export to MaixPy as maix.example.Example
C++ defination code:
class Example
__init__
def __init__(self, name: str, age: int = 18, pet: Kind = ...) -> None
Example constructor\nthis constructor will be export to MaixPy as maix.example.Example.init
item | description |
---|---|
type | func |
param | name: direction [in], name of Example, string type age: direction [in], age of Example, int type, default is 18, value range is [0, 100] |
attention | to make auto generate code work, param Kind should with full namespace name example::Kind instead of Kind ,namespace maix can be ignored. |
static | False |
C++ defination code:
Example(std::string &name, int age = 18, example::Kind pet = example::KIND_NONE)
get_name
def get_name(self) -> str
get name of Example\nyou can also get name by property name
.
item | description |
---|---|
type | func |
return | name of Example, string type |
static | False |
C++ defination code:
std::string get_name()
get_age
def get_age(self) -> int
get age of Example
item | description |
---|---|
type | func |
return | age of Example, int type, value range is [0, 100] |
static | False |
C++ defination code:
int get_age()
set_name
def set_name(self, name: str) -> None
set name of Example
item | description |
---|---|
type | func |
param | name: name of Example, string type |
static | False |
C++ defination code:
void set_name(std::string name)
set_age
def set_age(self, age: int) -> None
set age of Example
item | description |
---|---|
type | func |
param | age: age of Example, int type, value range is [0, 100] |
static | False |
C++ defination code:
void set_age(int age)
set_pet
def set_pet(self, pet: Kind) -> None
Example enum member
item | description |
---|---|
type | func |
attention | |
static | False |
C++ defination code:
void set_pet(example::Kind pet)
get_pet
def get_pet(self) -> Kind
Example enum member
item | description |
---|---|
type | func |
static | False |
C++ defination code:
example::Kind get_pet()
get_list
def get_list(self, in: list[int]) -> list[int]
get list example
item | description |
---|---|
type | func |
param | in: direction [in], input list, items are int type. In MaixPy, you can pass list or tuple to this API |
return | list, items are int type, content is [1, 2, 3] + in. Alloc item, del in MaixPy will auto free memory. |
static | False |
C++ defination code:
std::vector<int> *get_list(std::vector<int> in)
get_dict
def get_dict(self, in: dict[str, int]) -> dict[str, int]
Example dict API
item | description |
---|---|
type | func |
param | in: direction [in], input dict, key is string type, value is int type. In MaixPy, you can pass dict to this API |
return | dict, key is string type, value is int type, content is {"a": 1} + in In MaixPy, return type is dict object |
static | False |
C++ defination code:
std::map<std::string, int> get_dict(std::map<std::string, int> &in)
hello
def hello(name: str) -> str
say hello to someone
item | description |
---|---|
type | func |
param | name: name of someone, string type |
return | string type, content is Example::hello_str + name |
static | True |
C++ defination code:
static std::string hello(std::string name)
hello_bytes
def hello_bytes(*args, **kwargs)
param is bytes example
item | description |
---|---|
type | func |
param | bytes: bytes type param |
return | bytes type, return value is bytes changed value |
static | True |
C++ defination code:
static Bytes *hello_bytes(Bytes &bytes)
callback
def callback(cb: typing.Callable[[int, int], int]) -> int
Callback example
item | description |
---|---|
type | func |
param | cb: callback function, param is two int type, return is int type |
return | int type, return value is cb's return value. |
static | True |
C++ defination code:
static int callback(std::function<int(int, int)> cb)
callback2
def callback2(cb: typing.Callable[[list[int], int], int]) -> int
Callback example
item | description |
---|---|
type | func |
param | cb: callback function, param is a int list type and int type, return is int type |
return | int type, return value is cb's return value. |
static | True |
C++ defination code:
static int callback2(std::function<int(std::vector<int>, int)> cb)
hello_dict
def hello_dict(dict: dict[str, int]) -> dict[str, int]
Dict param example
item | description |
---|---|
type | func |
param | dict: dict type param, key is string type, value is int type |
static | True |
C++ defination code:
static std::map<std::string, int> *hello_dict(std::map<std::string, int> *dict)
name
name member of Example
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
std::string name
age
age member of Example, value range should be [0, 100]
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
int age
hello_str
hello_str member of Example, default value is "hello "
item | description |
---|---|
type | var |
static | True |
readonly | False |
C++ defination code:
static std::string hello_str
var1
Example module readonly variable
item | description |
---|---|
type | var |
static | False |
readonly | True |
C++ defination code:
const std::string var1 = "Example.var1"
var2
Example module readonly variable
item | description |
---|---|
type | var |
static | False |
readonly | True |
C++ defination code:
std::string var2 = "Example.var2"
dict_test
def dict_test() -> dict[str, Test]
dict_test, return dict type, and element is pointer type(alloc in C++).\nHere when the returned Tensor object will auto delete by Python GC.
item | description |
---|---|
type | func |
static | True |
C++ defination code:
static std::map<std::string, example::Test *> *dict_test()