home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fs.zip / octave / octave-2.1.23 / liboctave / dbleCHOL.cc < prev    next >
C/C++ Source or Header  |  2000-01-15  |  2KB  |  82 lines

  1. /*
  2.  
  3. Copyright (C) 1996, 1997 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "dbleCHOL.h"
  32. #include "f77-fcn.h"
  33. #include "lo-error.h"
  34.  
  35. extern "C"
  36. {
  37.   int F77_FCN (dpotrf, DPOTRF) (const char*, const int&, double*,
  38.                 const int&, int&, long);
  39. }
  40.  
  41. int
  42. CHOL::init (const Matrix& a)
  43. {
  44.   int a_nr = a.rows ();
  45.   int a_nc = a.cols ();
  46.  
  47.   if (a_nr != a_nc)
  48.     {
  49.       (*current_liboctave_error_handler) ("CHOL requires square matrix");
  50.       return -1;
  51.     }
  52.  
  53.   int n = a_nc;
  54.   int info;
  55.  
  56.   chol_mat = a;
  57.   double *h = chol_mat.fortran_vec ();
  58.  
  59.   F77_XFCN (dpotrf, DPOTRF, ("U", n, h, n, info, 1L));
  60.  
  61.   if (f77_exception_encountered)
  62.     (*current_liboctave_error_handler) ("unrecoverable error in dpotrf");
  63.   else
  64.     {
  65.       // If someone thinks of a more graceful way of doing this (or
  66.       // faster for that matter :-)), please let me know!
  67.  
  68.       if (n > 1)
  69.     for (int j = 0; j < a_nc; j++)
  70.       for (int i = j+1; i < a_nr; i++)
  71.         chol_mat.elem (i, j) = 0.0;
  72.     }
  73.  
  74.   return info;
  75. }
  76.  
  77. /*
  78. ;;; Local Variables: ***
  79. ;;; mode: C++ ***
  80. ;;; End: ***
  81. */
  82.