457
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
457
|
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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
457
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
457
|
26 #endif |
|
27 |
|
28 #include "dbleCHOL.h" |
1847
|
29 #include "f77-fcn.h" |
457
|
30 #include "lo-error.h" |
|
31 |
|
32 extern "C" |
|
33 { |
4552
|
34 F77_RET_T |
5275
|
35 F77_FUNC (dpotrf, DPOTRF) (F77_CONST_CHAR_ARG_DECL, const octave_idx_type&, |
|
36 double*, const octave_idx_type&, octave_idx_type& |
4552
|
37 F77_CHAR_ARG_LEN_DECL); |
457
|
38 } |
|
39 |
5275
|
40 octave_idx_type |
457
|
41 CHOL::init (const Matrix& a) |
|
42 { |
5275
|
43 octave_idx_type a_nr = a.rows (); |
|
44 octave_idx_type a_nc = a.cols (); |
1944
|
45 |
457
|
46 if (a_nr != a_nc) |
|
47 { |
|
48 (*current_liboctave_error_handler) ("CHOL requires square matrix"); |
|
49 return -1; |
|
50 } |
|
51 |
5275
|
52 octave_idx_type n = a_nc; |
|
53 octave_idx_type info; |
457
|
54 |
1944
|
55 chol_mat = a; |
|
56 double *h = chol_mat.fortran_vec (); |
457
|
57 |
4552
|
58 F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 ("U", 1), |
|
59 n, h, n, info |
|
60 F77_CHAR_ARG_LEN (1))); |
457
|
61 |
1944
|
62 if (f77_exception_encountered) |
|
63 (*current_liboctave_error_handler) ("unrecoverable error in dpotrf"); |
|
64 else |
|
65 { |
|
66 // If someone thinks of a more graceful way of doing this (or |
|
67 // faster for that matter :-)), please let me know! |
457
|
68 |
1944
|
69 if (n > 1) |
5275
|
70 for (octave_idx_type j = 0; j < a_nc; j++) |
|
71 for (octave_idx_type i = j+1; i < a_nr; i++) |
1944
|
72 chol_mat.elem (i, j) = 0.0; |
|
73 } |
457
|
74 |
|
75 return info; |
|
76 } |
|
77 |
|
78 /* |
|
79 ;;; Local Variables: *** |
|
80 ;;; mode: C++ *** |
|
81 ;;; End: *** |
|
82 */ |