1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use super::LRScheduler;
use crate::LearningRate;

/// Constant learning rate implementing [learning rate scheduler](LRScheduler).
///
/// # Notes
///
/// You can also use [learning rate](LearningRate) which the same effect.
#[derive(new, Clone, Debug)]
pub struct ConstantLR {
    lr: LearningRate,
}

impl From<LearningRate> for ConstantLR {
    fn from(lr: LearningRate) -> Self {
        Self { lr }
    }
}

impl LRScheduler for ConstantLR {
    type Record = ();

    fn step(&mut self) -> LearningRate {
        self.lr
    }

    fn to_record(&self) -> Self::Record {}

    fn load_record(self, _record: Self::Record) -> Self {
        self
    }
}

impl LRScheduler for LearningRate {
    type Record = ();

    fn step(&mut self) -> LearningRate {
        *self
    }

    fn to_record(&self) -> Self::Record {}

    fn load_record(self, _record: Self::Record) -> Self {
        self
    }
}