Reference Guide  2.5.0
psyclone.psyGen.TransInfo Class Reference

Public Member Functions

def __init__ (self, module=None, base_class=None)
 
def list (self)
 
def num_trans (self)
 
def get_trans_num (self, number)
 
def get_trans_name (self, name)
 

Detailed Description

This class provides information about, and access, to the available
transformations in this implementation of PSyclone. New transformations
will be picked up automatically as long as they subclass the abstract
Transformation class.

For example:

>>> from psyclone.psyGen import TransInfo
>>> t = TransInfo()
>>> print(t.list)
There is 1 transformation available:
  1: SwapTrans, A test transformation
>>> # accessing a transformation by index
>>> trans = t.get_trans_num(1)
>>> # accessing a transformation by name
>>> trans = t.get_trans_name("SwapTrans")

Definition at line 2633 of file psyGen.py.

Constructor & Destructor Documentation

◆ __init__()

def psyclone.psyGen.TransInfo.__init__ (   self,
  module = None,
  base_class = None 
)
 if module and/or baseclass are provided then use these else use
    the default module "Transformations" and the default base_class
    "Transformation"

Definition at line 2654 of file psyGen.py.

2654  def __init__(self, module=None, base_class=None):
2655  ''' if module and/or baseclass are provided then use these else use
2656  the default module "Transformations" and the default base_class
2657  "Transformation"'''
2658 
2659  if False:
2660  self._0_to_n = DummyTransformation() # only here for pyreverse!
2661 
2662  # TODO #620: This need to be improved to support the new
2663  # layout, where transformations are in different directories and files.
2664  # Leaving local imports so they will be removed once TransInfo is
2665  # replaced.
2666  # pylint: disable=import-outside-toplevel
2667  from psyclone import transformations
2668  if module is None:
2669  # default to the transformation module
2670  module = transformations
2671  if base_class is None:
2672  base_class = Transformation
2673  # find our transformations
2674  self._classes = self._find_subclasses(module, base_class)
2675 
2676  # create our transformations
2677  self._objects = []
2678  self._obj_map = {}
2679  for my_class in self._classes:
2680  my_object = my_class()
2681  self._objects.append(my_object)
2682  self._obj_map[my_object.name] = my_object
2683  # TODO #620:
2684  # Transformations that are in psyir and other subdirectories
2685  # are not found by TransInfo, so we add some that are used in
2686  # tests and examples explicitly. I'm leaving this import here
2687  # so it is obvious it can be removed.
2688  from psyclone.psyir.transformations import LoopFuseTrans
2689  my_object = LoopFuseTrans()
2690  # Only add the loop-fuse statement if base_class and module
2691  # match for the loop fusion transformation.
2692  if isinstance(my_object, base_class) and module == transformations:
2693  self._objects.append(LoopFuseTrans())
2694  self._obj_map["LoopFuseTrans"] = self._objects[-1]
2695 

References psyclone.domain.lfric.lfric_invokes.LFRicInvokes._0_to_n, psyclone.dynamo0p3.DynKernelArguments._0_to_n, psyclone.gocean1p0.GOInvokes._0_to_n, psyclone.gocean1p0.GOKernelArguments._0_to_n, psyclone.psyGen.TransInfo._0_to_n, psyclone.psyGen.TransInfo._classes, psyclone.psyGen.TransInfo._find_subclasses(), psyclone.psyGen.TransInfo._obj_map, and psyclone.psyGen.TransInfo._objects.

Here is the call graph for this function:

Member Function Documentation

◆ get_trans_name()

def psyclone.psyGen.TransInfo.get_trans_name (   self,
  name 
)
 return the transformation with this name (use list() first to see
    available transformations) 

Definition at line 2724 of file psyGen.py.

2724  def get_trans_name(self, name):
2725  ''' return the transformation with this name (use list() first to see
2726  available transformations) '''
2727  try:
2728  return self._obj_map[name]
2729  except KeyError:
2730  raise GenerationError(f"Invalid transformation name: got {name} "
2731  f"but expected one of "
2732  f"{self._obj_map.keys()}")
2733 

References psyclone.psyGen.TransInfo._obj_map.

◆ get_trans_num()

def psyclone.psyGen.TransInfo.get_trans_num (   self,
  number 
)
 return the transformation with this number (use list() first to
    see available transformations) 

Definition at line 2717 of file psyGen.py.

2717  def get_trans_num(self, number):
2718  ''' return the transformation with this number (use list() first to
2719  see available transformations) '''
2720  if number < 1 or number > len(self._objects):
2721  raise GenerationError("Invalid transformation number supplied")
2722  return self._objects[number-1]
2723 

References psyclone.psyGen.TransInfo._objects.

◆ list()

def psyclone.psyGen.TransInfo.list (   self)
 return a string with a human readable list of the available
    transformations 

Definition at line 2697 of file psyGen.py.

2697  def list(self):
2698  ''' return a string with a human readable list of the available
2699  transformations '''
2700  import os
2701  if len(self._objects) == 1:
2702  result = "There is 1 transformation available:"
2703  else:
2704  result = (f"There are {len(self._objects)} transformations "
2705  f"available:")
2706  result += os.linesep
2707  for idx, my_object in enumerate(self._objects):
2708  result += " " + str(idx+1) + ": " + my_object.name + ": " + \
2709  str(my_object) + os.linesep
2710  return result
2711 

References psyclone.psyGen.TransInfo._objects.

◆ num_trans()

def psyclone.psyGen.TransInfo.num_trans (   self)
 return the number of transformations available 

Definition at line 2713 of file psyGen.py.

2713  def num_trans(self):
2714  ''' return the number of transformations available '''
2715  return len(self._objects)
2716 

References psyclone.psyGen.TransInfo._objects.


The documentation for this class was generated from the following file: