Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/test_binary_ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,21 @@ def test_lerp_lowp_cpu(self, dtype):
expected = torch.lerp(xref, yref, wref).to(dtype)
self.assertEqual(actual, expected, atol=0.0, rtol=0.0)

def test_ldexp_backward_negative_exponent(self):
mantissa = torch.tensor([1.0], requires_grad=True)
exponent = torch.tensor([-1], dtype=torch.int32)

torch.ldexp(mantissa, exponent).sum().backward()

self.assertEqual(mantissa.grad, torch.tensor([0.5]))

with fwAD.dual_level():
mantissa_dual = fwAD.make_dual(torch.tensor([1.0]), torch.tensor([1.0]))
result = torch.ldexp(mantissa_dual, exponent)
_, result_tangent = fwAD.unpack_dual(result)

self.assertEqual(result_tangent, torch.tensor([0.5]))


class TestBinaryUfuncsDevice(TestCase):
# Generic tests for elementwise binary (AKA binary universal (u) functions (funcs))
Expand Down
4 changes: 2 additions & 2 deletions tools/autograd/derivatives.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,9 @@
values: gather_with_keepdimed_indices(self_t, dim, indices, keepdim)

- name: ldexp.Tensor(Tensor self, Tensor other) -> Tensor
self: grad * at::pow(2, other).conj()
self: grad * at::pow(2.0, other).conj()
other: grad * result.conj() * M_LN2
result: self_t * at::pow(2, other_p) + other_t * result * M_LN2
result: self_t * at::pow(2.0, other_p) + other_t * result * M_LN2

- name: le_.Scalar(Tensor(a!) self, Scalar other) -> Tensor(a!)
self: zeros_like(self)
Expand Down