3219
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include <iostream.h> |
|
32 |
3220
|
33 #include "oct-obj.h" |
3219
|
34 #include "ov-base.h" |
|
35 #include "ov-base-mat.h" |
|
36 |
|
37 template <class MT> |
3220
|
38 octave_value |
|
39 octave_base_matrix<MT>::do_index_op (const octave_value_list& idx) |
|
40 { |
|
41 octave_value retval; |
|
42 |
|
43 int len = idx.length (); |
|
44 |
|
45 switch (len) |
|
46 { |
|
47 case 2: |
|
48 { |
|
49 idx_vector i = idx (0).index_vector (); |
|
50 idx_vector j = idx (1).index_vector (); |
|
51 |
|
52 retval = MT (matrix.index (i, j)); |
|
53 } |
|
54 break; |
|
55 |
|
56 case 1: |
|
57 { |
|
58 idx_vector i = idx (0).index_vector (); |
|
59 |
|
60 retval = MT (matrix.index (i)); |
|
61 } |
|
62 break; |
|
63 |
|
64 default: |
|
65 { |
|
66 string n = type_name (); |
|
67 |
|
68 error ("invalid number of indices (%d) for %s value", |
|
69 len, n.c_str ()); |
|
70 } |
|
71 break; |
|
72 } |
|
73 |
|
74 return retval; |
|
75 } |
|
76 |
|
77 template <class MT> |
|
78 bool |
|
79 octave_base_matrix<MT>::is_true (void) const |
|
80 { |
|
81 bool retval = false; |
|
82 |
|
83 if (rows () == 0 || columns () == 0) |
|
84 { |
|
85 int flag = Vpropagate_empty_matrices; |
|
86 |
|
87 if (flag < 0) |
|
88 warning ("empty matrix used in conditional expression"); |
|
89 else if (flag == 0) |
|
90 error ("empty matrix used in conditional expression"); |
|
91 } |
|
92 else |
|
93 { |
|
94 boolMatrix m = (matrix.all ()) . all (); |
|
95 |
|
96 retval = (m.rows () == 1 && m.columns () == 1 && m (0, 0) != 0.0); |
|
97 } |
|
98 |
|
99 return retval; |
|
100 } |
|
101 |
|
102 template <class MT> |
3219
|
103 bool |
|
104 octave_base_matrix<MT>::print_as_scalar (void) const |
|
105 { |
|
106 int nr = rows (); |
|
107 int nc = columns (); |
|
108 |
|
109 return (nr == 1 && nc == 1 || (nr == 0 || nc == 0)); |
|
110 } |
|
111 |
|
112 template <class MT> |
|
113 void |
|
114 octave_base_matrix<MT>::print (ostream& os, bool pr_as_read_syntax) const |
|
115 { |
|
116 print_raw (os, pr_as_read_syntax); |
|
117 newline (os); |
|
118 } |
|
119 |
|
120 template <class MT> |
|
121 void |
|
122 octave_base_matrix<MT>::print_raw (ostream& os, bool pr_as_read_syntax) const |
|
123 { |
|
124 octave_print_internal (os, matrix, pr_as_read_syntax, |
|
125 current_print_indent_level ()); |
|
126 } |
|
127 |
|
128 template <class MT> |
|
129 bool |
|
130 octave_base_matrix<MT>::print_name_tag (ostream& os, const string& name) const |
|
131 { |
|
132 bool retval = false; |
|
133 |
|
134 indent (os); |
|
135 |
|
136 if (print_as_scalar ()) |
|
137 os << name << " = "; |
|
138 else |
|
139 { |
|
140 os << name << " ="; |
|
141 newline (os); |
|
142 newline (os); |
|
143 retval = true; |
|
144 } |
|
145 |
|
146 return retval; |
|
147 } |
|
148 |
|
149 /* |
|
150 ;;; Local Variables: *** |
|
151 ;;; mode: C++ *** |
|
152 ;;; End: *** |
|
153 */ |