Add fns Uniform::min, max using trait UniformSamplerRange#1775
Conversation
| for &(low, high) in $v.iter() { | ||
| let my_uniform = Uniform::new(low, high).unwrap(); | ||
| assert_eq!(my_uniform.min(), low); | ||
| // assert_eq!(my_uniform.max(), high - 1); |
There was a problem hiding this comment.
Because the macro input uses both integers and Simd values. We'd need a generic Simd::splat supporting both... possible, but not in std I think so we'd need extra utility code (I started on this before deciding it's probably better not to increase the code size without good reason).
If we only implement these on
|
|
Given the low interest I guess I'll just close this (it's not an essential addition). |
CHANGELOG.mdentrySummary
Add fns
Uniform::min, maxusing traitUniformSamplerRangeMotivation
I wanted
Uniform::maxand realised it's simple enough to add.Note: some
rand_distrdistribution objects already support querying parameters (example).Details
trait UniformSamplerRange: UniformSampleris an extension-trait, adding optional support forminandmax. This doesn't technically need theUniformSampler, though we do used its assoc. typeX.We could use a more generic name (like
HasRangeBoundsorHasMinandHasMaxtraits), butUniformSamplerRangefits in nicely (given the bound).Adds
min,maxfns onUniformfor types supportingUniformSamplerRange.Implements
UniformSamplerRangeforUniformIntsamplers only.I looked briefly at the other samplers and we certainly could implement these too, but code is less trivial. In particular,
UniformCharwould involve duplicatingunsafecode. I suggest we leave these off for now and see if anyone else requests them.