Skip to content

torch.arange output shape  #21579

@ksanjeevan

Description

@ksanjeevan

📚 Documentation

As described here the output size of torch.arange is int((end-start)/step) (i.e. the floor). But it's the ceiling:

import torch
import numpy as np
def verify_out_shape(start, end, steps): 
    for s in steps: 
        dif = end-start 
        assert torch.arange(start, end, step=s).size(0) == np.ceil(dif/s)

verify_out_shape(1, 400, [0.5, 0.7, 0.3, 1.3])  
verify_out_shape(23, 731, [0.5, 0.7, 0.3, 1.3])  

Metadata

Metadata

Assignees

Labels

module: docsRelated to our documentation, both in docs/ and docblockstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions