psyclone.domain.nemo.transformations.nemo_arrayrange2loop_trans

Module providing a transformation that given an Assignment node to an ArrayReference in its left-hand-side which has at least one PSyIR Range node (equivalent to an array assignment statement in Fortran), it converts it to the equivalent explicit loop representation using a NemoLoop node.

Classes

class psyclone.domain.nemo.transformations.nemo_arrayrange2loop_trans.NemoArrayRange2LoopTrans

Transformation that given an assignment with an ArrayReference Range in the LHS (equivalent to an array assignment statement in Fortran), it converts it to an explicit loop doing each of the individual element assignments separately. For example:

>>> from psyclone.parse.algorithm import parse
>>> from psyclone.psyGen import PSyFactory
>>> api = "nemo"
>>> filename = "tra_adv.F90" # examples/nemo/code
>>> ast, invoke_info = parse(filename, api=api)
>>> psy = PSyFactory(api).create(invoke_info)
>>> schedule = psy.invokes.invoke_list[0].schedule
>>> print(schedule.view())
>>>
>>> from psyclone.psyir.nodes import Range
>>> from psyclone.domain.nemo.transformations import             NemoArrayRange2LoopTrans
>>> from psyclone.transformations import TransformationError
>>>
>>> trans = NemoArrayRange2LoopTrans()
>>> for my_range in reversed(schedule.walk(Range)):
>>>     try:
>>>         trans.apply(my_range)
>>>     except TransformationError:
>>>         pass
>>> print(schedule.view())

The specified Range node must be the outermost Range (specifying an access to an array index) within an Array Reference and the array reference must be on the left-hand-side of an Assignment node. This is required for correctness and if not satisfied the transformation will raise an exception.

By default the transformation will reject character arrays, though this can be overriden by setting the allow_string option to True. Note that PSyclone expresses syntax such as character(LEN=100) as UnsupportedFortranType, and this transformation will convert unknown or unsupported types to loops.

Inheritance

Inheritance diagram of NemoArrayRange2LoopTrans
apply(node, options=None)

Apply the transformation such that, given an assignment with an ArrayReference Range in the LHS (equivalent to an array assignment statement in Fortran), it converts it to an explicit loop doing each of the individual element assignments separately.

The Range node is provided to the apply method of the transformation to indicate which array index should be transformed. This can only be applied to the outermost Range of the ArrayReference.

This is currently specific to the ‘nemo’ API in that it will create NemoLoops.

Parameters:
  • node (psyclone.psyir.nodes.Range) – a Range node.

  • options (Optional[Dict[str, Any]]) – a dictionary with options for transformations. No options are used in this transformation. This is an optional argument that defaults to None.

  • options["allow_string"] (bool) – whether to allow the transformation on a character type array range. Defaults to False.

property name
Returns:

the name of the transformation as a string.

Return type:

str

validate(node, options=None)

Perform various checks to ensure that it is valid to apply the NemoArrayRange2LoopTrans transformation to the supplied PSyIR Node.

By default the validation will reject character arrays that PSyclone understand as such, though this can be overriden by setting the allow_string option to True. Note that PSyclone expresses syntax such as character(LEN=100) as UnsupportedFortranType, and this transformation will convert unknown or unsupported types to loops.

Parameters:
  • node (psyclone.psyir.nodes.Range) – the node that is being checked.

  • options (Optional[Dict[str, Any]]) – a dictionary with options for transformations. No options are used in this transformation. This is an optional argument that defaults to None.

  • options["allow_string"] (bool) – whether to allow the transformation on a character type array range. Defaults to False.

Raises:
  • TransformationError – if the node argument is not a Range, if the Range node is not part of an ArrayReference, if the Range node is not the outermost Range node of the ArrayReference or if that ArrayReference does not constitute the left hand side of an Assignment node.

  • TransformationError – if the node argument has nested array expressions with Ranges or is an invalid tree with ranges in multiple locations of a structure of arrays.

  • TransformationError – if the node argument contains a non-elemental Operation or Call.

  • TransformationError – if node contains a character type child and the allow_strings option is not set.