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 |
3503
|
31 #include <iostream> |
3219
|
32 |
3220
|
33 #include "oct-obj.h" |
3219
|
34 #include "ov-base.h" |
|
35 #include "ov-base-mat.h" |
3572
|
36 #include "pr-output.h" |
3219
|
37 |
|
38 template <class MT> |
3220
|
39 octave_value |
|
40 octave_base_matrix<MT>::do_index_op (const octave_value_list& idx) |
|
41 { |
|
42 octave_value retval; |
|
43 |
|
44 int len = idx.length (); |
|
45 |
|
46 switch (len) |
|
47 { |
|
48 case 2: |
|
49 { |
|
50 idx_vector i = idx (0).index_vector (); |
|
51 idx_vector j = idx (1).index_vector (); |
|
52 |
|
53 retval = MT (matrix.index (i, j)); |
|
54 } |
|
55 break; |
|
56 |
|
57 case 1: |
|
58 { |
|
59 idx_vector i = idx (0).index_vector (); |
|
60 |
|
61 retval = MT (matrix.index (i)); |
|
62 } |
|
63 break; |
|
64 |
|
65 default: |
|
66 { |
3523
|
67 std::string n = type_name (); |
3220
|
68 |
|
69 error ("invalid number of indices (%d) for %s value", |
|
70 len, n.c_str ()); |
|
71 } |
|
72 break; |
|
73 } |
|
74 |
|
75 return retval; |
|
76 } |
|
77 |
|
78 template <class MT> |
|
79 bool |
|
80 octave_base_matrix<MT>::is_true (void) const |
|
81 { |
|
82 bool retval = false; |
|
83 |
|
84 if (rows () == 0 || columns () == 0) |
|
85 { |
|
86 int flag = Vpropagate_empty_matrices; |
|
87 |
|
88 if (flag < 0) |
|
89 warning ("empty matrix used in conditional expression"); |
|
90 else if (flag == 0) |
|
91 error ("empty matrix used in conditional expression"); |
|
92 } |
|
93 else |
|
94 { |
|
95 boolMatrix m = (matrix.all ()) . all (); |
|
96 |
|
97 retval = (m.rows () == 1 && m.columns () == 1 && m (0, 0) != 0.0); |
|
98 } |
|
99 |
|
100 return retval; |
|
101 } |
|
102 |
|
103 template <class MT> |
3219
|
104 bool |
|
105 octave_base_matrix<MT>::print_as_scalar (void) const |
|
106 { |
|
107 int nr = rows (); |
|
108 int nc = columns (); |
|
109 |
|
110 return (nr == 1 && nc == 1 || (nr == 0 || nc == 0)); |
|
111 } |
|
112 |
|
113 template <class MT> |
|
114 void |
3523
|
115 octave_base_matrix<MT>::print (std::ostream& os, bool pr_as_read_syntax) const |
3219
|
116 { |
|
117 print_raw (os, pr_as_read_syntax); |
|
118 newline (os); |
|
119 } |
|
120 |
|
121 template <class MT> |
|
122 void |
3523
|
123 octave_base_matrix<MT>::print_raw (std::ostream& os, bool pr_as_read_syntax) const |
3219
|
124 { |
|
125 octave_print_internal (os, matrix, pr_as_read_syntax, |
|
126 current_print_indent_level ()); |
|
127 } |
|
128 |
|
129 template <class MT> |
|
130 bool |
3523
|
131 octave_base_matrix<MT>::print_name_tag (std::ostream& os, const std::string& name) const |
3219
|
132 { |
|
133 bool retval = false; |
|
134 |
|
135 indent (os); |
|
136 |
|
137 if (print_as_scalar ()) |
|
138 os << name << " = "; |
|
139 else |
|
140 { |
|
141 os << name << " ="; |
|
142 newline (os); |
|
143 newline (os); |
|
144 retval = true; |
|
145 } |
|
146 |
|
147 return retval; |
|
148 } |
|
149 |
|
150 /* |
|
151 ;;; Local Variables: *** |
|
152 ;;; mode: C++ *** |
|
153 ;;; End: *** |
|
154 */ |