33
|
1 // tc-givens.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1993 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 // Written by A. S. Hodel <scotte@eng.auburn.edu> |
|
25 |
|
26 #ifdef __GNUG__ |
|
27 #pragma implementation |
|
28 #endif |
|
29 |
|
30 #include "Matrix.h" |
|
31 |
|
32 #include "tree-const.h" |
|
33 #include "user-prefs.h" |
|
34 #include "error.h" |
|
35 #include "gripes.h" |
49
|
36 #include "f-givens.h" |
33
|
37 |
47
|
38 extern "C" |
|
39 { |
|
40 int F77_FCN (dlartg) (const double*, const double*, double*, double*, |
|
41 double*); |
33
|
42 |
47
|
43 int F77_FCN (zlartg) (const Complex*, const Complex*, double*, |
|
44 Complex*, Complex*); |
|
45 } |
33
|
46 |
|
47 // These aren't used? |
|
48 #if 0 |
|
49 int F77_FCN (dorgqr) (const int*, const int*, const int*, double*, |
|
50 const int*, double*, double*, const int*, int*); |
|
51 |
|
52 int F77_FCN (zunghr) (const int*, const int*, const int*, Complex*, |
|
53 const int*, Complex*, Complex*, const int*, |
|
54 int*, long, long); |
|
55 #endif |
|
56 |
|
57 #ifdef WITH_DLD |
|
58 tree_constant * |
|
59 builtin_givens_2 (tree_constant *args, int nargin, int nargout) |
|
60 { |
|
61 return givens (args, nargin, nargout); |
|
62 } |
|
63 #endif |
|
64 |
|
65 tree_constant * |
|
66 givens (tree_constant *args, int nargin, int nargout) |
|
67 { |
|
68 |
|
69 tree_constant *retval = NULL_TREE_CONST; |
|
70 |
|
71 tree_constant arga = args[1].make_numeric (); |
|
72 tree_constant argb = args[2].make_numeric (); |
|
73 |
|
74 if (! arga.is_scalar_type () && argb.is_scalar_type ()) |
|
75 { |
|
76 error("givens: requires two scalar arguments"); |
|
77 } |
|
78 else |
|
79 { |
|
80 |
|
81 retval = new tree_constant [nargout+1]; |
|
82 |
|
83 Complex cx, cy; |
|
84 double x, y; |
|
85 |
|
86 if (arga.is_complex_type ()) |
|
87 cx = arga.complex_value (); |
|
88 else |
|
89 { |
|
90 x = arga.double_value (); |
|
91 cx = x; // copy to complex just in case |
|
92 } |
|
93 |
|
94 if (argb.is_complex_type ()) |
|
95 cy = argb.complex_value (); |
|
96 else |
|
97 { |
|
98 y = argb.double_value (); |
|
99 cy = y; // copy to complex just in case |
|
100 } |
|
101 |
|
102 // Now compute the rotation. |
|
103 |
|
104 double cc; |
|
105 if (arga.is_complex_type () || argb.is_complex_type ()) |
|
106 { |
|
107 Complex cs, temp_r; |
|
108 |
|
109 F77_FCN (zlartg) (&cx, &cy, &cc, &cs, &temp_r); |
|
110 |
|
111 switch (nargout) |
|
112 { |
|
113 case 1: // output a matrix |
|
114 { |
|
115 ComplexMatrix g (2, 2); |
|
116 g.elem (0, 0) = cc; |
|
117 g.elem (1, 1) = cc; |
|
118 g.elem (0, 1) = cs; |
|
119 g.elem (1, 0) = -conj (cs); |
|
120 |
|
121 retval[0] = tree_constant (g); |
|
122 } |
|
123 break; |
|
124 |
|
125 case 2: // output scalar values |
|
126 retval[0] = tree_constant(cc); |
|
127 retval[1] = tree_constant(cs); |
|
128 break; |
|
129 |
|
130 default: |
|
131 error ("givens: illegal number of output arguments"); |
|
132 break; |
|
133 } |
|
134 } |
|
135 else |
|
136 { |
|
137 double s, temp_r; |
|
138 |
|
139 F77_FCN (dlartg) (&x, &y, &cc, &s, &temp_r); |
|
140 |
|
141 switch (nargout) |
|
142 { |
|
143 case 1: // output a matrix |
|
144 { |
|
145 Matrix g (2, 2); |
|
146 g.elem (0, 0) = cc; |
|
147 g.elem (1, 1) = cc; |
|
148 g.elem (0, 1) = s; |
|
149 g.elem (1, 0) = -s; |
|
150 |
|
151 retval[0] = tree_constant (g); |
|
152 } |
|
153 break; |
|
154 |
|
155 case 2: // output scalar values |
|
156 retval[0] = tree_constant (cc); |
|
157 retval[1] = tree_constant (s); |
|
158 break; |
|
159 |
|
160 default: |
|
161 error ("givens: illegal number of output arguments"); |
|
162 break; |
|
163 } |
|
164 } |
|
165 } |
|
166 |
|
167 return retval; |
|
168 } |
|
169 |
|
170 /* |
|
171 ;;; Local Variables: *** |
|
172 ;;; mode: C++ *** |
|
173 ;;; page-delimiter: "^/\\*" *** |
|
174 ;;; End: *** |
|
175 */ |