Nektar++
Public Member Functions | Public Attributes | List of all members
CellMLToNektar.optimize.LookupTableAnalyser.LUTState Class Reference
Inheritance diagram for CellMLToNektar.optimize.LookupTableAnalyser.LUTState:
[legend]

Public Member Functions

def __init__ (self)
 
def update (self, res)
 
def suitable (self)
 
def reason (self)
 

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

◆ __init__()

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.

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

Member Function Documentation

◆ reason()

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.

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

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

◆ suitable()

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.

511 def suitable(self):
512 """Return True iff this state indicates a suitable expression for replacement with a lookup table."""
513 return (self.has_var and
514 not self.bad_vars and
515 self.has_func)
516

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

◆ update()

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.

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

References CellMLToNektar.optimize.LookupTableAnalyser.LUTState.bad_vars, CellMLToNektar.optimize.LookupTableAnalyser.LUTState.has_func, CellMLToNektar.optimize.LookupTableAnalyser.LUTState.has_var, CellMLToNektar.optimize.LookupTableAnalyser.LUTState.table_var, and CellMLToNektar.optimize.LookupTableAnalyser.LUTState.update().

Referenced by CellMLToNektar.optimize.LookupTableAnalyser.LUTState.update().

Member Data Documentation

◆ bad_vars

CellMLToNektar.optimize.LookupTableAnalyser.LUTState.bad_vars

◆ has_func

CellMLToNektar.optimize.LookupTableAnalyser.LUTState.has_func

◆ has_var

CellMLToNektar.optimize.LookupTableAnalyser.LUTState.has_var

◆ table_var

CellMLToNektar.optimize.LookupTableAnalyser.LUTState.table_var