-
Notifications
You must be signed in to change notification settings - Fork 0
/
scaling.rs
44 lines (35 loc) · 1 KB
/
scaling.rs
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
use geometry::{Space, Card};
use projectors::{Projector, Projection};
use rand::ThreadRng;
use std::marker::PhantomData;
pub struct Scale<I: ?Sized, P: Projector<I>> {
scale: f64,
projector: P,
phantom: PhantomData<I>,
}
impl<I: ?Sized, P: Projector<I>> Scale<I, P> {
pub fn new(scale: f64, projector: P) -> Self {
Scale {
scale: scale,
projector: projector,
phantom: PhantomData,
}
}
}
impl<I: ?Sized, P: Projector<I>> Space for Scale<I, P> {
type Value = Projection;
fn sample(&self, rng: &mut ThreadRng) -> Projection {
Projection::Dense(self.projector.sample(rng).expanded(self.dim()) * self.scale)
}
fn dim(&self) -> usize {
self.projector.dim()
}
fn card(&self) -> Card {
self.projector.card()
}
}
impl<I: ?Sized, P: Projector<I>> Projector<I> for Scale<I, P> {
fn project(&self, input: &I) -> Projection {
Projection::Dense(self.scale * self.project_expanded(input))
}
}