提交 f4063b2f 编写于 作者: HansBug's avatar HansBug 😆

dev, test, doc(hansbug): add Tensor.sign_

上级 b9f0c0bc
......@@ -435,6 +435,26 @@ class TestTorchTensor:
[0, -1]]},
})).all()
@choose_mark()
def test_sign_(self):
t1 = ttorch.tensor([12, 0, -3])
t1r = t1.sign_()
assert t1r is t1
assert isinstance(t1, torch.Tensor)
assert (t1 == ttorch.tensor([1, 0, -1])).all()
t2 = ttorch.tensor({
'a': [12, 0, -3],
'b': {'x': [[-3, 1], [0, -2]]},
})
t2r = t2.sign_()
assert t2r is t2
assert (t2 == ttorch.tensor({
'a': [1, 0, -1],
'b': {'x': [[-1, 1],
[0, -1]]},
})).all()
@choose_mark()
def test_round(self):
t1 = ttorch.tensor([[1.2, -1.8], [-2.3, 2.8]]).round()
......
......@@ -363,6 +363,15 @@ class Tensor(Torch, metaclass=clsmeta(_to_tensor, allow_dict=True)):
"""
return self.sign(*args, **kwargs)
@doc_from_base()
@return_self
@method_treelize()
def sign_(self, *args, **kwargs):
"""
In-place version of :meth:`Tensor.sign`.
"""
return self.sign_(*args, **kwargs)
@doc_from_base()
@method_treelize()
def sigmoid(self, *args, **kwargs):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册