add Tensor.log10 with test\test_ops.py::TestOps::test_log10 (#14113)

This commit is contained in:
C T
2026-01-12 20:45:47 +02:00
committed by GitHub
parent 6b0a9f5ee6
commit a8c821f45e
2 changed files with 16 additions and 0 deletions

View File

@@ -916,6 +916,10 @@ class TestOps(unittest.TestCase):
helper_test_op([(45,65)], torch.log, Tensor.log)
helper_test_op(None, torch.log, Tensor.log, vals=[[math.inf, -math.inf, math.nan]])
helper_test_op([()], torch.log, Tensor.log)
def test_log10(self):
helper_test_op([(45,65)], torch.log10, Tensor.log10)
helper_test_op(None, torch.log10, Tensor.log10, vals=[[math.inf, -math.inf, math.nan]])
helper_test_op([()], torch.log10, Tensor.log10)
def test_log2(self):
helper_test_op([(45,65)], torch.log2, Tensor.log2)
helper_test_op(None, torch.log2, Tensor.log2, vals=[[math.inf, -math.inf, math.nan]])

View File

@@ -2760,6 +2760,18 @@ class Tensor(OpMixin):
"""
return self.log2()*math.log(2)
def log10(self) -> Tensor:
"""
Computes the base-10 logarithm element-wise.
See: https://en.wikipedia.org/wiki/Logarithm
```python exec="true" source="above" session="tensor" result="python"
print(Tensor([1., 2., 4., 8.]).log10().numpy())
```
"""
return self.log2()*math.log10(2)
def log2(self) -> Tensor:
"""
Computes the base-2 logarithm element-wise.