comparison src/svd.cc @ 620:8e4e7e5f307e

[project @ 1994-08-16 04:36:32 by jwe]
author jwe
date Tue, 16 Aug 1994 04:36:32 +0000
parents 20fbad23ae51
children 6636e6198f01
comparison
equal deleted inserted replaced
619:8778be2e70e7 620:8e4e7e5f307e
52 return retval; 52 return retval;
53 } 53 }
54 54
55 tree_constant arg = args(1).make_numeric (); 55 tree_constant arg = args(1).make_numeric ();
56 56
57 if (error_state)
58 return retval;
59
57 if (arg.rows () == 0 || arg.columns () == 0) 60 if (arg.rows () == 0 || arg.columns () == 0)
58 { 61 {
59 int flag = user_pref.propagate_empty_matrices; 62 int flag = user_pref.propagate_empty_matrices;
60 if (flag != 0) 63 if (flag != 0)
61 { 64 {
62 if (flag < 0) 65 if (flag < 0)
63 gripe_empty_arg ("svd", 0); 66 gripe_empty_arg ("svd", 0);
64 67
65 Matrix m; 68 Matrix m;
66 retval.resize (3); 69 retval.resize (3, m);
67 retval(0) = m;
68 retval(1) = m;
69 retval(2) = m;
70 } 70 }
71 else 71 else
72 gripe_empty_arg ("svd", 1); 72 gripe_empty_arg ("svd", 1);
73 73
74 return retval; 74 return retval;
75 } 75 }
76 76
77 Matrix tmp;
78 ComplexMatrix ctmp;
79 switch (arg.const_type ())
80 {
81 case tree_constant_rep::scalar_constant:
82 tmp.resize (1, 1);
83 tmp.elem (0, 0) = arg.double_value ();
84 break;
85 case tree_constant_rep::matrix_constant:
86 tmp = arg.matrix_value ();
87 break;
88 case tree_constant_rep::complex_scalar_constant:
89 ctmp.resize (1, 1);
90 ctmp.elem (0, 0) = arg.complex_value ();
91 break;
92 case tree_constant_rep::complex_matrix_constant:
93 ctmp = arg.complex_matrix_value ();
94 break;
95 default:
96 panic_impossible ();
97 break;
98 }
99
100 SVD::type type = (nargin == 3) ? SVD::economy : SVD::std; 77 SVD::type type = (nargin == 3) ? SVD::economy : SVD::std;
101 78
102 switch (arg.const_type ()) 79 if (arg.is_real_type ())
103 { 80 {
104 case tree_constant_rep::scalar_constant: 81 Matrix tmp = arg.matrix_value ();
105 case tree_constant_rep::matrix_constant:
106 {
107 SVD result (tmp, type);
108 82
109 DiagMatrix sigma = result.singular_values (); 83 SVD result (tmp, type);
110 84
111 if (nargout == 0 || nargout == 1) 85 DiagMatrix sigma = result.singular_values ();
112 {
113 retval.resize (1);
114 retval(0) = tree_constant (sigma.diag (), 1);
115 }
116 else
117 {
118 retval.resize (3);
119 retval(0) = result.left_singular_matrix ();
120 retval(1) = sigma;
121 retval(2) = result.right_singular_matrix ();
122 }
123 }
124 break;
125 case tree_constant_rep::complex_scalar_constant:
126 case tree_constant_rep::complex_matrix_constant:
127 {
128 ComplexSVD result (ctmp, type);
129 86
130 DiagMatrix sigma = result.singular_values (); 87 if (nargout == 0 || nargout == 1)
88 {
89 retval(0) = tree_constant (sigma.diag (), 1);
90 }
91 else
92 {
93 retval(2) = result.right_singular_matrix ();
94 retval(1) = sigma;
95 retval(0) = result.left_singular_matrix ();
96 }
97 }
98 else if (arg.is_complex_type ())
99 {
100 ComplexMatrix ctmp = arg.complex_matrix_value ();
131 101
132 if (nargout == 0 || nargout == 1) 102 ComplexSVD result (ctmp, type);
133 { 103
134 retval.resize (1); 104 DiagMatrix sigma = result.singular_values ();
135 retval(0) = tree_constant (sigma.diag (), 1); 105
136 } 106 if (nargout == 0 || nargout == 1)
137 else 107 {
138 { 108 retval(0) = tree_constant (sigma.diag (), 1);
139 retval.resize (3); 109 }
140 retval(0) = result.left_singular_matrix (); 110 else
141 retval(1) = sigma; 111 {
142 retval(2) = result.right_singular_matrix (); 112 retval(2) = result.right_singular_matrix ();
143 } 113 retval(1) = sigma;
144 } 114 retval(0) = result.left_singular_matrix ();
145 break; 115 }
146 default: 116 }
147 panic_impossible (); 117 else
148 break; 118 {
119 gripe_wrong_type_arg ("svd", arg);
120 return retval;
149 } 121 }
150 122
151 return retval; 123 return retval;
152 } 124 }
153 125