Python Nelson types

Managing Data between Python and Nelson.

Description

Managing data returned by Python functions:

Python return type, as shown in PythonCorresponding Nelson type (scalar)

bool

logical

complex

double (complex)

float

double

Convert Python types to Nelson type explicitly:

Python return types or protocols shown in NelsonNelson conversion methods

py.str

char, string

py.int

double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64

py.long

double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64

py.float

double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64

py.bool

double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64, logical

py.bytes

double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64, logical

py.bytearray

double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64, logical

py.array.array

double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64

py.memoryview

double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64

py.numpy.ndarray

double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64

py.list

double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64, logical, string, cell

py.tuple

double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64, logical, string, cell

py.dict

struct

Pass scalar Nelson type to Python:

Nelson scalar input argument typePython type

NaN

float("nan")

Inf

float("inf")

double (real)

py.float

single (real)

py.float

double (complex)

py.complex

single (complex)

py.complex

int8

py.int

uint8

py.int

int16

py.int

uint16

py.int

int32

py.int

uint32

py.int

int64

py.int

uint64

py.int

string scalar

py.str

char vector

py.str

logical

py.bool

struct

py.dict

Pass 1-by-N Vector Nelson type to Python:

Nelson 1-by-N Vector input argument typePython type

double (real)

array.array('d')

single (real)

array.array('f')

int8

array.array('b')

uint8

array.array('B')

int16

array.array('h')

uint16

array.array('H')

int32

array.array('i')

uint32

array.array('I')

int64

array.array('q')

uint64

array.array('Q')

double

memoryview

single

memoryview

logical

memoryview

char vector

str

string scalar

str

cell vector

tuple

Pass 2D Matrices and ND Arrays to Python:

The Python language offers a protocol for accessing memory buffers, akin to the data stored in Nelson arrays.

Nelson incorporates this Python buffer protocol for its arrays.

Example

R = pyrun('', "A", 'A', magic(3))
R.double()

See also

pyrun.

History

VersionDescription

1.4.0

initial version

Author

Allan CORNET

Last updated