Module dev.civl.mc

Interface ArrayReshaper


public interface ArrayReshaper

This class provides methods for reshaping arrays. In C language, an array of objects is physically a sequence of objects in memory but can be accessed in various ways. For example, an array T a[10] can be access as a one dimensional array of T with length 10, as a two dimensional array T a[2][5], a two dimensional array T a[5][2], etc.

In CIVL, arrays are represented in a logical way, e.g. a two dimensional array is a one dimensional array of arrays. But such difference will not prevent us from providing array reshaping.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    allComplete(dev.civl.sarl.IF.type.SymbolicArrayType arrayType)
     
    dev.civl.sarl.IF.expr.SymbolicExpression
    arrayFlatten(dev.civl.sarl.IF.expr.SymbolicExpression array, ArrayToolBox.ArrayShape shape)
    Reshape a multiple dimensional array of type t to a one dimensional array of type t.
    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.
    dev.civl.sarl.IF.expr.SymbolicExpression
    arrayReshape(dev.civl.sarl.IF.expr.SymbolicExpression array, ArrayToolBox.ArrayShape originShape, ArrayToolBox.ArrayShape targetShape)
    Reshape an array a to the given target shape t.
    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.
  • Method Details

    • arrayFlatten

      dev.civl.sarl.IF.expr.SymbolicExpression arrayFlatten(dev.civl.sarl.IF.expr.SymbolicExpression array, ArrayToolBox.ArrayShape shape)
      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
      shape - the ArrayToolBox.ArrayShape of the given 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 originShape, ArrayToolBox.ArrayShape targetShape)
      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.
      originShape - the ArrayToolBox.ArrayShape of the given array
      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.
    • allComplete

      boolean allComplete(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.
    • 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