Next: SIC scalars Up: Importing SIC objects Previous: Importing SIC objects   Contents   Index

### SIC arrays

SIC arrays are imported as SicVar instances. Let us define9 a 1D array A in SIC:
 >>> Sic.setgdict(globals()) Importing all SIC variables into Python... ... done. >>> Sic.comm('DEFINE INTEGER A[3]')

Defining a variable in SIC automatically imports it in Python __main__. Here A is imported into a SicVar instance with name 'a':

 >>> a [0 0 0] >>> print a array([0, 0, 0]) >>> type(a) >>> print a.__doc__ A SicVar instance.

All of the numpy.ndarray attributes, methods or functions should apply to the SicVar instances, because almost all these instances behaviors are redirected to their numpy.ndarray component. Their elements can be accessed with standard NumPy indexing syntax:

 >>> a[0] 0 >>> a[1:] # Elements 1 and subsequents [0 0] >>> a += 1 # Adds 1 to all elements >>> a [1 1 1]
 >>> a[:] = 0 # Sets all elements to 0 >>> a [0 0 0] >>> len(a) # Length 3 >>> a.shape (3,)

Remember that data pointed to by SicVar instances is not a copy: if you modify it in Python it will be modified in SIC:

 >>> a[0] = 1 >>> a [1 0 0] >>> Sic.comm('EXA A') A is an integer Array of dimensions 3 1 0 0

Remember also that derived arrays share their data with the initial array:

 >>> b = a[0:2] # First two elements (upper limit is excluded) >>> print b.__doc__ A SicVar instance. >>> b [1 0] >>> b += 1 # Adds 1 to all elements >>> b [2 1] >>> a [2 1 0]

Note that b, as a derived array, is itself a SicVar instance, but is only visible in Python. And remember the different memory arrangement between SIC (Fortran) and C (Python) for multidimensionnal arrays (see subsection 2.1.1):

 >>> Sic.comm('DEFINE INTEGER C[2,3,4]') >>> c.shape (4, 3, 2) >>> c[0,0,0] = 1 # First element >>> c[3,2,1] = 2 # Last element >>> Sic.comm('EXAMINE C') C is an integer Array of dimensions 2 3 4 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2

Next: SIC scalars Up: Importing SIC objects Previous: Importing SIC objects   Contents   Index
Gildas manager 2014-07-01