Commit Graph

6 Commits

Author SHA1 Message Date
Jane Xu
2aa0ba38a4 Make is_sparse a property of MaskedTensor (#110725)
Fixes #104574

Seeing that MaskedTensor is a prototype, the BC breaking nature of this change seems okay?

Locally tested:
<img width="1372" alt="image" src="https://github.com/pytorch/pytorch/assets/31798555/239e61ba-e0b9-4909-8c7a-0ce3869d7375">

Pull Request resolved: https://github.com/pytorch/pytorch/pull/110725
Approved by: https://github.com/cpuhrsch
2023-10-09 22:35:38 +00:00
Tom Stein
fd60b818b9 [Python] refactor slices on sorted (#86995)
Sometimes you want to query the small element of a set of elements and use `sorted(elements)[0]` without a second thought. However, this is not optimal, since the entire list must be sorted first `O(n log n)`. It would be better to use the `min(elements)` method provided for this purpose `O(n)`.
Furthermore `sorted(elements)[::-1]` is not very efficient, because it would be better to use `sorted(elements, reverse=True)` to save the slice operation.

**TLDR: using `sorted(elements)[0]` is slow and can be replaced with `min(elements)`.**

I stumbled across these code snippets while playing around with CodeQL (see https://lgtm.com/query/4148064474379348546/).
Pull Request resolved: https://github.com/pytorch/pytorch/pull/86995
Approved by: https://github.com/jansel
2022-10-25 04:07:19 +00:00
George Qi
686555b663 [maskedtensor] port torch/_masked into torch/masked (#85515)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85515
Approved by: https://github.com/cpuhrsch
2022-09-26 23:41:13 +00:00
George Qi
e3766e9855 [maskedtensor] move __torch_function/dispatch__ functions to a map (#85529)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85529
Approved by: https://github.com/bhosmer
2022-09-23 18:31:20 +00:00
George Qi
0c46e3ec66 [maskedtensor] add basic tests and unary/binary/reduction tests from common_method_invocations (#82841)
Decided offline on the invariant that:

`masked_tensor` calls `MaskedTensor()`, which is analogous to `torch.tensor`
`as_masked_tensor` calls `MaskedTensor._from_values()`, which is analogous to `torch.as_tensor`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/82841
Approved by: https://github.com/cpuhrsch, https://github.com/bhosmer
2022-09-22 07:37:04 +00:00
George Qi
5e9c26c8e2 [maskedtensor] adding reductions (#82839)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/82839
Approved by: https://github.com/bhosmer
2022-09-06 15:01:35 +00:00