Skip to main content

Tensor operations with mask for PyTorch.

Project description

torchmasked

Tensor operations with mask for PyTorch.

Sometimes you need to perform operations on tensors with the masked elements been ignored, for example:

>>> input = torch.tensor([1., 2., 3.])
>>> result = torch.sum(input)
>>> print(result)

tensor(6.)

>>> mask = torch.tensor([1, 1, 0]).byte()
>>> masked_result = torchmasked.masked_sum(input, mask)
>>> print(masked_result)

tensor(3.)  # element input[2] is masked and ignored

Then this package could be helpful.

 

Installation

From source:

pip install git+https://github.com/Renovamen/torchmasked.git --upgrade

# or

python setup.py install

 

Supported Operations

  • max (masked version of torch.max)
  • min (torch.min)
  • sum (torch.sum)
  • mean (torch.mean)
  • softmax (torch.nn.functional.softmax and torch.nn.Softmax)

 

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchmasked-0.1.0.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

torchmasked-0.1.0-py3-none-any.whl (4.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page