Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix aten.logspace decomposition #105201

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/test_prims.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,16 @@ def test_unbind(self):
expect = torch.unbind(a, 1)
self.assertEqual(actual, expect)

def test_logspace_with_complex_input(self):
actual = refs.logspace(2, 10 + 5j, steps=5)
expect = torch.logspace(2, 10 + 5j, steps=5)
self.assertEqual(actual, expect)

def test_linspace_with_complex_input(self):
actual = refs.linspace(2, 10 + 5j, steps=5)
expect = torch.linspace(2, 10 + 5j, steps=5)
self.assertEqual(actual, expect)
yanboliang marked this conversation as resolved.
Show resolved Hide resolved


instantiate_device_type_tests(TestRefs, globals())

Expand Down
15 changes: 12 additions & 3 deletions torch/_refs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4619,20 +4619,29 @@ def logspace(
if isinstance(end, FloatLike):
end = sym_int(end)

if py_any(isinstance(arg, complex) for arg in (start, end, steps)):
default_complex_dtype = utils.corresponding_complex_dtype(
torch.get_default_dtype()
)
dtype = default_complex_dtype
_dtype = None # torch.linspace will update the correct dtype
yanboliang marked this conversation as resolved.
Show resolved Hide resolved
else:
_dtype = torch.float64

assert not isinstance(base, complex) # for mypy
if base < 0:
raise NotImplementedError
ret = torch.linspace(
ret = torch.linspace( # type: ignore[misc]
start,
end,
steps, # type: ignore[arg-type]
dtype=torch.float64,
dtype=_dtype,
layout=layout,
device=device,
pin_memory=pin_memory,
requires_grad=requires_grad,
)
return _maybe_convert_to_dtype(torch.pow(base, ret), dtype)
return _maybe_convert_to_dtype(torch.pow(base, ret), dtype) # type: ignore[arg-type,return-value]


@overload
Expand Down
4 changes: 2 additions & 2 deletions torch/testing/_internal/common_methods_invocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ def sample_inputs_linspace(op, device, dtype, requires_grad, **kwargs):
yield SampleInput(1, args=(3, 1))


def sample_inputs_logpace(op, device, dtype, requires_grad, **kwargs):
def sample_inputs_logspace(op, device, dtype, requires_grad, **kwargs):
ends = (-3, 0, 1.2, 2, 4)
starts = (-2., 0, 1, 2, 4.3)
nsteps = (0, 1, 2, 4)
Expand Down Expand Up @@ -11149,7 +11149,7 @@ def reference_flatten(input, start_dim=0, end_dim=-1):
supports_out=True,
supports_autograd=False,
error_inputs_func=error_inputs_linspace,
sample_inputs_func=sample_inputs_logpace,
sample_inputs_func=sample_inputs_logspace,
skips=(
# Tests that assume input is a tensor or sequence of tensors
DecorateInfo(unittest.expectedFailure, 'TestCommon', 'test_variant_consistency_eager'),
Expand Down