Skip to content

Should torch.reshape support integer shape? #28

Closed
@thomasjpfan

Description

@thomasjpfan

torch.reshape requires an tuple as the shape:

import torch
import array_api_compat 

x = torch.asarray([1.0, 2.0])
xp = array_api_compat.get_namespace(x)

# works
xp.reshape(x, (-1,))

xp.reshape(x, -1)
# TypeError: reshape(): argument 'shape' (position 2) must be tuple of ints, not int

Note that integer shape works with numpy.array_api:

import numpy.array_api as np
import array_api_compat 

x = np.asarray([1.0, 2.0])
xp = array_api_compat.get_namespace(x)

xp.reshape(x, -1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions