29 #include "../../../../Eigen/src/Core/util/NonMPL2.h" 31 #ifndef EIGEN_CONSTRAINEDCG_H 32 #define EIGEN_CONSTRAINEDCG_H 46 template <
typename CMatrix,
typename CINVMatrix>
50 typedef typename CMatrix::Scalar Scalar;
55 Index rows = C.
rows(), cols = C.cols();
57 TmpVec
d(rows), e(rows), l(cols), p(rows),
q(rows), r(rows);
58 Scalar rho, rho_1, alpha;
62 std::vector<T> tripletList;
64 for (Index i = 0; i < rows; ++i)
75 l = C.transpose() * p;
77 alpha = rho / p.dot(
q);
82 p = (rho/rho_1) * p + r;
85 l = C.transpose() * e;
87 for (Index j=0; j<l.size(); ++j)
89 tripletList.push_back(T(i,j,l(j)));
94 CINV.setFromTriplets(tripletList.begin(), tripletList.end());
104 template<
typename TMatrix,
typename CMatrix,
105 typename VectorX,
typename VectorB,
typename VectorF>
110 typedef typename TMatrix::Scalar Scalar;
114 Scalar rho = 1.0, rho_1, lambda,
gamma;
115 Index xSize = x.size();
116 TmpVec p(xSize),
q(xSize), q2(xSize),
117 r(xSize), old_z(xSize),
z(xSize),
119 std::vector<bool> satured(C.rows());
135 bool transition =
false;
136 for (Index i = 0; i < C.rows(); ++i)
138 Scalar al = C.row(i).dot(x) - f.coeff(i);
146 Scalar bb = CINV.row(i).dot(
z);
149 for (
typename CMatrix::InnerIterator it(C,i); it; ++it)
150 z.coeffRef(it.index()) -= bb*it.value();
162 if (iter.
noiseLevel() > 0 && transition) std::cerr <<
"CCG: transition\n";
163 if (transition || iter.
first()) gamma = 0.0;
164 else gamma = (
std::max)(0.0, (rho - old_z.dot(
z)) / rho_1);
170 lambda = rho /
q.dot(p);
171 for (Index i = 0; i < C.rows(); ++i)
175 Scalar bb = C.row(i).dot(p) - f[i];
177 lambda = (std::min)(lambda, (f.coeff(i)-C.row(i).dot(x)) / bb);
189 #endif // EIGEN_CONSTRAINEDCG_H void pseudo_inverse(const CMatrix &C, CINVMatrix &CINV)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
void setRhsNorm(double r)
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() max(const half &a, const half &b)
const mpreal gamma(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
EIGEN_DEVICE_FUNC const Scalar & q
void constrained_cg(const TMatrix &A, const CMatrix &C, VectorX &x, const VectorB &b, const VectorF &f, IterationController &iter)
TFSIMD_FORCE_INLINE const tfScalar & z() const
A small structure to hold a non zero as a triplet (i,j,value).
Controls the iterations of the iterative solvers.
EIGEN_DEVICE_FUNC const Scalar & b