#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;
}
void solveLinearSystem(LSInterface lsi, typename LSInterface::Matrix &A, typename LSInterface::Vector &b, typename LSInterface::Vector &x, LinearSystemSolverHints hints=LinearSystemSolverHints::ALL())
Definition linearSystemHandler.hpp:770
[Function]
Definition Example_21_Special_handling_of_linear_system_solvers.cpp:27
typename Base::MatrixReal MatrixReal
Matrix type.
Definition Example_21_Special_handling_of_linear_system_solvers.cpp:31
typename Base::VectorReal VectorReal
Vector type.
Definition Example_21_Special_handling_of_linear_system_solvers.cpp:32
codi::EigenLinearSystem< Number, Matrix, Vector > Base
Base solver.
Definition Example_21_Special_handling_of_linear_system_solvers.cpp:30
void solveSystem(MatrixReal const *A, VectorReal const *b, VectorReal *x)
System solve implementation.
Definition Example_21_Special_handling_of_linear_system_solvers.cpp:35
Definition eigenLinearSystem.hpp:80
typename InterfaceTypes::MatrixReal MatrixReal
See LinearSystemInterfaceTypes.
Definition eigenLinearSystem.hpp:87
typename InterfaceTypes::VectorReal VectorReal
See LinearSystemInterfaceTypes.
Definition eigenLinearSystem.hpp:90