Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Public Attributes | List of all members
CellMLToNektar.optimize.LookupTableAnalyser.LUTState Class Reference
Inheritance diagram for CellMLToNektar.optimize.LookupTableAnalyser.LUTState:
Inheritance graph
[legend]
Collaboration diagram for CellMLToNektar.optimize.LookupTableAnalyser.LUTState:
Collaboration graph
[legend]

Public Member Functions

def __init__
 
def update
 
def suitable
 
def reason
 

Public Attributes

 has_var
 
 bad_vars
 
 has_func
 
 table_var
 

Detailed Description

Represents the state for lookup table analysis.

Definition at line 479 of file optimize.py.

Constructor & Destructor Documentation

def CellMLToNektar.optimize.LookupTableAnalyser.LUTState.__init__ (   self)
Set the initial state.

We assume at first a lookup table would not be suitable.

Definition at line 481 of file optimize.py.

482  def __init__(self):
483  """Set the initial state.
484 
485  We assume at first a lookup table would not be suitable.
486  """
487  self.has_var = False
488  self.bad_vars = set()
489  self.has_func = False
490  self.table_var = None

Member Function Documentation

def CellMLToNektar.optimize.LookupTableAnalyser.LUTState.reason (   self)
Return a unicode string describing why this state indicates the
expression is not suitable for replacement with a lookup table.

This can be:
 'no_var' - doesn't contain the table variable
 'bad_var <vname>' - contains a variable which isn't permitted
 'no_func' - doesn't contain an expensive function
or a comma separated combination of the above.

Definition at line 517 of file optimize.py.

References CellMLToNektar.optimize.LookupTableAnalyser.LUTState.bad_vars, CellMLToNektar.optimize.LookupTableAnalyser.LUTState.has_func, and CellMLToNektar.optimize.LookupTableAnalyser.LUTState.has_var.

518  def reason(self):
519  """
520  Return a unicode string describing why this state indicates the
521  expression is not suitable for replacement with a lookup table.
522 
523  This can be:
524  'no_var' - doesn't contain the table variable
525  'bad_var <vname>' - contains a variable which isn't permitted
526  'no_func' - doesn't contain an expensive function
527  or a comma separated combination of the above.
528  """
529  r = []
530  if not self.has_var:
531  r.append(u'no_var')
532  if not self.has_func:
533  r.append(u'no_func')
534  for vname in self.bad_vars:
535  r.append(u'bad_var ' + vname)
536  return u','.join(r)
def create_state_from_annotations(self, expr):
def CellMLToNektar.optimize.LookupTableAnalyser.LUTState.suitable (   self)
Return True iff this state indicates a suitable expression for replacement with a lookup table.

Definition at line 511 of file optimize.py.

References CellMLToNektar.optimize.LookupTableAnalyser.LUTState.bad_vars, CellMLToNektar.optimize.LookupTableAnalyser.LUTState.has_func, and CellMLToNektar.optimize.LookupTableAnalyser.LUTState.has_var.

512  def suitable(self):
513  """Return True iff this state indicates a suitable expression for replacement with a lookup table."""
514  return (self.has_var and
515  not self.bad_vars and
516  self.has_func)
def CellMLToNektar.optimize.LookupTableAnalyser.LUTState.update (   self,
  res 
)
Update the state with the results of a recursive call.

res is the result of checking a sub-expression for suitability,
and should be another instance of this class.

Definition at line 491 of file optimize.py.

References CellMLToNektar.optimize.LookupTableAnalyser.LUTState.has_func, CellMLToNektar.optimize.LookupTableAnalyser.LUTState.has_var, and CellMLToNektar.optimize.LookupTableAnalyser.LUTState.table_var.

492  def update(self, res):
493  """Update the state with the results of a recursive call.
494 
495  res is the result of checking a sub-expression for suitability,
496  and should be another instance of this class.
497  """
498  self.has_var = (self.has_var or res.has_var) and \
499  (not (self.table_var and res.table_var) or
500  self.table_var.get_source_variable(recurse=True) is
501  res.table_var.get_source_variable(recurse=True))
502  # The second condition above specifies that the keying variables must be the same if they both exist
503  self.bad_vars.update(res.bad_vars)
504  self.has_func = self.has_func or res.has_func
505  self.table_var = self.table_var or res.table_var
506  if not self.has_var and self.table_var:
507  # Two sub-expressions have different keying variables, so consider them as bad variables
508  self.bad_vars.add(self.table_var.name)
509  self.bad_vars.add(res.table_var.name)
510  self.table_var = None

Member Data Documentation

CellMLToNektar.optimize.LookupTableAnalyser.LUTState.bad_vars

Definition at line 487 of file optimize.py.

Referenced by CellMLToNektar.optimize.LookupTableAnalyser.LUTState.reason(), and CellMLToNektar.optimize.LookupTableAnalyser.LUTState.suitable().

CellMLToNektar.optimize.LookupTableAnalyser.LUTState.has_func

Definition at line 488 of file optimize.py.

Referenced by CellMLToNektar.optimize.LookupTableAnalyser.LUTState.reason(), CellMLToNektar.optimize.LookupTableAnalyser.LUTState.suitable(), and CellMLToNektar.optimize.LookupTableAnalyser.LUTState.update().

CellMLToNektar.optimize.LookupTableAnalyser.LUTState.has_var

Definition at line 486 of file optimize.py.

Referenced by CellMLToNektar.optimize.LookupTableAnalyser.LUTState.reason(), CellMLToNektar.optimize.LookupTableAnalyser.LUTState.suitable(), and CellMLToNektar.optimize.LookupTableAnalyser.LUTState.update().

CellMLToNektar.optimize.LookupTableAnalyser.LUTState.table_var

Definition at line 489 of file optimize.py.

Referenced by CellMLToNektar.optimize.LookupTableAnalyser.is_keying_var(), and CellMLToNektar.optimize.LookupTableAnalyser.LUTState.update().