提交 f359ff99 authored 作者: Tanjay94's avatar Tanjay94

Added str method to Op class.

上级 a8fb84fb
......@@ -581,6 +581,12 @@ class Op(utils.object2, PureOp, CLinkerOp):
else:
return super(Op, self).__hash__()
def __str__(self):
if hasattr(self, 'props'):
return self.__class__.__name__
else:
return super(Op, self).__str__()
def __eq__(self, other):
if hasattr(self, 'props'):
return (type(self) == type(other) and self.props() == other.props())
......
......@@ -50,9 +50,6 @@ class MatrixPinv(Op):
def perform(self, node, (x,), (z, )):
z[0] = numpy.linalg.pinv(x).astype(x.dtype)
def __str__(self):
return "MatrixPseudoInverse"
pinv = MatrixPinv()
......@@ -125,9 +122,6 @@ class MatrixInverse(Op):
return [None]
return [-matrix_dot(xi, ev, xi)]
def __str__(self):
return "MatrixInverse"
matrix_inverse = MatrixInverse()
......@@ -326,9 +320,6 @@ class Eig(Op):
n = shapes[0][0]
return [(n,), (n, n)]
def __str__(self):
return self._numop.__name__.capitalize()
eig = Eig()
......@@ -343,9 +334,6 @@ class Eigh(Eig):
assert UPLO in ['L', 'U']
self.UPLO = UPLO
def __str__(self):
return 'Eigh{%s}' % self.UPLO
def props(self):
return self.UPLO,
......@@ -422,9 +410,6 @@ class EighGrad(Op):
def props(self):
return (self.UPLO,)
def __str__(self):
return 'EighGrad{%s}' % self.UPLO
def make_node(self, x, w, v, gw, gv):
x, w, v, gw, gv = map(as_tensor_variable, (x, w, v, gw, gv))
assert x.ndim == 2
......@@ -503,9 +488,6 @@ class QRFull(Op):
q[0], r[0] = self._numop(x,
self.mode)
def __str__(self):
return self._numop.__class__.__name__
class QRIncomplete(Op):
"""
......@@ -532,9 +514,6 @@ class QRIncomplete(Op):
q[0] = self._numop(x,
self.mode)
def __str__(self):
return self._numop.__class__.__name__
def qr(a, mode="full"):
"""
......@@ -625,9 +604,6 @@ class SVD(Op):
self.full_matrices,
self.compute_uv)
def __str__(self):
return self._numop.__name__.capitalize()
def svd(a, full_matrices=1, compute_uv=1):
"""
......
......@@ -53,17 +53,6 @@ class Cholesky(Op):
def infer_shape(self, node, shapes):
return [shapes[0]]
def __str__(self):
if self.lower:
lu = 'lower'
else:
lu = 'upper'
if self.destructive:
destr = 'destructive'
else:
destr = 'non-destructive'
return 'Cholesky{%s,%s}' % (lu, destr)
def make_node(self, x):
assert imported_scipy, (
"Scipy not available. Scipy is needed for the Cholesky op")
......@@ -94,17 +83,6 @@ class CholeskyGrad(Op):
return (self.lower,
self.destructive)
def __str__(self):
if self.lower:
lu = 'lower'
else:
lu = 'upper'
if self.destructive:
destr = 'destructive'
else:
destr = 'non-destructive'
return 'CholeskyGrad{%s,%s}' % (lu, destr)
def make_node(self, x, l, dz):
x = as_tensor_variable(x)
l = as_tensor_variable(l)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论