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
// Copyright 2018 Stefan Kroboth
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use crate::{ArgminOp, Error};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;

#[derive(Clone, Default, Debug, Serialize, Deserialize)]
pub struct NoOperator<T, U, H>
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,
{
    param: std::marker::PhantomData<T>,
    output: std::marker::PhantomData<U>,
    hessian: std::marker::PhantomData<H>,
}

impl<T, U, H> NoOperator<T, U, H>
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,
{
    #[allow(dead_code)]
    pub fn new() -> Self {
        NoOperator {
            param: std::marker::PhantomData,
            output: std::marker::PhantomData,
            hessian: std::marker::PhantomData,
        }
    }
}

impl<T, U, H> ArgminOp for NoOperator<T, U, H>
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,
{
    type Param = T;
    type Output = U;
    type Hessian = H;

    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)]
pub struct MinimalNoOperator {}

impl MinimalNoOperator {
    #[allow(dead_code)]
    pub fn new() -> Self {
        MinimalNoOperator {}
    }
}

impl ArgminOp for MinimalNoOperator {
    type Param = Vec<f64>;
    type Output = f64;
    type Hessian = Vec<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!()
    }
}