comparison src/DLD-FUNCTIONS/det.cc @ 8371:c3f7e2549abb

make det & inv aware of diagonal & permutation matrices
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 04 Dec 2008 12:03:45 +0100
parents e02242c54c49
children a2878ba31a9e
comparison
equal deleted inserted replaced
8370:34960ba08a81 8371:c3f7e2549abb
30 #include "defun-dld.h" 30 #include "defun-dld.h"
31 #include "error.h" 31 #include "error.h"
32 #include "gripes.h" 32 #include "gripes.h"
33 #include "oct-obj.h" 33 #include "oct-obj.h"
34 #include "utils.h" 34 #include "utils.h"
35 #include "ops.h"
35 36
36 #include "ov-re-mat.h" 37 #include "ov-re-mat.h"
37 #include "ov-cx-mat.h" 38 #include "ov-cx-mat.h"
38 #include "ov-flt-re-mat.h" 39 #include "ov-flt-re-mat.h"
39 #include "ov-flt-cx-mat.h" 40 #include "ov-flt-cx-mat.h"
41 #include "ov-re-diag.h"
42 #include "ov-cx-diag.h"
43 #include "ov-flt-re-diag.h"
44 #include "ov-flt-cx-diag.h"
45 #include "ov-perm.h"
46 #include "ov-flt-perm.h"
40 47
41 #define MAYBE_CAST(VAR, CLASS) \ 48 #define MAYBE_CAST(VAR, CLASS) \
42 const CLASS *VAR = arg.type_id () == CLASS::static_type_id () ? \ 49 const CLASS *VAR = arg.type_id () == CLASS::static_type_id () ? \
43 dynamic_cast<const CLASS *> (&arg.get_rep ()) : 0 50 dynamic_cast<const CLASS *> (&arg.get_rep ()) : 0
44 51
45 DEFUN_DLD (det, args, , 52 DEFUN_DLD (det, args, nargout,
46 "-*- texinfo -*-\n\ 53 "-*- texinfo -*-\n\
47 @deftypefn {Loadable Function} {[@var{d}, @var{rcond}] =} det (@var{a})\n\ 54 @deftypefn {Loadable Function} {[@var{d}, @var{rcond}] =} det (@var{a})\n\
48 Compute the determinant of @var{a} using @sc{Lapack} for full and UMFPACK\n\ 55 Compute the determinant of @var{a} using @sc{Lapack} for full and UMFPACK\n\
49 for sparse matrices. Return an estimate of the reciprocal condition number\n\ 56 for sparse matrices. Return an estimate of the reciprocal condition number\n\
50 if requested.\n\ 57 if requested.\n\
82 { 89 {
83 gripe_square_matrix_required ("det"); 90 gripe_square_matrix_required ("det");
84 return retval; 91 return retval;
85 } 92 }
86 93
87 94 bool isfloat = arg.is_single_type ();
88 if (arg.is_single_type ()) 95
96 if (arg.is_diag_matrix ())
97 {
98 const octave_base_value& a = arg.get_rep ();
99 if (arg.is_complex_type ())
100 {
101 if (isfloat)
102 {
103 CAST_CONV_ARG (const octave_float_complex_diag_matrix&);
104 retval(0) = v.float_complex_diag_matrix_value ().determinant ().value ();
105 if (nargout > 1)
106 retval(1) = v.float_complex_diag_matrix_value ().rcond ();
107 }
108 else
109 {
110 CAST_CONV_ARG (const octave_complex_diag_matrix&);
111 retval(0) = v.complex_diag_matrix_value ().determinant ().value ();
112 if (nargout > 1)
113 retval(1) = v.complex_diag_matrix_value ().rcond ();
114 }
115 }
116 else
117 {
118 if (isfloat)
119 {
120 CAST_CONV_ARG (const octave_float_diag_matrix&);
121 retval(0) = v.float_diag_matrix_value ().determinant ().value ();
122 if (nargout > 1)
123 retval(1) = v.float_diag_matrix_value ().rcond ();
124 }
125 else
126 {
127 CAST_CONV_ARG (const octave_diag_matrix&);
128 retval(0) = v.diag_matrix_value ().determinant ().value ();
129 if (nargout > 1)
130 retval(1) = v.diag_matrix_value ().rcond ();
131 }
132 }
133 }
134 else if (arg.is_perm_matrix ())
135 {
136 const octave_base_value& a = arg.get_rep ();
137 if (isfloat)
138 {
139 CAST_CONV_ARG (const octave_float_perm_matrix&);
140 retval(0) = static_cast<float> (v.perm_matrix_value ().determinant ());
141 if (nargout > 1)
142 retval(1) = 1.0;
143 }
144 else
145 {
146 CAST_CONV_ARG (const octave_perm_matrix&);
147 retval(0) = static_cast<double> (v.perm_matrix_value ().determinant ());
148 if (nargout > 1)
149 retval(1) = 1.0f;
150 }
151 }
152 else if (arg.is_single_type ())
89 { 153 {
90 if (arg.is_real_type ()) 154 if (arg.is_real_type ())
91 { 155 {
92 octave_idx_type info; 156 octave_idx_type info;
93 float rcond = 0.0; 157 float rcond = 0.0;