##### DO NOT USE THESE BECAUSE INPLACE OPS SHOULD BE INSERTED
##### BY OPTIMIZATIONS ONLY
## ARITHMETIC - INPLACE
#def __iadd__(self, other):
# return _add_inplace(self, other)
#def __isub__(self, other):
# return _sub_inplace(self, other)
#
#def __imul__(self, other):
# return _mul_inplace(self, other)
#
#def __idiv__(self, other):
# return _div_inplace(self, other)
#
#def __ipow__(self, other):
# return _pow_inplace(self, other)
# ARITHMETIC - RIGHT-OPERAND
def__radd__(self,other):
returnadd(other,self)
def__rsub__(self,other):
returnsub(other,self)
def__rmul__(self,other):
returnmul(other,self)
def__rdiv__(self,other):
returndiv_proxy(other,self)
def__rmod__(self,other):
returnmod(other,self)
def__rpow__(self,other):
returnpow(other,self)
#TRANSPOSE
T=property(lambdaself:transpose(self))
...
...
@@ -1360,43 +1450,51 @@ class _tensor_py_operators:
size=property(lambdaself:prod(self.shape))
# We can't implement __len__ to provide a better error message.
defany(self,axis=None):
defany(self,axis=None):
returnelemwise.Any(axis)(self)
defall(self,axis=None):
defall(self,axis=None):
returnelemwise.All(axis)(self)
# Otherwise TensorVariable[:-1] does not work as Python 2.5.1 calls
# __len__ before calling __getitem__. It also does not catch the raised
# Exception!
# def __len__(self):
# # We can't implement __len__ as Python requests that this
# # function returns an integer >=0
# raise Exception("Theano Variables can't work with len(Theano "
# "Variable) due to Python restriction. You can use "
# "TheanoVariable.shape[0] instead.")
# def __len__(self):
# # We can't implement __len__ as Python requests that this
# # function returns an integer >=0
# raise Exception("Theano Variables can't work with len(Theano "
# "Variable) due to Python restriction. You can use "
# "TheanoVariable.shape[0] instead.")
defreshape(self,shape,ndim=None):
"""Return a reshaped view/copy of this variable.
:param shape: something that can be converted to a symbolic vector of integers
:param shape: something that can be converted to a symbolic vector of
integers
:param ndim: the length of the shape. Passing None here means for theano to try and
guess the length of `shape`.
:param ndim: the length of the shape. Passing None here means for
theano to try and guess the length of `shape`.
"""
returnreshape(self,shape,ndim=ndim)
defdimshuffle(self,*pattern):
"""Reorder the dimensions of this variable, optionally inserting broadcasted dimensions.
"""
Reorder the dimensions of this variable, optionally inserting
broadcasted dimensions.
:param pattern: list/tuple of int mixed with 'x' for broadcastable dimensions
:param pattern: list/tuple of int mixed with 'x' for broadcastable
dimensions
For example, to create a 3D view of a [2D] matrix, call ``dimshuffle([0,'x',1])``. This
will create a 3D view such that the middle dimension is an implicit broadcasted
dimension. To do the same thing on the transpose of that matrix, call ``dimshuffle([1,
'x', 0])``.
For example, to create a 3D view of a [2D] matrix, call
``dimshuffle([0,'x',1])``. This will create a 3D view such that the
middle dimension is an implicit broadcasted dimension. To do the same
thing on the transpose of that matrix, call
``dimshuffle([1, 'x', 0])``.
This function supports the pattern passed as a tuple, or as a variable-length argument (e.g. ``a.dimshuffle(pattern)`` is equivalent to ``a.dimshuffle(*pattern)`` where ``pattern`` is a list/tuple of ints mixed with 'x' characters).
This function supports the pattern passed as a tuple, or as a
variable-length argument (e.g. ``a.dimshuffle(pattern)`` is equivalent
to ``a.dimshuffle(*pattern)`` where ``pattern`` is a list/tuple of ints