Skip to content

[JIT] Support range(start, stop[, step]) in script #18440

@jamesr66a

Description

@jamesr66a

This should work:

import torch

@torch.jit.script
def foo(x):
    for i in range(1, 10):
        x += float(i)
    return x

print(foo.code)

Right now it does this:

Traceback (most recent call last):
  File "param.py", line 3, in <module>
    @torch.jit.script
  File "/Users/jamesreed/onnx-fairseq/pytorch/torch/jit/__init__.py", line 739, in script
    _jit_script_compile(mod, ast, _rcb, get_default_args(obj))
RuntimeError:
range() expects 1 argument but got 2:
@torch.jit.script
def foo(x):
    for i in range(1, 10):
    ~~~~~~~~~~~~~~~~~~~~~~...  <--- HERE
        x += float(i)
    return x

Metadata

Metadata

Assignees

No one assigned

    Labels

    oncall: jitAdd this issue/PR to JIT oncall triage queue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions