# loki.transformations.argument_shape module

Inter-procedural analysis passes to derive and augment argument array shapes.

A pair of utility `Transformation` classes that allows thea shape of array arguments with deferred dimensions to be derived from the calling context via inter-procedural analysis.

To infer the declared dimensions of array arguments `ArgumentArrayShapeAnalysis` needs to be applied first to set the `shape` property on respective `Array` symbols, before `ExplicitArgumentArrayShapeTransformation` can be applied in a reverse traversal order to apply the necessary changes to argument declarations and call signatures.

class ArgumentArrayShapeAnalysis

  Bases: `Transformation`

  Infer shape of array arguments with deferred shape.

  An inter-procedural analysis pass that passively infers the shape symbols for argument arrays from calling contexts and sets the `shape` attribute on `Array` symbols accordingly.

  The shape information is propagated from a caller to the called subroutine in a forward traversal of the call-tree. If the call-side shape of an array argument is either set, or has already been derived (possibly with conflicting information), this transformation will have no effect.

  Note: This transformation does not affect the generated source code, as it only sets the `shape` property, which is ignored during the code generation step (`fgen`). To actively change the argument array declarations and the resulting source code, the `ExplicitArgumentArrayShapeTransformation` needs to be applied after this transformation.

  transform_subroutine(routine, **kwargs)

    Defines the transformation to apply to `Subroutine` items.

    For transformations that modify `Subroutine` objects, this method should be implemented. It gets called via the dispatch method `apply()`.

    Parameters:

      - routine (`Subroutine`) – The subroutine to be transformed.

      - **kwargs (optional) – Keyword arguments for the transformation.

class ExplicitArgumentArrayShapeTransformation

  Bases: `Transformation`

  Add dimensions to array arguments and adjust call signatures.

  Adjusts array argument declarations by inserting explicit shape variables according to the `shape` property of the `Array` symbol. This property can be derived from the calling context via `ArgumentArrayShapeAnalysis`.

  If the `Scalar` symbol defining an array dimension is not yet known in the local `Subroutine`, it gets added to the call signature. In the caller routine, the respective `Scalar` argument is added to the `CallStatement` via keyword-argument notation.

  Note: Since the `CallStatement` needs updating after the called `Subroutine` signature, this transformation has to be applied in reverse order via `Scheduler.process(..., reverse=True)`.

  reverse_traversal = True
  transform_subroutine(routine, **kwargs)

    Defines the transformation to apply to `Subroutine` items.

    For transformations that modify `Subroutine` objects, this method should be implemented. It gets called via the dispatch method `apply()`.

    Parameters:

      - routine (`Subroutine`) – The subroutine to be transformed.

      - **kwargs (optional) – Keyword arguments for the transformation.