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

Validators/permissive multiples #852

Merged
merged 10 commits into from Nov 7, 2017

Conversation

WilliamHPNielsen
Copy link
Contributor

Fixes #765

Changes proposed in this pull request:

  • Add a validator for non-integer multiples of a base value
  • Add a test (@AdriaanRol, perhaps you can think of more/better corner cases?)

The new validator, PermissiveMultiples allows integer multiples of a given base value to slip through. It allows negative multiples as well, and therefore by definition always 0. It is subject to rounding errors, so a user-specificied absolute precision is in principle required.

@jenshnielsen

print(div, mult)
val.validate(mult)

# finally, a quick test that the precision is indeed setable
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Woops... nice catch.

divs = int(divmod(value, self.divisor)[0])
true_vals = np.array([n*self.divisor for n in range(divs, divs+2)])
abs_errs = [abs(tv-value) for tv in true_vals]
if min(abs_errs) > self.precision:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this have a relative tolerance too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mimicking np.allclose? I am a bit undecided. I think for most cases it will suffice to say "be precise to within 0.5 nV".

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes as long as people are not using "strange" units its fine, we can always add later if needed

@jenshnielsen
Copy link
Collaborator

2 Inline comments otherwise looks good

Copy link
Collaborator

@jenshnielsen jenshnielsen left a comment

Choose a reason for hiding this comment

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

Just waiting for travis

@WilliamHPNielsen WilliamHPNielsen merged commit 8b258ad into master Nov 7, 2017
@WilliamHPNielsen WilliamHPNielsen deleted the validators/PermissiveMultiples branch November 7, 2017 09:26
giulioungaretti pushed a commit that referenced this pull request Nov 7, 2017
Author: William H.P. Nielsen <whpn@mailbox.org>

    Validators/permissive multiples (#852)
giulioungaretti pushed a commit that referenced this pull request Nov 7, 2017
Author: William H.P. Nielsen <whpn@mailbox.org>

    Validators/permissive multiples (#852)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants