[CppAD] LuSolve nan
Kasper Kristensen
kkr at dfu.min.dk
Mon Feb 27 10:29:10 EST 2006
Hello all,
I have attached a small code example which tapes the mapping
A->log(abs(det(A))) for a 1x1 matrix A=1 using LuSolve.
I was expecting the tape to be valid for all non-zero matrices A.
However if I evaluate the tape with a matrix for which det(A)<0 the
evaluation gives nan (but the Jacobian is correct!).
Best regards
Kasper
PROGRAM OUTPUT:
A=2
{ 0.693147 }{ 0.5 }
A=-2
{ nan }{ -0.5 }
CODE:
# include <CppAD/CppAD.h>
using namespace CppAD;
int main()
{
// dimension of the matrix
size_t n = 1;
// Dummy arguments to LuSolve
vector<AD<double> > B(0);
vector<AD<double> > X(0);
// construct ADFun object F:A->log(abs(det(A)))
vector<AD<double> > A(n);
vector<AD<double> > y(n);
A[0]=1;
Independent(A);
AD<double> logdet;
LuSolve(n, 0, A, B, X, logdet);
y[0]=logdet;
ADFun<double> F(A,y);
// evaluate the tape
vector<double> A0(n);
A0[0]=2;
std::cout << "A=2\n";
std::cout << F.Forward(0,A0) ;
std::cout << F.Jacobian(A0) ;
A0[0]=-2;
std::cout << "\nA=-2\n";
std::cout << F.Forward(0,A0) ;
std::cout << F.Jacobian(A0) << "\n";
}
More information about the CppAD
mailing list