8 #include "parameter.hpp"
9 #include "variable.hpp"
11 #include <Eigen/Sparse>
17 struct NumTraits<cvx::Scalar>
29 RequireInitialization = 1,
41 class OptimizationProblem;
47 class SOCPWrapperBase;
58 bool operator==(
const Term &other)
const;
59 Term &operator*=(
const Parameter ¶m);
60 Term &operator/=(
const Parameter ¶m);
62 operator Affine()
const;
64 friend std::ostream &operator<<(std::ostream &os,
const Term &term);
65 double evaluate()
const;
71 bool operator==(
const Affine &other)
const;
73 Parameter constant = Parameter(0.);
74 std::vector<Term> terms;
76 friend std::ostream &operator<<(std::ostream &os,
const Affine &affine);
77 double evaluate()
const;
78 Affine &operator+=(
const Affine &other);
79 Affine &operator-=(
const Affine &other);
80 Affine &operator*=(
const Parameter ¶m);
81 Affine &operator/=(
const Parameter ¶m);
83 Affine operator-(
const Affine &other)
const;
84 Affine operator-()
const;
89 bool isConstant()
const;
90 bool isFirstOrder()
const;
96 explicit Product(
const Affine &term);
97 Product(
const Affine &lhs,
const Affine &rhs);
100 const Affine &firstTerm()
const;
101 const Affine &secondTerm()
const;
102 void toSquaredTerm();
103 double evaluate()
const;
104 bool isSquare()
const;
106 bool operator==(
const Product &other)
const;
108 friend std::ostream &operator<<(std::ostream &os,
const Product &product);
111 std::vector<Affine> factors;
122 explicit Scalar(
double *x);
136 double evaluate()
const;
137 size_t getOrder()
const;
141 friend internal::SOCPWrapperBase;
142 friend internal::QPWrapperBase;
144 explicit operator double()
const;
151 friend internal::Variable::operator
Scalar()
const;
159 internal::Affine affine;
160 std::vector<internal::Product> products;
163 friend std::ostream &operator<<(std::ostream &os,
const Scalar &scalar);
166 using MatrixX = Eigen::Matrix<cvx::Scalar, Eigen::Dynamic, Eigen::Dynamic>;
167 using VectorX = Eigen::Matrix<cvx::Scalar, Eigen::Dynamic, 1>;
196 template <
typename Derived>
197 inline auto par(
const Eigen::MatrixBase<Derived> &m)
199 return m.template cast<Scalar>().eval();
209 template <
typename Derived>
210 inline auto par(
const Eigen::SparseMatrixBase<Derived> &m)
212 return m.template cast<Scalar>().eval();
226 template <
typename Derived>
227 auto dynpar(Eigen::MatrixBase<Derived> &m)
229 auto result = m.template cast<Scalar>().eval();
231 for (
int row = 0; row < m.rows(); row++)
233 for (
int col = 0; col < m.cols(); col++)
235 result.coeffRef(row, col) =
dynpar(m.coeffRef(row, col));
253 template <
typename T>
256 auto result = m.template cast<Scalar>().eval();
258 for (
int k = 0; k < result.nonZeros(); k++)
260 result.valuePtr()[k] =
dynpar(m.valuePtr()[k]);
281 template <
typename Derived>
282 inline auto eval(
const Eigen::MatrixBase<Derived> &m)
284 return m.template cast<double>();
294 template <
typename Derived>
295 inline auto eval(
const Eigen::SparseMatrixBase<Derived> &m)
297 return m.template cast<double>();
300 inline const Scalar &conj(
const Scalar &x) {
return x; }
301 inline const Scalar &real(
const Scalar &x) {
return x; }
302 inline Scalar imag(
const Scalar &) {
return Scalar(0.); }
303 inline Scalar square(
const Scalar &x)
306 new_scalar.products = {internal::Product(x.affine)};
309 inline Scalar abs2(
const Scalar &x)