#include <codi.hpp>
#include <iostream>
#if CODI_EnableEigen
template<typename T>
using Matrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
template<typename T>
using Vector = Eigen::Matrix<T, Eigen::Dynamic, 1>;
template<typename Type>
void func(Matrix<Type> const& A, Vector<Type> const& rhs, Vector<Type>& sol) {
sol = A.colPivHouseholderQr().solve(rhs);
}
template<typename Number>
public:
std::cout << "Solve system says hello!!!" << std::endl;
func(*A, *b, *x);
}
};
#else
#warning EIGEN_DIR not set. Skipping Eigen example.
#endif
int main(int nargs, char** args) {
#if CODI_EnableEigen
int size = 10;
Matrix<Real> A(size, size);
Vector<Real> rhs(size);
Vector<Real> sol(size);
tape.setActive();
tape.registerInput(matrixEntry);
tape.registerInput(rhsEntry);
for(int i = 0; i < size; i += 1) {
A(i,i) = matrixEntry;
if(i + 1 != size) {
A(i, i + 1) = matrixEntry;
}
rhs(i) = rhsEntry;
}
std::cout << "Solving primal system:" << std::endl;
for(int i = 0; i < size; i += 1) {
y += sol(i);
}
tape.registerOutput(y);
tape.setPassive();
std::cout << "Running reverse evaluation:" << std::endl;
tape.evaluate();
std::cout << "y = " << y << std::endl;
std::cout <<
"dy/d matrixEntry = " << matrixEntry.
getGradient() << std::endl;
std::cout <<
"dy/d rhsEntry = " << rhsEntry.
getGradient() << std::endl;
tape.reset();
#else
std::cerr << "EIGEN_DIR not set. Skipping Eigen example." << std::endl;
#endif
return 0;
}
RealReverseGen< double > RealReverse
Definition: codi.hpp:120
void solveLinearSystem(LSInterface lsi, typename LSInterface::Matrix &A, typename LSInterface::Vector &b, typename LSInterface::Vector &x, LinearSystemSolverHints hints=LinearSystemSolverHints::ALL())
Definition: linearSystemHandler.hpp:770
Represents a concrete lvalue in the CoDiPack expression tree.
Definition: activeType.hpp:52
typename Tape::Identifier Identifier
See LhsExpressionInterface.
Definition: activeTypeBase.hpp:78
static Tape & getTape()
Get a reference to the tape which manages this expression.
Definition: activeType.hpp:99
T_Tape Tape
See ActiveType.
Definition: activeType.hpp:55
typename Tape::Real Real
See LhsExpressionInterface.
Definition: activeTypeBase.hpp:76
void setGradient(Gradient const &g)
Set the gradient of this lvalue in the tape.
Definition: lhsExpressionInterface.hpp:120
Gradient getGradient() const
Get the gradient of this lvalue from the tape.
Definition: lhsExpressionInterface.hpp:115