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

Use new APIs added in PyTorch v1.8.0 #1349

Closed
matthewfeickert opened this issue Mar 5, 2021 · 0 comments · Fixed by #1354
Closed

Use new APIs added in PyTorch v1.8.0 #1349

matthewfeickert opened this issue Mar 5, 2021 · 0 comments · Fixed by #1354
Assignees
Labels
good first issue Good for newcomers refactor A code change that neither fixes a bug nor adds a feature
Projects

Comments

@matthewfeickert
Copy link
Member

Description

In PyTorch v1.8.0 in the Python API section under "New features" there is the addition of torch.ravel (pytorch/pytorch#46098) and torch.tile (pytorch/pytorch#47974) to the public API. These should be adopted for the torch backend.

Currently we use

def ravel(self, tensor):
"""
Return a flattened view of the tensor, not a copy.
Example:
>>> import pyhf
>>> pyhf.set_backend("pytorch")
>>> tensor = pyhf.tensorlib.astensor([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
>>> pyhf.tensorlib.ravel(tensor)
tensor([1., 2., 3., 4., 5., 6.])
Args:
tensor (Tensor): Tensor object
Returns:
`torch.Tensor`: A flattened array.
"""
return tensor.view(-1)

and

def tile(self, tensor_in, repeats):
"""
Repeat tensor data along a specific dimension
Example:
>>> import pyhf
>>> pyhf.set_backend("pytorch")
>>> a = pyhf.tensorlib.astensor([[1.0], [2.0]])
>>> pyhf.tensorlib.tile(a, (1, 2))
tensor([[1., 1.],
[2., 2.]])
Args:
tensor_in (:obj:`tensor`): The tensor to be repeated
repeats (:obj:`tensor`): The tuple of multipliers for each dimension
Returns:
PyTorch tensor: The tensor with repeated axes
"""
return tensor_in.repeat(repeats)

@matthewfeickert matthewfeickert added good first issue Good for newcomers refactor A code change that neither fixes a bug nor adds a feature labels Mar 5, 2021
@matthewfeickert matthewfeickert added this to To do in v0.6.1 via automation Mar 5, 2021
@matthewfeickert matthewfeickert self-assigned this Mar 5, 2021
v0.6.1 automation moved this from To do to Done Mar 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers refactor A code change that neither fixes a bug nor adds a feature
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

1 participant