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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use *;
use *;
/*
nalgebra conventions:
<algorithm>.<opname>(&input) -> owned_output Takes a reference to self and a reference to the input and
provides a newly-allocated output (perhaps cloning input and applying the op in-place to the cloned data)
<algorithm>.<opname_mut>(&mut output) Takes a reference to self (which holds the domain) and outputs
the result to the informed pre-allocated buffer.
Use Option for fallible operations because usually those algorithms can fail in a single
way (buffer size is not sufficient).
The difference is that instead of returning owned_output, we return &output for the operations,
since we always assume the existence of a pre-allocated buffer inside the structure that is the
destination of the operation.
We add the following convention: forward_from(.) and backward_from(.) modify the internal
buffers from an external reference.
*/
/*/// Implemented by forward-transform algorithms (FFT, DWT), which modify
/// their internal state by calculating the forward transform from src,
/// and which allows reading the updated coefficients via coefficients(.)
/// and coefficients_mut(.). The coefficients are stored at a generic container
/// C, defined by the implementation.
pub trait Forward<'a, D, C>
where
Self : Sized + 'a,
// C : Clone + 'a
{
/// Apply the forward transform from buffer src into Self, updating its coefficients.
fn forward_from(&'a mut self, src : &D) -> &'a C;
/// Iterate over eigenvalues of the decomposition (PCA/LDA) or over
/// complex coefficients at a vector or matrix (FFT) or over the real
/// coefficient windows (DWT). Returns single result for PCA/LDA (Option).
/// Return groups of coefficients for splines, depending on the region
/// the spline is centered at (Vec).
fn coefficients(&'a self) -> &'a C;
fn coefficients_mut(&'a mut self) -> &'a mut C;
// This should consume the structure and return its coefficients.
// fn take_coefficients(self) -> C;
}
/// Implemented by backward-transform algorithms (IFFT,IDWT),
/// which modify the destination buffer from the inverse transform
/// applied to the data carried into Self. The original domain is written
/// into a generic container D, defined by the implementation.
pub trait Backward<'a, D, C>
where
Self : Forward<'a, D, C> + Sized
{
fn backward_from(&'a mut self, coefs : &'a C) -> Option<&'a D>;
fn backward_from_self(&'a mut self) -> Option<&'a D>;
fn take_domain(&mut self) -> Option<D>;
fn domain(&'a self) -> Option<&'a D>;
fn domain_mut(&'a mut self) -> Option<&'a mut D>;
/// Apply the backward transform into original buffer dst.
fn backward_mut(&'a self, dst : &'a mut D);
// fn backward(&self) -> D {
// let mut dom = self.domain().clone();
// self.backward_mut(&mut dom);
// dom
// }
}*/