3665
|
1 /* |
|
2 |
|
3 Copyright (C) 2000 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> |
|
32 |
|
33 #include "lo-ieee.h" |
|
34 #include "lo-utils.h" |
|
35 #include "mx-base.h" |
|
36 |
|
37 #include "gripes.h" |
|
38 #include "oct-obj.h" |
|
39 #include "oct-lvalue.h" |
|
40 #include "ops.h" |
|
41 #include "ov-base.h" |
|
42 #include "ov-base-nd-array.h" |
|
43 #include "ov-base-nd-array.cc" |
|
44 #include "ov-re-nd-array.h" |
|
45 #include "pr-output.h" |
|
46 #include "variables.h" |
|
47 |
|
48 template class octave_base_nd_array<ArrayN<double> >; |
|
49 |
|
50 DEFINE_OCTAVE_ALLOCATOR (octave_double_nd_array); |
|
51 |
|
52 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_double_nd_array, |
|
53 "double-nd-array"); |
|
54 |
|
55 #if 0 |
|
56 octave_value * |
|
57 octave_matrix::try_narrowing_conversion (void) |
|
58 { |
|
59 octave_value *retval = 0; |
|
60 |
|
61 int nr = matrix.rows (); |
|
62 int nc = matrix.cols (); |
|
63 |
|
64 if (nr == 1 && nc == 1) |
|
65 retval = new octave_scalar (matrix (0, 0)); |
|
66 |
|
67 return retval; |
|
68 } |
|
69 |
|
70 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) |
|
71 extern void assign (Array2<double>&, const Array2<double>&); |
|
72 #endif |
|
73 |
|
74 void |
|
75 octave_matrix::assign (const octave_value_list& idx, const Matrix& rhs) |
|
76 { |
|
77 int len = idx.length (); |
|
78 |
|
79 switch (len) |
|
80 { |
|
81 case 2: |
|
82 { |
|
83 idx_vector i = idx (0).index_vector (); |
|
84 idx_vector j = idx (1).index_vector (); |
|
85 |
|
86 matrix.set_index (i); |
|
87 matrix.set_index (j); |
|
88 |
|
89 ::assign (matrix, rhs); |
|
90 } |
|
91 break; |
|
92 |
|
93 case 1: |
|
94 { |
|
95 idx_vector i = idx (0).index_vector (); |
|
96 |
|
97 matrix.set_index (i); |
|
98 |
|
99 ::assign (matrix, rhs); |
|
100 } |
|
101 break; |
|
102 |
|
103 default: |
|
104 error ("invalid number of indices (%d) for indexed matrix assignment", |
|
105 len); |
|
106 break; |
|
107 } |
|
108 } |
|
109 |
|
110 bool |
|
111 octave_matrix::valid_as_scalar_index (void) const |
|
112 { |
|
113 // XXX FIXME XXX |
|
114 return false; |
|
115 } |
|
116 |
|
117 double |
|
118 octave_matrix::double_value (bool) const |
|
119 { |
|
120 double retval = octave_NaN; |
|
121 |
|
122 // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() |
|
123 if ((rows () == 1 && columns () == 1) |
|
124 || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) |
|
125 retval = matrix (0, 0); |
|
126 else |
|
127 gripe_invalid_conversion ("real matrix", "real scalar"); |
|
128 |
|
129 return retval; |
|
130 } |
|
131 |
|
132 Complex |
|
133 octave_matrix::complex_value (bool) const |
|
134 { |
|
135 Complex retval (octave_NaN, octave_NaN); |
|
136 |
|
137 if ((rows () == 1 && columns () == 1) |
|
138 || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) |
|
139 retval = matrix (0, 0); |
|
140 else |
|
141 gripe_invalid_conversion ("real matrix", "complex scalar"); |
|
142 |
|
143 return retval; |
|
144 } |
|
145 #endif |
|
146 |
|
147 /* |
|
148 ;;; Local Variables: *** |
|
149 ;;; mode: C++ *** |
|
150 ;;; End: *** |
|
151 */ |