chainer.utils.type_check.Expr¶
-
class
chainer.utils.type_check.Expr(priority)[source]¶ Abstract syntax tree of an expression.
It represents an abstract syntax tree, and isn’t a value. You can get its actual value with
eval()function, and get syntax representation with the__str__()method. Each comparison operator (e.g.==) generates a newExprobject which represents the result of comparison between two expressions.Example
Let
xandybe instances ofExpr, then>>> x = Variable(1, 'x') >>> y = Variable(1, 'y') >>> c = (x == y)
is also an instance of
Expr. To evaluate and get its value, calleval()method:>>> c.eval() True
Call
strfunction to get a representation of the original equation:>>> str(c) 'x == y'
You can actually compare an expression with a value:
>>> (x == 1).eval() True
Note that you can’t use boolean operators such as
and, as they try to cast expressions to boolean values:>>> z = Variable(1, 'z') >>> x == y and y == z # raises an error Traceback (most recent call last): RuntimeError: Don't convert Expr to bool. Please call Expr.eval method to evaluate expression.
Methods
-
eval()[source]¶ Evaluates the tree to get actual value.
Behavior of this function depends on an implementation class. For example, a binary operator
+calls the__add__function with the two results ofeval()function.
-
__eq__(y)¶
-
__ne__(y)¶
-
__lt__(y)¶
-
__le__(y)¶
-
__gt__(y)¶
-
__ge__(y)¶
-
__neg__()¶
-
__add__(y)¶
-
__sub__(y)¶
-
__mul__(y)¶
-
__truediv__(y)¶
-
__floordiv__(y)¶
-
__pow__(y)¶
-