L1Norm.cpp 1.66 KB
Newer Older
Tobias Lasser's avatar
Tobias Lasser committed
1
2
3
4
5
6
7
8
9
#include "L1Norm.h"

#include <stdexcept>

namespace elsa
{
    template <typename data_t>
    L1Norm<data_t>::L1Norm(const DataDescriptor& domainDescriptor)
        : Functional<data_t>(domainDescriptor)
Jens Petit's avatar
Jens Petit committed
10
11
    {
    }
Tobias Lasser's avatar
Tobias Lasser committed
12
13

    template <typename data_t>
Jens Petit's avatar
Jens Petit committed
14
15
16
    L1Norm<data_t>::L1Norm(const Residual<data_t>& residual) : Functional<data_t>(residual)
    {
    }
Tobias Lasser's avatar
Tobias Lasser committed
17
18

    template <typename data_t>
19
    data_t L1Norm<data_t>::evaluateImpl(const DataContainer<data_t>& Rx)
Tobias Lasser's avatar
Tobias Lasser committed
20
21
22
23
24
    {
        return Rx.l1Norm();
    }

    template <typename data_t>
25
    void L1Norm<data_t>::getGradientInPlaceImpl([[maybe_unused]] DataContainer<data_t>& Rx)
Tobias Lasser's avatar
Tobias Lasser committed
26
27
28
29
30
    {
        throw std::logic_error("L1Norm: not differentiable, so no gradient! (busted!)");
    }

    template <typename data_t>
31
32
    LinearOperator<data_t>
        L1Norm<data_t>::getHessianImpl([[maybe_unused]] const DataContainer<data_t>& Rx)
Tobias Lasser's avatar
Tobias Lasser committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    {
        throw std::logic_error("L1Norm: not differentiable, so no Hessian! (busted!)");
    }

    template <typename data_t>
    L1Norm<data_t>* L1Norm<data_t>::cloneImpl() const
    {
        return new L1Norm(this->getResidual());
    }

    template <typename data_t>
    bool L1Norm<data_t>::isEqual(const Functional<data_t>& other) const
    {
        if (!Functional<data_t>::isEqual(other))
            return false;

        auto otherL1Norm = dynamic_cast<const L1Norm*>(&other);
Jens Petit's avatar
Jens Petit committed
50
        return static_cast<bool>(otherL1Norm);
Tobias Lasser's avatar
Tobias Lasser committed
51
52
53
54
55
56
57
58
59
60
    }

    // ------------------------------------------
    // explicit template instantiation
    template class L1Norm<float>;
    template class L1Norm<double>;
    template class L1Norm<std::complex<float>>;
    template class L1Norm<std::complex<double>>;

} // namespace elsa