Module dev.civl.mc

Interface ArrayToolBox


public interface ArrayToolBox
This interface provides a collection of methods that manipulating symbolic expressions whose symbolic type has ARRAY kind.
  • Method Details

    • arrayFlatten

      dev.civl.sarl.IF.expr.SymbolicExpression arrayFlatten(dev.civl.sarl.IF.expr.SymbolicExpression array)
      Reshape a multiple dimensional array of type t to a one dimensional array of type t. Notice that the type t is the base type of the given ArrayToolBox.ArrayShape. (i.e. ArrayToolBox.ArrayShape.baseType).
      Parameters:
      array - a multiple dimensional array
      Returns:
      a one dimensional array which is equivalent (physically in C language) to the given array.
    • arrayReshape

      dev.civl.sarl.IF.expr.SymbolicExpression arrayReshape(dev.civl.sarl.IF.expr.SymbolicExpression array, ArrayToolBox.ArrayShape targethape)
      Reshape an array a to the given target shape t. The target shape t must be physically equivalent to the shape of array a.
      Parameters:
      array - the array that will be reshaped.
      targetShape - the ArrayToolBox.ArrayShape that the given array will be reshaped to
      Returns:
      an array of the given target shape that is physically equivalent to the given array.
    • newArrayShape

      ArrayToolBox.ArrayShape newArrayShape(dev.civl.sarl.IF.type.SymbolicArrayType arrayType)
      create an ArrayToolBox.ArrayShape, the base type will be (default) non-array type
      Parameters:
      arrayType -
      Returns:
      The ArrayToolBox.ArrayShape of the given array type, or null is the array type is NOT
      invalid reference
      #allComplete(SymbolicArrayType)
    • newArrayShape

      ArrayToolBox.ArrayShape newArrayShape(dev.civl.sarl.IF.type.SymbolicArrayType arrayType, dev.civl.sarl.IF.type.SymbolicType baseType)
      create an ArrayToolBox.ArrayShape with a specified base type. The behavior is undefined if the given base type is not a sub-type of the given array type.
      Parameters:
      arrayType -
      baseType -
      Returns:
      The ArrayToolBox.ArrayShape of the given array type, or null is the array type is NOT
      invalid reference
      #allComplete(SymbolicArrayType)
    • newArraySlice

      ArrayToolBox.ArraySlice newArraySlice(dev.civl.sarl.IF.expr.SymbolicExpression array, dev.civl.sarl.IF.expr.NumericExpression[] startIndices, dev.civl.sarl.IF.expr.NumericExpression count, dev.civl.sarl.IF.type.SymbolicType baseType)
      Parameters:
      array - the array where the slice is carved out
      startIndices - the starting indices for carving out the slice from the array
      count - the number of base type elements in the slice, notice that the base type is decided by startIndices.length
      baseType - the base type of this slice. The slice type is an array of "count" baseType elements.
      Returns:
      an ArrayToolBox.ArraySlice
    • extractArraySlice

      dev.civl.sarl.IF.expr.SymbolicExpression extractArraySlice(ArrayToolBox.ArraySlice arraySlice)
      Returns a SymbolicExpression representing the given ArrayToolBox.ArraySlice. The type of the symbolic expression will be the ArrayToolBox.ArraySlice.sliceType of arraySlice.
    • sliceIndiceProjecting

      dev.civl.sarl.IF.expr.NumericExpression[] sliceIndiceProjecting(dev.civl.sarl.IF.expr.NumericExpression[] fromSliceArrayIndices, ArrayToolBox.ArrayShape fromSliceArrayShape, dev.civl.sarl.IF.expr.NumericExpression[] fromSliceStartIndices, ArrayToolBox.ArrayShape toSliceArrayShape, dev.civl.sarl.IF.expr.NumericExpression[] toSliceStartIndices)

      Projecting the indices of an array slice s0 to another array slice s1. Requires that s0 and s1 have exact same base type.

      Example, there is an array slice s0 in an array T a[10][10], from indices {2,3}, of length 10. Then the indices of such slice are I : {{2, 3}, {2, 4}, ..., {2, 9}, {3, 0}, ..., {3, 2}}.

      And, there is another array slice s1 in an array T b[100], from index {x}, of length 20.

      Now projects indices {i, j}, which belongs to I to indices of s1, the result should be: k : i * 10 + j - (2 * 10 + 3) + x
      This projecting is mainly used for such case : the value of n-th element of s0, which is referred by {i, j}, is the value of n-th element of s1, which is referred by k.

      Notice that the caller of this method is responsible to guarantee that the given indices belong to s0 and the projected indices (returned indices) belong to s1.

      Parameters:
      fromSliceArrayIndices - The indices over the array of slice s0, that belongs to s0. They refer to the n-th element in s0
      fromSliceArrayShape - the shape of the array of slice s0
      fromSliceStartIndices - the starting indices of slice s0
      toSliceArrayShape - the shape of the array of projected slice s1
      toSliceStartIndices - the starting indices of projected slice s1
      Returns:
      the indices of the n-th element in s1
    • arrayIndiceProjecting

      dev.civl.sarl.IF.expr.NumericExpression[] arrayIndiceProjecting(dev.civl.sarl.IF.expr.NumericExpression[] fromArrayIndices, ArrayToolBox.ArrayShape fromArrayShape, ArrayToolBox.ArrayShape toArrayShape)

      Projecting indices I of an array a0 to another array a1, i.e. the value of the n-th element, referred by I, in a0 is same as the value of the n-th element in a1.

      Notice that caller of this method is responsible to guarantee that the given indices I belongs to a0 (is valid indices of a0) and the resulting indices belongs to a1

      Parameters:
      fromArrayIndices - the indices of array a0, refers to the n-th element of a0
      fromArrayShape - the shape of the array a0
      toArrayShape - the shape of the array a1
      Returns:
      indices referring to the n-th element of a1
    • areArrayShapesPhysicallyEquivalent

      dev.civl.sarl.IF.expr.BooleanExpression areArrayShapesPhysicallyEquivalent(ArrayToolBox.ArrayShape s0, ArrayToolBox.ArrayShape s1)
      Test if two array shapes s0 and s1 are physically equivalent. s0 and s1 are physically equivalent if and only if there exists an element type e_t such that array of s0 has N elements of e_t and array of s1 has M elements of e_t and N = M.
      Parameters:
      s0 -
      s1 -
      Returns:
      True iff the two array shapes are physically equivalent.
    • isArrayTypeallComplete

      boolean isArrayTypeallComplete(dev.civl.sarl.IF.type.SymbolicArrayType arrayType)
      Parameters:
      arrayType -
      Returns:
      true iff the given type is an array type and is complete at every dimension.
    • arraySliceRead

      dev.civl.sarl.IF.expr.SymbolicExpression arraySliceRead(dev.civl.sarl.IF.expr.SymbolicExpression array, dev.civl.sarl.IF.expr.NumericExpression[] indices, dev.civl.sarl.IF.expr.NumericExpression count)

      Returns a symbolic expression representing an array slice which is an one-dimensional array of elements of type t that is carved out from the given array a, where t is associated to to the given indices: {i0, i1, ... in-1}.
      t = typeof(a[i0][...][in-1]

      Parameters:
      array - an array
      indices - the indices of the element in the given array which is the first element in the returned array. (inclusive)
      count - the number of elements in the returned array
      Returns:
      a symbolic expression representing the array slice
    • arraySliceRead

      dev.civl.sarl.IF.expr.SymbolicExpression arraySliceRead(dev.civl.sarl.IF.expr.SymbolicExpression array, dev.civl.sarl.IF.expr.NumericExpression[] indices, int count)
      Same as arraySliceRead(SymbolicExpression, NumericExpression[], NumericExpression) but the "count" is known as having a concrete value.
    • arraySliceWrite

      dev.civl.sarl.IF.expr.SymbolicExpression arraySliceWrite(ArrayToolBox.ArraySlice slice, dev.civl.sarl.IF.expr.SymbolicExpression targetArray, ArrayToolBox.ArrayShape targetShape, dev.civl.sarl.IF.expr.NumericExpression[] targetStartIndices)

      Write an ArrayToolBox.ArraySlice s into the targetArray, starting from the given targetStartIndices

      Parameters:
      slice - the array slice
      targetArray - the target array where the slice will be written in
      targetShape - the ArrayToolBox.ArrayShape of the target array. targetShape and sliceShape must have the same base type
      targetStartIndices - the start indices of the written slice in the target array. (inclusive). targetStartIndices.length == targetShape.dimensions
      Returns:
      the updated target array which has been written the slice
    • mdArrayRead

      dev.civl.sarl.IF.expr.SymbolicExpression mdArrayRead(dev.civl.sarl.IF.expr.SymbolicExpression array, dev.civl.sarl.IF.expr.NumericExpression[] indices)
      Read a multi-dimensional array
      Parameters:
      array - a multi-dimensional array
      indices - indices for reading
      Returns:
      The element indexed by the given indices
    • mdArrayWrite

      dev.civl.sarl.IF.expr.SymbolicExpression mdArrayWrite(dev.civl.sarl.IF.expr.SymbolicExpression array, dev.civl.sarl.IF.expr.NumericExpression[] indices, dev.civl.sarl.IF.expr.SymbolicExpression value)
      Write a value to a multi-dimensional array
      Parameters:
      array - a multi-dimensional array
      indices - indices for reading
      Returns:
      new array after writing
    • subArrayShape

      ArrayToolBox.ArrayShape subArrayShape(ArrayToolBox.ArrayShape arrayShape, int subArrayDimensions)
      Parameters:
      arrayShape - the array shape of an array
      subArrayDimensions - the dimension of the sub-array, it must be greater than 0 and LESS THAN OR EQUAL TO the dimensions of the given array shape.
      Returns:
      The ArrayToolBox.ArrayShape of the sub array, which is a "subArrayDimensions"-dimensional array of "arrayShape".baseType
    • switchBaseType

      ArrayToolBox.ArrayShape switchBaseType(ArrayToolBox.ArrayShape arrayShape, int baseTypeDimensions)
      Given an array shape s, returns an new array shape s'. s and s' represent exact the same array shape but the base type of s' may have an array type of the base type of s.
      Parameters:
      arrayShape - the ArrayToolBox.ArrayShape of an array
      baseTypeDimensions - the dimensions of the new base type. The new base type is a 'baseTypeDimensions'-dimensional array of the old base type. 'baseTypeDimensions' must be GREATER THAN OR EQUAL TO 0 and LESS THAN the dimensions of the given array shape.
      Returns:
      a new ArrayToolBox.ArrayShape which represents the same shape as the given one but has different base type.