Edit this page on our live server and create a PR by running command !create-pr in the console panel

Working with Scilab

  • Difficulty level: easy
  • Time need to lean: 15 minutes or less
  • Key points:
    • There are intuitive corresponding data types between most Python (SoS) and Scilab datatypes

Overview

The convertion of datatype from SoS to Scilab is as followings:

Python condition Scilab
None Nan
boolean boolean
integer constant
float constant
complex complex
str string
char string
Sequence (list, tuple, ...) homogenous type, all numeric constant
Sequence (list, tuple, ...) homogenous type, all char string
Sequence (list, tuple, ...) multiple types list
numpy.ndarray constant
numpy.matrix constant

Python objects in other datatypes are transferred as string "Unsupported datatype".

The convertion of datatype from Scilab to SoS is as followings:

Scilab length (n) Python
Nan None
boolean 1 boolean
integer 1 integer
constant 1 double
string 1 string
complex 1 complex
boolean n > 1 list
integer n > 1 list
complex n > 1 list
constant n > 1 list
string n > 1 list
struct n > 0 numpy.ndarray
matrix n > 0 numpy.array
cell n > 0 numpy.ndarray

Simple data types

Most simple Python data types can be converted to Scilab types easily.

In [16]:
In [17]:
> null_var:
  null_var  = 

   Nan

> int_var:
  int_var  = 

   123.

> float_var:
  float_var  = 

   3.1415925

> logic_var:
  logic_var  = 

  T

> char_var:
  char_var  = 

  "1"23"

> comp_var:
  comp_var  = 

   1. + 2.i

In [18]:
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
> null_var: NoneType
None
> int_var: int
123
> float_var: float
3.1415925
> logic_var: bool
True
> char_var: str of length 4
'1"23'
> comp_var: complex
(1+2j)

However, because Python allows integers of arbitrary precision which is not supported by Scilab, large integers would be presented in Scilab as float point numbers, which might not be able to keep the precision of the original number.

For example, if we put a large integer with 18 significant digits to Scilab

In [1]:
/usr/bin/chcon: failed to change context of '/share/apps/scilab-6.1.1/bin/scilab-bin' to ‘unconfined_u:object_r:execmem_exec_t:s0’: Operation not permitted
/usr/bin/chcon: failed to change context of '/share/apps/scilab-6.1.1/bin/scilab-cli-bin' to ‘unconfined_u:object_r:execmem_exec_t:s0’: Operation not permitted

The integer would be considered a double-precision float number and be presented with a D

In [5]:
  large_int  = 

   1.235D+17

This is not a problem with SoS because you would get the same result if you enter this number in Scilab

In [2]:
  ans  =

   1.235D+17

Consequently, if you send large_int back to SoS, the number would be different

In [9]:
Out[9]:
123456789123456784

Array and matrix

The one-dimension (vector) data is converted from SoS to Scilab as follows:

In [34]:
In [35]:
Undefined variable: char_arr_var


Undefined variable: list_var


Undefined variable: recursive_var

 logic_arr_var  = 

  T F T

The multi-dimension data is converted from SoS to Scilab as follows:

In [17]:
In [18]:
> num_arr_var:
  num_arr_var  = 

  1  2
  3  4

> mat_var:
  mat_var  = 

  1  2
  3  4

The scalar data is converted from Scilab to SoS as follows:

In [20]:
 null_var  = 

   Nan

 num_var  = 

   123.

 logic_var  = 

  T

 char_var  = 

  "1 23"

 comp_var  = 

   1. + 2.i

In [21]:
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
> null_var: NoneType
None
> num_var: None
Unknown variable num_var
> logic_var: bool
True
> char_var: str of length 4
'1"23'
> comp_var: complex
(1+2j)

The one-dimension (vector) data is converted from R to SoS as follows:

In [26]:
 num_vector_var  = 

   1.   2.   3.

 logic_vector_var  = 

  T F T

 char_vector_var  = 

  "1"  "2"  "3"

 list_var  = 

  (1) = 1
  (2) = 2
  (3) = "3"


 recursive_var  = 

  (1) = 1
  (2) : list:
      (1) = 3
      (2) = "whatever"


In [27]:
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
> num_vector_var: None
Unknown variable num_vector_var
> logic_vector_var: None
Unknown variable logic_vector_var
> char_vector_var: None
Unknown variable char_vector_var
> list_var: list of length 3
[1, 2, '3']
> recursive_var: dict of length 2
{'a': {'b': 123}, 'c': True}

The multi-dimension data is converted from Scilab to SoS as follows:

In [47]:
 mat_var  = 

   1.   2.
   3.   4.

 arr_var  = 

(:,:,1)

   0.   0.
   0.   0.
(:,:,2)

   0.   0.
   0.   0.
(:,:,3)

   0.   0.
   0.   0.

In [48]:
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
Failed to evaluate 'Undefined variable: sos_py_repr':
 Invalid return expresion "Undefined variable: sos_py_repr"
[0]: 
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
script_6617773757429726406 in <module>
----> mat_var
      arr_var
      

NameError: name 'mat_var' is not defined