<< pyWrap Python Interaction Mechanism in Scilab

Python Interaction Mechanism in Scilab >> Python Interaction Mechanism in Scilab > pyWrapAsRef

pyWrapAsRef

Wrap as reference (no copy) a Scilab variable

Calling Sequence

X = pyWrapAsRef(varName)

Arguments

varName

A string.

X

A Python object

Description

The function requires that Numpy wrapping is enabled with pyUseNumpy(%t).

Rows or matrices of doubles (not complexes), integers and booleans corresponding to the variable named varName are wrapped as a reference (i.e. no copy is made, the Numpy array is built with a pointer on the Scilab stack). Single data are not passed by references. Strings and complex data cannot be passed by reference since the Scilab corresponding structure is different from the Numpy one.

The main advantage is that is possible to avoid copy (so it is faster). A Scilab matrix can be allocated and fill on the Python side.

This function must be used very carefully. If the Scilab variable is cleared, the pointer becomes invalid.

Examples

pyImport numpy

pyUseScilabIndex(%t);
pyUseNumpy(%t);

a = zeros(3, 3);
A = pyWrapAsRef("a");

// We modify a and look at A
a(2, 2) = 1234;
A

// We modify A (in using the Scilab way to index)
A(3, 3) = 4321;
a

pyRemove numpy A

See Also

History

VersionDescription
5.4.0 Python module.

Report an issue
<< pyWrap Python Interaction Mechanism in Scilab