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

feat: Add percentile function to tensorlib #817

Merged
merged 35 commits into from
Nov 11, 2021
Merged

Conversation

matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented Apr 5, 2020

Description

Add a percentile function to the tensor backends that adheres to NumPy's numpy.percentile API.

To get quotation marks to look okay for the interpolation method section of the docstrings I used \\ to escape them given this Stack Overflow question. There may be a better way.

Docs build at: https://pyhf--817.org.readthedocs.build/en/817/api.html#backends

Checklist Before Requesting Reviewer

  • Tests are passing
  • "WIP" removed from the title of the pull request
  • Selected an Assignee for the PR to be responsible for the log summary

Before Merging

For the PR Assignees:

  • Summarize commit messages into a comprehensive review of the PR
* Add percentile function to the tensor backends
* Add tests for percentile and its interpolation methods
   - JAX requires additional dtype support with the 'linear' interpolation method
     c.f. https://github.com/google/jax/issues/8513
   - PyTorch has yet to implement interpolation method options
   - c.f. https://github.com/scikit-hep/pyhf/issues/1693

@matthewfeickert matthewfeickert added feat/enhancement New feature or request tests pytest labels Apr 5, 2020
@matthewfeickert matthewfeickert self-assigned this Apr 5, 2020
@codecov
Copy link

codecov bot commented Apr 5, 2020

Codecov Report

Merging #817 (eee1d30) into master (902052f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #817   +/-   ##
=======================================
  Coverage   98.05%   98.05%           
=======================================
  Files          64       64           
  Lines        4212     4220    +8     
  Branches      587      587           
=======================================
+ Hits         4130     4138    +8     
  Misses         49       49           
  Partials       33       33           
Flag Coverage Δ
contrib 25.35% <50.00%> (+0.04%) ⬆️
doctest 61.13% <100.00%> (+0.07%) ⬆️
unittests 96.37% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/pyhf/tensor/jax_backend.py 97.12% <100.00%> (+0.04%) ⬆️
src/pyhf/tensor/numpy_backend.py 98.49% <100.00%> (+0.02%) ⬆️
src/pyhf/tensor/pytorch_backend.py 98.43% <100.00%> (+0.02%) ⬆️
src/pyhf/tensor/tensorflow_backend.py 97.26% <100.00%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 902052f...eee1d30. Read the comment docs.

@matthewfeickert
Copy link
Member Author

Note to self: Should give more information in docstrings of interpolation methods and note what is the default interpolation method ("linear").


"""
# Interpolation options not yet supported
# c.f. https://github.com/pytorch/pytorch/issues/38349
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be out with pytorch/pytorch#48523 being done?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sadly. I just keep rebasing these PRs so that they don't fall too far behind and make it harder later on.

@matthewfeickert matthewfeickert added API Changes the public API docs Documentation related labels Nov 11, 2021
@matthewfeickert matthewfeickert marked this pull request as ready for review November 11, 2021 04:13
Comment on lines +386 to +388
@pytest.mark.skip_pytorch
@pytest.mark.skip_pytorch64
@pytest.mark.skip_jax
Copy link
Member Author

@matthewfeickert matthewfeickert Nov 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipping PyTorch as interpolation kwargs aren't implemented yet as of torch v1.10.0. c.f. #815 (comment)

Skipping JAX so as to have separate test below given floating point issues with "linear" option.

assert tb.tolist(tb.percentile(a, 50, interpolation="higher")) == 4.0


@pytest.mark.only_jax
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully these tests are tolerable at the moment, though obviously not ideal.

@matthewfeickert
Copy link
Member Author

RE: the deviations seen for JAX compared to all other backends, I opened up jax-ml/jax#8513.

@matthewfeickert
Copy link
Member Author

Issue #1693 exists to monitor the PyTorch and JAX issues, so this can PR can move forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Changes the public API docs Documentation related feat/enhancement New feature or request tests pytest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking of TensorFlow and Python 3.9 harmonization Add a percentile function to tensorlib
2 participants