SparsedbleCHOL.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2005-2012 David Bateman
00004 Copyright (C) 1998-2005 Andy Adler
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #include "SparsedbleCHOL.h"
00029 
00030 // Instantiate the base CHOL class for the type we need
00031 #define OCTAVE_CHOLMOD_TYPE CHOLMOD_REAL
00032 #include "sparse-base-chol.h"
00033 #include "sparse-base-chol.cc"
00034 template class sparse_base_chol <SparseMatrix, double, SparseMatrix>;
00035 
00036 // Compute the inverse of a matrix using the Cholesky factorization.
00037 SparseMatrix
00038 chol2inv (const SparseMatrix& r)
00039 {
00040   octave_idx_type r_nr = r.rows ();
00041   octave_idx_type r_nc = r.cols ();
00042   SparseMatrix retval;
00043 
00044   if (r_nr == r_nc)
00045     {
00046       MatrixType mattype (r);
00047       int typ = mattype.type (false);
00048       double rcond;
00049       octave_idx_type info;
00050       SparseMatrix rinv;
00051 
00052       if (typ == MatrixType::Upper)
00053         {
00054           rinv = r.inverse(mattype, info, rcond, true, false);
00055           retval = rinv.transpose() * rinv;
00056         }
00057       else if (typ == MatrixType::Lower)
00058         {
00059           rinv = r.transpose().inverse(mattype, info, rcond, true, false);
00060           retval = rinv.transpose() * rinv;
00061         }
00062       else
00063         (*current_liboctave_error_handler)
00064           ("spchol2inv requires triangular matrix");
00065     }
00066   else
00067     (*current_liboctave_error_handler) ("spchol2inv requires square matrix");
00068 
00069   return retval;
00070 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines