next up previous contents index
Next: SIC structures Up: Importing SIC objects Previous: SIC arrays   Contents   Index


SIC scalars

Particular numpy.ndarray's which have no (0) dimension have a special treatment: they still have numpy.ndarray type, but their representation and handling is similar to standard Python scalars. SIC scalars are imported in Python as numpy.ndarray scalars through SicVar instances:

>>> Sic.comm('DEF REAL D')
>>> d
0.0
>>> print d.__doc__
A SicVar instance.

You have to take care that you cannot modify scalars (and, actually, any SicVar or SicStructure instance) with commands such as d = 1, because this unbounds d to its corresponding SicVar instance (which is lost and deleted if no other variable uses it), and bounds it to integer 1. If it happens, you can get('D') again: SicVar instance is recreated and all the previous changes will not be lost because D have not been deleted in SIC.

>>> Sic.comm('LET D 1.')
>>> d
1.0
>>> d = 2.            # ooops... 'd' instance is lost!
>>> type(d)
<type 'float'>        # 'd' is bound to a standard float,
>>> Sic.comm('EXA D') # but 'D' remains unchanged in SIC.
D          =   1.000000              ! Real    GLOBAL
>>> Sic.get('D')      # Reincarnates d.
>>> d
1.0

Thus, to modify scalars from Python, you have to access its data through its unique element:

>>> d[0] = 2.
>>> d
2.0
>>> print d.__doc__
A SicVar instance.



Gildas manager 2024-03-28