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