Prev Next double_det_lu.cpp

Double Speed: Determinant Using Lu Factorization

compute_det_lu
Routine that computes the gradient of determinant using CppAD:
# include <cppad/vector.hpp>
# include <cppad/speed/det_by_lu.hpp>
# include <cppad/speed/uniform_01.hpp>

void compute_det_lu(
     size_t                           size     , 
     size_t                           repeat   , 
     CppAD::vector<double>           &matrix   ,
     CppAD::vector<double>           &det      )
{
     // -----------------------------------------------------
     // setup
     CppAD::det_by_lu<double>  Det(size);
     size_t n = size * size; // number of independent variables
     
     // ------------------------------------------------------

     while(repeat--)
     {    // get the next matrix
          CppAD::uniform_01(n, matrix);

          // computation of the determinant
          det[0] = Det(matrix);
     }
     return;
}

Input File: speed/double/det_lu.cpp