5164
|
1 /* |
|
2 |
|
3 Copyright (C) 2004 David Bateman |
|
4 Copyright (C) 1998-2004 Andy Adler |
|
5 |
|
6 Octave is free software; you can redistribute it and/or modify it |
|
7 under the terms of the GNU General Public License as published by the |
|
8 Free Software Foundation; either version 2, or (at your option) any |
|
9 later version. |
|
10 |
|
11 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 for more details. |
|
15 |
|
16 You should have received a copy of the GNU General Public License |
5307
|
17 along with this program; see the file COPYING. If not, write to the |
|
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
19 Boston, MA 02110-1301, USA. |
5164
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "defun-dld.h" |
|
28 #include "error.h" |
|
29 #include "gripes.h" |
|
30 #include "oct-obj.h" |
|
31 #include "utils.h" |
|
32 |
|
33 #include "dbleDET.h" |
|
34 #include "CmplxDET.h" |
|
35 |
|
36 #include "ov-re-sparse.h" |
|
37 #include "ov-cx-sparse.h" |
|
38 |
5534
|
39 // PKG_ADD: dispatch ("det", "spdet", "sparse matrix"); |
|
40 // PKG_ADD: dispatch ("det", "spdet", "sparse complex matrix"); |
|
41 // PKG_ADD: dispatch ("det", "spdet", "sparse bool matrix"); |
5164
|
42 DEFUN_DLD (spdet, args, , |
|
43 "-*- texinfo -*-\n\ |
|
44 @deftypefn {Loadable Function} {[@var{d}, @var{rcond}] = } spdet (@var{a})\n\ |
|
45 Compute the determinant of sparse matrix @var{a} using UMFPACK. Return\n\ |
|
46 an estimate of the reciprocal condition number if requested.\n\ |
|
47 @end deftypefn") |
|
48 { |
|
49 octave_value_list retval; |
|
50 |
|
51 int nargin = args.length (); |
|
52 |
|
53 if (nargin != 1) |
|
54 { |
|
55 print_usage ("spdet"); |
|
56 return retval; |
|
57 } |
|
58 |
|
59 octave_value arg = args(0); |
|
60 |
5275
|
61 octave_idx_type nr = arg.rows (); |
|
62 octave_idx_type nc = arg.columns (); |
5164
|
63 |
|
64 if (nr == 0 && nc == 0) |
|
65 { |
|
66 retval(0) = 1.0; |
|
67 return retval; |
|
68 } |
|
69 |
|
70 int arg_is_empty = empty_arg ("spdet", nr, nc); |
|
71 if (arg_is_empty < 0) |
|
72 return retval; |
|
73 if (arg_is_empty > 0) |
|
74 return octave_value (Matrix (1, 1, 1.0)); |
|
75 |
|
76 if (nr != nc) |
|
77 { |
|
78 gripe_square_matrix_required ("spdet"); |
|
79 return retval; |
|
80 } |
|
81 |
|
82 if (arg.is_real_type ()) |
|
83 { |
|
84 SparseMatrix m = args(0).sparse_matrix_value (); |
|
85 |
|
86 if (! error_state) |
|
87 { |
|
88 // Always compute rcond, so we can detect numerically |
|
89 // singular matrices. |
|
90 |
5275
|
91 octave_idx_type info; |
5164
|
92 double rcond = 0.0; |
|
93 DET det = m.determinant (info, rcond); |
|
94 retval(1) = rcond; |
|
95 volatile double xrcond = rcond; |
|
96 xrcond += 1.0; |
|
97 retval(0) = ((info == -1 || xrcond == 1.0) ? 0.0 : det.value ()); |
|
98 } |
|
99 } |
|
100 else if (arg.is_complex_type ()) |
|
101 { |
|
102 SparseComplexMatrix m = args(0).sparse_complex_matrix_value (); |
|
103 |
|
104 if (! error_state) |
|
105 { |
|
106 // Always compute rcond, so we can detect numerically |
|
107 // singular matrices. |
|
108 |
5275
|
109 octave_idx_type info; |
5164
|
110 double rcond = 0.0; |
|
111 ComplexDET det = m.determinant (info, rcond); |
|
112 retval(1) = rcond; |
|
113 volatile double xrcond = rcond; |
|
114 xrcond += 1.0; |
|
115 retval(0) = ((info == -1 || xrcond == 1.0) |
|
116 ? Complex (0.0) : det.value ()); |
|
117 } |
|
118 } |
|
119 else |
|
120 { |
|
121 gripe_wrong_type_arg ("spdet", arg); |
|
122 } |
|
123 |
|
124 return retval; |
|
125 } |
|
126 |
|
127 /* |
|
128 ;;; Local Variables: *** |
|
129 ;;; mode: C++ *** |
|
130 ;;; End: *** |
|
131 */ |