Skip to main content

score_set/
normalized_eval.rs

1use crate::traits::{EvalF32, EvalF64, Map01F32, Map01F64, Measure};
2
3/// An `f64` evaluator that measures a context and normalizes the result.
4pub struct NormalizedEval64<M, G> {
5    measure: M,
6    map: G,
7}
8
9impl<M, G> NormalizedEval64<M, G> {
10    /// Creates a normalized evaluator from a measurement and a map.
11    pub fn new(measure: M, map: G) -> Self {
12        Self { measure, map }
13    }
14}
15
16impl<Ctx, M, G> EvalF64<Ctx> for NormalizedEval64<M, G>
17where
18    Ctx: ?Sized,
19    M: Measure<Ctx>,
20    G: Map01F64<Input = M::Output>,
21{
22    #[inline]
23    fn eval(&self, ctx: &Ctx) -> f64 {
24        *self.map.map(self.measure.measure(ctx))
25    }
26}
27
28/// An `f32` evaluator that measures a context and normalizes the result.
29pub struct NormalizedEval32<M, G> {
30    measure: M,
31    map: G,
32}
33
34impl<M, G> NormalizedEval32<M, G> {
35    /// Creates a normalized evaluator from a measurement and a map.
36    pub fn new(measure: M, map: G) -> Self {
37        Self { measure, map }
38    }
39}
40
41impl<Ctx, M, G> EvalF32<Ctx> for NormalizedEval32<M, G>
42where
43    Ctx: ?Sized,
44    M: Measure<Ctx>,
45    G: Map01F32<Input = M::Output>,
46{
47    #[inline]
48    fn eval(&self, ctx: &Ctx) -> f32 {
49        *self.map.map(self.measure.measure(ctx))
50    }
51}