norm.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #ifndef CASADI_NORM_HPP
27 #define CASADI_NORM_HPP
28 
29 #include "mx_node.hpp"
30 
32 namespace casadi {
33 
40  class CASADI_EXPORT Norm : public MXNode {
41  public:
42 
46  explicit Norm(const MX& x);
47 
51  ~Norm() override {}
52 
53  protected:
57  explicit Norm(DeserializingStream& s) : MXNode(s) {}
58  };
59 
66  class CASADI_EXPORT NormF : public Norm {
67  public:
68 
72  explicit NormF(const MX& x) : Norm(x) {}
73 
77  ~NormF() override {}
78 
80  template<typename T>
81  int eval_gen(const T** arg, T** res, casadi_int* iw, T* w) const;
82 
84  int eval(const double** arg, double** res, casadi_int* iw, double* w) const override;
85 
87  int eval_sx(const SXElem** arg, SXElem** res, casadi_int* iw, SXElem* w) const override;
88 
92  void eval_mx(const std::vector<MX>& arg, std::vector<MX>& res) const override;
93 
97  void ad_forward(const std::vector<std::vector<MX> >& fseed,
98  std::vector<std::vector<MX> >& fsens) const override;
99 
103  void ad_reverse(const std::vector<std::vector<MX> >& aseed,
104  std::vector<std::vector<MX> >& asens) const override;
105 
109  void generate(CodeGenerator& g,
110  const std::vector<casadi_int>& arg,
111  const std::vector<casadi_int>& res) const override;
112 
116  std::string disp(const std::vector<std::string>& arg) const override;
117 
121  casadi_int op() const override { return OP_NORMF;}
122 
126  static MXNode* deserialize(DeserializingStream& s) { return new NormF(s); }
127 
128  protected:
132  explicit NormF(DeserializingStream& s) : Norm(s) {}
133  };
134 
141  class CASADI_EXPORT Norm2 : public Norm {
142  public:
143 
147  explicit Norm2(const MX& x): Norm(x) {}
148 
152  ~Norm2() override {}
153 
157  std::string disp(const std::vector<std::string>& arg) const override;
158 
162  casadi_int op() const override { return OP_NORM2;}
163 
167  static MXNode* deserialize(DeserializingStream& s) { return new Norm2(s); }
168 
169  protected:
173  explicit Norm2(DeserializingStream& s) : Norm(s) {}
174  };
175 
182  class CASADI_EXPORT Norm1 : public Norm {
183  public:
184 
188  explicit Norm1(const MX& x) : Norm(x) {}
189 
193  ~Norm1() override {}
194 
198  std::string disp(const std::vector<std::string>& arg) const override;
199 
203  casadi_int op() const override { return OP_NORM1;}
204 
208  static MXNode* deserialize(DeserializingStream& s) { return new Norm1(s); }
209 
210  protected:
214  explicit Norm1(DeserializingStream& s) : Norm(s) {}
215  };
216 
223  class CASADI_EXPORT NormInf : public Norm {
224  public:
225 
229  explicit NormInf(const MX& x) : Norm(x) {}
230 
234  ~NormInf() override {}
235 
239  std::string disp(const std::vector<std::string>& arg) const override;
240 
244  casadi_int op() const override { return OP_NORMINF;}
245 
249  static MXNode* deserialize(DeserializingStream& s) { return new NormInf(s); }
250 
251  protected:
255  explicit NormInf(DeserializingStream& s) : Norm(s) {}
256  };
257 
258 } // namespace casadi
259 
261 
262 #endif // CASADI_NORM_HPP
The casadi namespace.