Reference Guide  2.5.0
psyclone.core.signature.Signature Class Reference

Public Member Functions

def __init__ (self, variable, sub_sig=None)
 
def is_structure (self)
 
def __len__ (self)
 
def __getitem__ (self, indx)
 
def __str__ (self)
 
def to_language (self, component_indices=None, language_writer=None)
 
def __repr__ (self)
 
def __hash__ (self)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __lt__ (self, other)
 
def __le__ (self, other)
 
def __gt__ (self, other)
 
def __ge__ (self, other)
 
def var_name (self)
 

Detailed Description

Given a variable access of the form ``a(i,j)%b(k,l)%c``, the signature
of this access is the tuple ``(a,b,c)``. For a simple scalar variable
``a`` the signature would just be ``(a,)``.
The signature is the key used in `VariablesAccessInfo`. In order to make
sure two different signature objects containing the same variable
can be used as a key, this class implements `__hash__` and other special
functions.
The constructor also supports appending an existing signature to this
new signature using the `sub_sig` argument. This is used in
StructureReference to assemble the overall signature of a structure
access.

:param variable: the variable that is accessed.
:type variable: str or tuple of str or list of str

:param sub_sig: a signature that is to be added to this new signature.
:type sub_sig: :py:class:`psyclone.core.Signature`

Definition at line 46 of file signature.py.

Member Function Documentation

◆ __eq__()

def psyclone.core.signature.Signature.__eq__ (   self,
  other 
)
Required in order to use a Signature instance as a key.
Compares two objects (one of which might not be a Signature).

Definition at line 205 of file signature.py.

205  def __eq__(self, other):
206  '''Required in order to use a Signature instance as a key.
207  Compares two objects (one of which might not be a Signature).'''
208  if not hasattr(other, "_signature"):
209  return False
210  return self._signature == other._signature
211 

References psyclone.core.signature.Signature._signature, and psyclone.core.single_variable_access_info.SingleVariableAccessInfo._signature.

◆ __ge__()

def psyclone.core.signature.Signature.__ge__ (   self,
  other 
)
Required to compare signatures. It just compares the tuples.

Definition at line 245 of file signature.py.

245  def __ge__(self, other):
246  '''Required to compare signatures. It just compares the tuples.'''
247  if not isinstance(other, Signature):
248  raise TypeError(f"'>=' not supported between instances of "
249  f"'Signature' and '{type(other).__name__}'.")
250  return self._signature >= other._signature
251 

References psyclone.core.signature.Signature._signature, and psyclone.core.single_variable_access_info.SingleVariableAccessInfo._signature.

◆ __gt__()

def psyclone.core.signature.Signature.__gt__ (   self,
  other 
)
Required to compare signatures. It just compares the tuples.

Definition at line 237 of file signature.py.

237  def __gt__(self, other):
238  '''Required to compare signatures. It just compares the tuples.'''
239  if not isinstance(other, Signature):
240  raise TypeError(f"'>' not supported between instances of "
241  f"'Signature' and '{type(other).__name__}'.")
242  return self._signature > other._signature
243 

References psyclone.core.signature.Signature._signature, and psyclone.core.single_variable_access_info.SingleVariableAccessInfo._signature.

◆ __hash__()

def psyclone.core.signature.Signature.__hash__ (   self)
This returns a hash value that is independent of the instance.
I.e. two instances with the same signature will have the same
hash key.

Definition at line 197 of file signature.py.

197  def __hash__(self):
198  '''This returns a hash value that is independent of the instance.
199  I.e. two instances with the same signature will have the same
200  hash key.
201  '''
202  return hash(self._signature)
203 

References psyclone.core.signature.Signature._signature, and psyclone.core.single_variable_access_info.SingleVariableAccessInfo._signature.

◆ __le__()

def psyclone.core.signature.Signature.__le__ (   self,
  other 
)
Required to compare signatures. It just compares the tuples.

Definition at line 229 of file signature.py.

229  def __le__(self, other):
230  '''Required to compare signatures. It just compares the tuples.'''
231  if not isinstance(other, Signature):
232  raise TypeError(f"'<=' not supported between instances of "
233  f"'Signature' and '{type(other).__name__}'.")
234  return self._signature <= other._signature
235 

References psyclone.core.signature.Signature._signature, and psyclone.core.single_variable_access_info.SingleVariableAccessInfo._signature.

◆ __len__()

def psyclone.core.signature.Signature.__len__ (   self)
:returns: the number of components of this signature.
:rtype: int

Definition at line 94 of file signature.py.

94  def __len__(self):
95  ''':returns: the number of components of this signature.
96  :rtype: int'''
97  return len(self._signature)
98 

References psyclone.core.signature.Signature._signature, and psyclone.core.single_variable_access_info.SingleVariableAccessInfo._signature.

◆ __lt__()

def psyclone.core.signature.Signature.__lt__ (   self,
  other 
)
Required to sort signatures. It just compares the tuples.

Definition at line 221 of file signature.py.

221  def __lt__(self, other):
222  '''Required to sort signatures. It just compares the tuples.'''
223  if not isinstance(other, Signature):
224  raise TypeError(f"'<' not supported between instances of "
225  f"'Signature' and '{type(other).__name__}'.")
226  return self._signature < other._signature
227 

References psyclone.core.signature.Signature._signature, and psyclone.core.single_variable_access_info.SingleVariableAccessInfo._signature.

◆ __ne__()

def psyclone.core.signature.Signature.__ne__ (   self,
  other 
)
Required for != comparisons of Signatures with python2.
Compares two objects (one of which might not be a Signature).

Definition at line 213 of file signature.py.

213  def __ne__(self, other):
214  '''Required for != comparisons of Signatures with python2.
215  Compares two objects (one of which might not be a Signature).'''
216  if not hasattr(other, "_signature"):
217  return True
218  return self._signature != other._signature
219 

References psyclone.core.signature.Signature._signature, and psyclone.core.single_variable_access_info.SingleVariableAccessInfo._signature.

◆ is_structure()

def psyclone.core.signature.Signature.is_structure (   self)
:returns: True if this signature represents a structure.
:rtype: bool

Definition at line 87 of file signature.py.

87  def is_structure(self):
88  ''':returns: True if this signature represents a structure.
89  :rtype: bool
90  '''
91  return len(self._signature) > 1
92 

References psyclone.core.signature.Signature._signature, and psyclone.core.single_variable_access_info.SingleVariableAccessInfo._signature.

◆ to_language()

def psyclone.core.signature.Signature.to_language (   self,
  component_indices = None,
  language_writer = None 
)
Converts this signature with the provided indices to a string
in the selected language.

TODO 1320 This subroutine can be removed when we stop supporting
strings - then we can use a PSyIR writer for the ReferenceNode
to provide the right string.

:param component_indices: the indices for each component of \
    the signature.
:type component_indices: None (default is scalar access), or \
    :py:class:`psyclone.core.component_indices.ComponentIndices`
:param language_writer: a backend visitor to convert PSyIR \
    expressions to a representation in the selected language. \
    This is used when creating error and warning messages.
:type language_writer: None (default is Fortran), or an instance of \
    :py:class:`psyclone.psyir.backend.language_writer.LanguageWriter`

:raises InternalError: if the number of components in this signature \
    is different from the number of indices in component_indices.

Definition at line 110 of file signature.py.

110  def to_language(self, component_indices=None, language_writer=None):
111  # pylint: disable=too-many-locals
112  '''Converts this signature with the provided indices to a string
113  in the selected language.
114 
115  TODO 1320 This subroutine can be removed when we stop supporting
116  strings - then we can use a PSyIR writer for the ReferenceNode
117  to provide the right string.
118 
119  :param component_indices: the indices for each component of \
120  the signature.
121  :type component_indices: None (default is scalar access), or \
122  :py:class:`psyclone.core.component_indices.ComponentIndices`
123  :param language_writer: a backend visitor to convert PSyIR \
124  expressions to a representation in the selected language. \
125  This is used when creating error and warning messages.
126  :type language_writer: None (default is Fortran), or an instance of \
127  :py:class:`psyclone.psyir.backend.language_writer.LanguageWriter`
128 
129  :raises InternalError: if the number of components in this signature \
130  is different from the number of indices in component_indices.
131  '''
132 
133  # Avoid circular import
134  # pylint: disable=import-outside-toplevel
135  from psyclone.core import ComponentIndices
136 
137  # By default, if component_indices is None, we assume a scalar access:
138  if component_indices is None:
139  component_indices = ComponentIndices([[]] * len(self))
140 
141  # Check if number of components between self and component_indices
142  # is consistent:
143  if len(self._signature) != len(component_indices):
144  raise InternalError(f"Signature '{self}' has {len(self)} "
145  f"components, but component_indices "
146  f"{component_indices} has "
147  f"{len(component_indices)}.")
148  # Avoid circular import
149  # pylint: disable=import-outside-toplevel
150  from psyclone.psyir.backend.debug_writer import DebugWriter
151  from psyclone.psyir.nodes import Literal, Node, Reference
152 
153  if language_writer is None:
154  writer = DebugWriter()
155  else:
156  writer = language_writer
157 
158  # out_list collects the string representation of the components
159  # including indices
160  out_list = []
161  for i, component in enumerate(self._signature):
162  indices = component_indices[i]
163  if not indices:
164  out_list.append(component)
165  else:
166  # If there are indices, add the "(ind1, ind2, ...)"
167  # TODO 1320: since we support strings and integer, we cannot
168  # simply pass the list of indices to writer.gen_indices
169  # (since it only accepts PSyIR Nodes). Instead we convert each
170  # string to a Reference, and each integer to a Literal
171  index_list = []
172 
173  for dimension in indices:
174  if isinstance(dimension, Node):
175  index_list.append(dimension)
176  elif isinstance(dimension, int):
177  index_list.append(Literal(str(dimension),
178  INTEGER_TYPE))
179  else:
180  ref = Reference(DataSymbol(dimension, INTEGER_TYPE))
181  index_list.append(ref)
182  dims = writer.gen_indices(index_list, component)
183 
184  parenthesis = writer.array_parenthesis
185  out_list.append(component + parenthesis[0] +
186  ",".join(dims) +
187  parenthesis[1])
188 
189  # Combine the components in out_list to form the language string.
190  return writer.structure_character.join(out_list)
191 

References psyclone.core.signature.Signature._signature, and psyclone.core.single_variable_access_info.SingleVariableAccessInfo._signature.

◆ var_name()

def psyclone.core.signature.Signature.var_name (   self)
:returns: the actual variable name, i.e. the first component of
    the signature.
:rtype: str

Definition at line 254 of file signature.py.

254  def var_name(self):
255  ''':returns: the actual variable name, i.e. the first component of
256  the signature.
257  :rtype: str
258  '''
259  return self._signature[0]
260 
261 
262 # ---------- Documentation utils -------------------------------------------- #
263 # The list of module members that we wish AutoAPI to generate
264 # documentation for. (See https://psyclone-ref.readthedocs.io)

References psyclone.core.signature.Signature._signature, and psyclone.core.single_variable_access_info.SingleVariableAccessInfo._signature.

Here is the caller graph for this function:

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