annotate main/fixed/src/ov-base-fixed-mat.cc @ 3272:17e102866239 octave-forge

FSF address update
author adb014
date Fri, 23 Mar 2007 20:59:58 +0000
parents 73fa4496fb07
children 2de537641f94
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2383
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
1 /*
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
2
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
3 Copyright (C) 2003 Motorola Inc
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
4 Copyright (C) 2003 David Bateman
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
5
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
6 This program is free software; you can redistribute it and/or modify it
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
9 later version.
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
10
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
11 This program is distributed in the hope that it will be useful, but WITHOUT
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
14 for more details.
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
15
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
17 along with this program; see the file COPYING. If not, write to the Free
3272
17e102866239 FSF address update
adb014
parents: 3268
diff changeset
18 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2383
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
19
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
20 In addition to the terms of the GPL, you are permitted to link
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
21 this program with any Open Source program, as defined by the
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
22 Open Source Initiative (www.opensource.org)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
23
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
24 */
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
25
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
26 #include <config.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
27 #include <iostream>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
28 #include <octave/oct-obj.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
29 #include <octave/ov-base.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
30 #include <octave/ov-base-scalar.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
31 #include <octave/pr-output.h>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
32
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
33 template <class MT>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
34 octave_value_list
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
35 octave_base_fixed_matrix<MT>::dotref (const octave_value_list& idx)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
36 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
37 octave_value_list retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
38
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
39 assert (idx.length () == 1);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
40
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
41 std::string nm = idx(0).string_value ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
42
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
43 if (nm == __FIXED_SIGN_STR)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
44 retval(0) = octave_value (matrix.sign());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
45 else if (nm == __FIXED_VALUE_STR)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
46 retval(0) = octave_value (matrix.fixedpoint());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
47 else if (nm == __FIXED_DECSIZE_STR)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
48 retval(0) = octave_value (matrix.getdecsize());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
49 else if (nm == __FIXED_INTSIZE_STR)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
50 retval(0) = octave_value (matrix.getintsize());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
51 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
52 error ("fixed point structure has no member `%s'", nm.c_str ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
53
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
54 return retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
55 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
56
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
57 template <class MT>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
58 octave_value
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
59 octave_base_fixed_matrix<MT>::subsref (const std::string& type,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
60 const std::list<octave_value_list>& idx)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
61 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
62 octave_value retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
63
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
64 switch (type[0])
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
65 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
66 case '(':
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
67 retval = do_index_op (idx.front ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
68 break;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
69
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
70 case '.':
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
71 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
72 octave_value_list t = dotref (idx.front ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
73
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
74 retval = (t.length () == 1) ? t(0) : octave_value (t);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
75 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
76 break;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
77
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
78 case '{':
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
79 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
80 std::string nm = type_name ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
81 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
82 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
83 break;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
84
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
85 default:
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
86 panic_impossible ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
87 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
88
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
89 return retval.next_subsref (type, idx);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
90 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
91
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
92 template <class MT>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
93 void
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
94 octave_base_fixed_matrix<MT>::assign (const octave_value_list& idx,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
95 const MT& rhs)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
96 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
97 int len = idx.length ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
98
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
99 if (len > 2)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
100 error ("invalid number of indices (%d) for indexed assignment",
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
101 len);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
102 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
103 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
104 for (int i = 0; i < len; i++)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
105 matrix.set_index (idx(i).index_vector ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
106
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
107 ::assign (matrix, rhs, MT::resize_fill_value ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
108 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
109 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
110
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
111 template <class MT>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
112 bool
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
113 octave_base_fixed_matrix<MT>::is_true (void) const
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
114 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
115 bool retval = false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
116
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
117 if (rows () > 0 && columns () > 0)
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
118 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
119 boolMatrix m = (matrix.all () . all ());
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
120
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
121 retval = (m.rows () == 1 && m.columns () == 1 && m(0,0));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
122 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
123
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
124 return retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
125 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
126
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
127 template <class MT>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
128 bool
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
129 octave_base_fixed_matrix<MT>::valid_as_scalar_index (void) const
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
130 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
131 // XXX FIXME XXX
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
132 return false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
133 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
134
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
135 template <class MT>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
136 bool
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
137 octave_base_fixed_matrix<MT>::print_as_scalar (void) const
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
138 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
139 int nr = rows ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
140 int nc = columns ();
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
141
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
142 return (nr == 1 && nc == 1 || (nr == 0 || nc == 0));
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
143 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
144
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
145 template <class MT>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
146 void
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
147 octave_base_fixed_matrix<MT>::print (std::ostream& os, bool pr_as_read_syntax) const
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
148 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
149 print_raw (os, pr_as_read_syntax);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
150 newline (os);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
151 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
152
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
153 template <class MT>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
154 bool
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
155 octave_base_fixed_matrix<MT>::print_name_tag (std::ostream& os,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
156 const std::string& name) const
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
157 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
158 bool retval = false;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
159
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
160 indent (os);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
161
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
162 if (print_as_scalar ())
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
163 os << name << " = ";
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
164 else
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
165 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
166 os << name << " =";
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
167 newline (os);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
168 newline (os);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
169 retval = true;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
170 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
171
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
172 return retval;
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
173 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
174
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
175 template <class MT>
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
176 void
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
177 octave_base_fixed_matrix<MT>::print_info (std::ostream& os,
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
178 const std::string& prefix) const
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
179 {
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
180 matrix.print_info (os, prefix);
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
181 }
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
182
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
183 /*
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
184 ;;; Local Variables: ***
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
185 ;;; mode: C++ ***
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
186 ;;; End: ***
d1930f8af7ca Changed the directory structure of fixed to match the package system
hauberg
parents:
diff changeset
187 */