Package esys :: Package escript :: Module util :: Class Symbol
[hide private]
[frames] | no frames]

Class Symbol

object --+
         |
        Symbol
Known Subclasses:

Symbol class objects provide the same functionality as numpy.ndarray and escript.Data objects but they do not have a value and therefore cannot be plotted or visualized. The main purpose is the possibility to calculate derivatives with respect to other Symbols used to define a Symbol.

Instance Methods [hide private]
 
__abs__(self)
Returns a Symbol representing the absolute value of the object.
DependendSymbol
__add__(self, other)
Adds another object to this object.
DependendSymbol
__div__(self, other)
Divides this object by another object.
DependendSymbol
__getitem__(self, index)
Returns the slice defined by index.
 
__init__(self, shape=(), args=[], dim=None)
Creates an instance of a symbol of a given shape.
DependendSymbol or 0 if other is identical to zero.
__mul__(self, other)
Multiplies this object with another object.
DependendSymbol
__neg__(self)
Returns -self.
DependendSymbol
__pos__(self)
Returns +self.
DependendSymbol or 1 if other is identical to zero
__pow__(self, other)
Raises this object to the power of other.
DependendSymbol
__radd__(self, other)
Adds this object to another object.
DependendSymbol or 0 if other is identical to zero
__rdiv__(self, other)
Divides another object by this object.
DependendSymbol or 0 if other is identical to zero
__rmul__(self, other)
Multiplies another object by this object.
DependendSymbol or 0 if other is identical to zero
__rpow__(self, other)
Raises an object to the power of this object.
DependendSymbol
__rsub__(self, other)
Subtracts this object from another object.
str
__str__(self)
Returns a string representation of the symbol.
DependendSymbol
__sub__(self, other)
Subtracts another object from this object.
typically escript.Symbol but other types such as float, escript.Data, numpy.ndarray are possible
diff(self, arg)
Returns the derivative of the symbol with respect to Symbol arg.
a single object or a list of objects
getArgument(self, i=None)
Returns the i-th argument of the symbol.
list of objects
getDifferentiatedArguments(self, arg)
Applies differentials to the arguments of this object and returns the result as a list.
int if the dimension is defined, None otherwise
getDim(self)
Returns the spatial dimension.
str
getMyCode(self, argstrs, format='escript')
Returns program code that can be used to evaluate the symbol.
int
getRank(self)
Returns the rank of the symbol.
tuple of int
getShape(self)
Returns the shape of the symbol.
list of objects
getSubstitutedArguments(self, argvals)
Substitutes symbols in the arguments of this object and returns the result as a list.
bool
isAppropriateValue(self, arg)
Checks if the given argument arg can be used as a substitution for this object.
escript.Symbol, float, escript.Data, numpy.ndarray depending on the degree of substitution
substitute(self, argvals)
Assigns new values to symbols in the definition of the symbol.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__add__(self, other)
(Addition operator)

 

Adds another object to this object.

Parameters:
Returns: DependendSymbol
a Symbol representing the sum of this object and other

__div__(self, other)

 

Divides this object by another object.

Parameters:
Returns: DependendSymbol
a Symbol representing the quotient of this object and other

__getitem__(self, index)
(Indexing operator)

 

Returns the slice defined by index.

Parameters:
  • index (slice or int or a tuple of them) - the slice index
Returns: DependendSymbol
a Symbol representing the slice defined by index

__init__(self, shape=(), args=[], dim=None)
(Constructor)

 

Creates an instance of a symbol of a given shape. The symbol may depend on a list of arguments args which may be symbols or any other object.

Parameters:
  • args (list) - the arguments of the symbol
  • shape (tuple of int) - the shape of the symbol
  • dim (None or int) - spatial dimension of the symbol. If dim=None the spatial dimension is undefined.
Overrides: object.__init__

__mul__(self, other)

 

Multiplies this object with another object.

Parameters:
Returns: DependendSymbol or 0 if other is identical to zero.
a Symbol representing the product of the object and other

__neg__(self)

 

Returns -self.

Returns: DependendSymbol
a Symbol representing the negative of the object

__pos__(self)

 

Returns +self.

Returns: DependendSymbol
a Symbol representing the positive of the object

__pow__(self, other)

 

Raises this object to the power of other.

Parameters:
Returns: DependendSymbol or 1 if other is identical to zero
a Symbol representing the power of this object to other

__radd__(self, other)
(Right-side addition operator)

 

Adds this object to another object.

Parameters:
Returns: DependendSymbol
a Symbol representing the sum of other and this object

__rdiv__(self, other)

 

Divides another object by this object.

Parameters:
Returns: DependendSymbol or 0 if other is identical to zero
a Symbol representing the quotient of other and this object

__rmul__(self, other)

 

Multiplies another object by this object.

Parameters:
Returns: DependendSymbol or 0 if other is identical to zero
a Symbol representing the product of other and the object

__rpow__(self, other)

 

Raises an object to the power of this object.

Parameters:
Returns: DependendSymbol or 0 if other is identical to zero
a Symbol representing the power of other to this object

__rsub__(self, other)

 

Subtracts this object from another object.

Parameters:
Returns: DependendSymbol
a Symbol representing the difference of this object and other.

__str__(self)
(Informal representation operator)

 

Returns a string representation of the symbol.

Returns: str
a string representation of the object
Overrides: object.__str__

__sub__(self, other)
(Subtraction operator)

 

Subtracts another object from this object.

Parameters:
Returns: DependendSymbol
a Symbol representing the difference of other and this object

diff(self, arg)

 

Returns the derivative of the symbol with respect to Symbol arg.

Parameters:
  • arg (typically escript.Symbol but can also be float, escript.Data, numpy.ndarray depending on the involved functions and data) - the derivative is calculated with respect to arg
Returns: typically escript.Symbol but other types such as float, escript.Data, numpy.ndarray are possible
derivative with respect to arg

Note: this method is overwritten by a particular Symbol.

getArgument(self, i=None)

 

Returns the i-th argument of the symbol.

Parameters:
  • i (int or None) - index of the argument requested
Returns: a single object or a list of objects
the value of the i-th argument or if i is not specified the list of all arguments
Raises:
  • IndexError - if the requested index does not exist

getDifferentiatedArguments(self, arg)

 

Applies differentials to the arguments of this object and returns the result as a list.

Parameters:
  • arg (typically escript.Symbol but can also be float, escript.Data, numpy.ndarray depending on the involved functions and data) - the derivative is calculated with respect to arg
Returns: list of objects
list of object obtained by calculating the derivatives of the arguments with respect to arg

getDim(self)

 

Returns the spatial dimension.

Returns: int if the dimension is defined, None otherwise
the symbol's spatial dimension

getMyCode(self, argstrs, format='escript')

 

Returns program code that can be used to evaluate the symbol.

Parameters:
  • argstrs (list of str) - a string for each argument representing the argument for the evaluation
  • format (str) - specifies the format to be used. At the moment only "escript", "str" and "text" are supported.
Returns: str
a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available
Raises:
  • NotImplementedError - if no implementation for the given format is available

Note: This method has to be overwritten by subclasses.

getRank(self)

 

Returns the rank of the symbol.

Returns: int
the rank of the symbol. This is length of the shape.

getShape(self)

 

Returns the shape of the symbol.

Returns: tuple of int
the shape of the symbol

getSubstitutedArguments(self, argvals)

 

Substitutes symbols in the arguments of this object and returns the result as a list.

Parameters:
  • argvals (dict with keywords of type Symbol) - Symbol and their substitutes. The Symbol u in the expression defining this object is replaced by argvals[u].
Returns: list of objects
list of the object assigned to the arguments through substitution or for the arguments which are not Symbols the value assigned to the argument at instantiation.

isAppropriateValue(self, arg)

 

Checks if the given argument arg can be used as a substitution for this object. The method checks the shape of arg and, if the spatial dimension is defined, the spatial dimension of arg.

Parameters:
  • arg (numpy.ndarray, escript.Data, float, int, Symbol) - object to be checked
Returns: bool
True if arg is a suitable object to be used for substitution, False otherwise

substitute(self, argvals)

 

Assigns new values to symbols in the definition of the symbol.

The method replaces the Symbol u by argvals[u] in the expression defining this object.

Parameters:
  • argvals (dict with keywords of type Symbol) - new values assigned to symbols
Returns: escript.Symbol, float, escript.Data, numpy.ndarray depending on the degree of substitution
result of the substitution process. Operations are executed as much as possible.
Raises:
  • NotImplementedError - if no implementation for the given format is available
  • TypeError - if a value for a Symbol cannot be substituted

Note: this method has to be overwritten by a particular Symbol