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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use crate::{ArgminOp, Error};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Display};
#[derive(
Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Hash, Copy,
)]
pub struct NoOperator<T, U, H, J> {
param: std::marker::PhantomData<T>,
output: std::marker::PhantomData<U>,
hessian: std::marker::PhantomData<H>,
jacobian: std::marker::PhantomData<J>,
}
impl<T, U, H, J> NoOperator<T, U, H, J> {
#[allow(dead_code)]
pub fn new() -> Self {
NoOperator {
param: std::marker::PhantomData,
output: std::marker::PhantomData,
hessian: std::marker::PhantomData,
jacobian: std::marker::PhantomData,
}
}
}
impl<T, U, H, J> Display for NoOperator<T, U, H, J> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "NoOperator")
}
}
impl<T, U, H, J> ArgminOp for NoOperator<T, U, H, J>
where
T: Clone + Default + Debug + Send + Sync + Serialize + DeserializeOwned,
U: Clone + Default + Debug + Send + Sync + Serialize + DeserializeOwned,
H: Clone + Default + Debug + Send + Sync + Serialize + DeserializeOwned,
J: Clone + Default + Debug + Send + Sync + Serialize + DeserializeOwned,
{
type Param = T;
type Output = U;
type Hessian = H;
type Jacobian = J;
fn apply(&self, _p: &Self::Param) -> Result<Self::Output, Error> {
Ok(Self::Output::default())
}
fn gradient(&self, _p: &Self::Param) -> Result<Self::Param, Error> {
Ok(Self::Param::default())
}
fn hessian(&self, _p: &Self::Param) -> Result<Self::Hessian, Error> {
Ok(Self::Hessian::default())
}
fn modify(&self, _p: &Self::Param, _t: f64) -> Result<Self::Param, Error> {
Ok(Self::Param::default())
}
}
#[derive(
Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Hash, Copy,
)]
pub struct MinimalNoOperator {}
impl MinimalNoOperator {
#[allow(dead_code)]
pub fn new() -> Self {
MinimalNoOperator {}
}
}
impl Display for MinimalNoOperator {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "MinimalNoOperator")
}
}
impl ArgminOp for MinimalNoOperator {
type Param = Vec<f64>;
type Output = f64;
type Hessian = Vec<Vec<f64>>;
type Jacobian = Vec<f64>;
fn apply(&self, _p: &Self::Param) -> Result<Self::Output, Error> {
unimplemented!()
}
fn gradient(&self, _p: &Self::Param) -> Result<Self::Param, Error> {
unimplemented!()
}
fn hessian(&self, _p: &Self::Param) -> Result<Self::Hessian, Error> {
unimplemented!()
}
fn modify(&self, _p: &Self::Param, _t: f64) -> Result<Self::Param, Error> {
unimplemented!()
}
}