Next: The SicVar class
Up: How SIC variables are
Previous: How SIC variables are
Contents
Index
Concerning variables handling from both SIC and Python, the first priority was to
manage the same data in memory from the two processes, e.g. a modification of a
variable in one process should be instantaneously visible in the other with no
particular resynchronization.
Another consideration is that Python does not natively handle multi-dimensionnal
arrays. This feature can be easily added, but we need the Numeric package or one of
its derivates (including NumPy).
It appeared quite naturally that the solution was to use the
PyArray_FromDimsAndData() function of the Numeric C-API: it can construct a
Numeric.array from the memory address of an array, its dimensions and its datatype. NumPy also implements this function14 and is used by
default. It returns a numpy.ndarray.
With this feature the strategy can be summarized as follow:
- Numeric/NumPy freeze their array's definition (attributes, size in memory and
so on) at compilation time. We can not add to it more interesting features,
especially new attributes or write protection for read-only variables.
- an overlay had to be created with one purpose: defining a set of features like
- the ability to define attributes to variables,
- the protection of read-only variables,
- a special treatment for character string variables (concatenation),
- ...
and all this must keep unmodified all the numpy.ndarray features (indexing, array
handling, special functions and attributes, and so on)
- this overlay was created as a Python class named SicVar. It has three
attributes: a string named __sicname__, which is the SIC name of the variable,
a numpy.ndarray named __sicdata__, which shares its data with the SIC variable, and its
SIC-level (global or local) stored as an integer named __siclevel__. All
numpy.ndarray-like requests on a SicVar are redirected to the __sicdata__ attribute: with
this, SicVar instances behaves like any other numpy.ndarray.
Next: The SicVar class
Up: How SIC variables are
Previous: How SIC variables are
Contents
Index
Gildas manager
2014-07-01