3219
|
1 /* |
|
2 |
|
3 Copyright (C) 1998 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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
3219
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_base_matrix_h) |
|
25 #define octave_base_matrix_h 1 |
|
26 |
|
27 #include <cstdlib> |
|
28 |
3503
|
29 #include <iostream> |
3219
|
30 #include <string> |
|
31 |
|
32 #include "mx-base.h" |
|
33 #include "str-vec.h" |
|
34 |
|
35 #include "error.h" |
4649
|
36 #include "oct-obj.h" |
3219
|
37 #include "ov-base.h" |
|
38 #include "ov-typeinfo.h" |
|
39 |
5785
|
40 #include "MatrixType.h" |
|
41 |
3219
|
42 class Octave_map; |
|
43 |
|
44 class tree_walker; |
|
45 |
|
46 // Real matrix values. |
|
47 |
3223
|
48 template <class MT> |
|
49 class |
3219
|
50 octave_base_matrix : public octave_base_value |
|
51 { |
|
52 public: |
|
53 |
|
54 octave_base_matrix (void) |
5785
|
55 : octave_base_value (), typ (MatrixType ()) { } |
3219
|
56 |
|
57 octave_base_matrix (const MT& m) |
5785
|
58 : octave_base_value (), matrix (m), typ (MatrixType ()) |
|
59 { |
|
60 if (matrix.ndims () == 0) |
|
61 matrix.resize (dim_vector (0, 0)); |
|
62 } |
|
63 |
|
64 octave_base_matrix (const MT& m, const MatrixType& t) |
|
65 : octave_base_value (), matrix (m), typ (t) |
4676
|
66 { |
|
67 if (matrix.ndims () == 0) |
|
68 matrix.resize (dim_vector (0, 0)); |
|
69 } |
3219
|
70 |
|
71 octave_base_matrix (const octave_base_matrix& m) |
5785
|
72 : octave_base_value (), matrix (m.matrix), typ (m.typ) { } |
3219
|
73 |
|
74 ~octave_base_matrix (void) { } |
|
75 |
5759
|
76 octave_base_value *clone (void) const { return new octave_base_matrix (*this); } |
|
77 octave_base_value *empty_clone (void) const { return new octave_base_matrix (); } |
3933
|
78 |
4901
|
79 size_t byte_size (void) const { return matrix.byte_size (); } |
|
80 |
5147
|
81 octave_value squeeze (void) const { return MT (matrix.squeeze ()); } |
4532
|
82 |
4247
|
83 octave_value subsref (const std::string& type, |
4219
|
84 const std::list<octave_value_list>& idx); |
3219
|
85 |
4661
|
86 octave_value_list subsref (const std::string&, |
|
87 const std::list<octave_value_list>&, int) |
4271
|
88 { |
|
89 panic_impossible (); |
|
90 return octave_value_list (); |
|
91 } |
|
92 |
4247
|
93 octave_value subsasgn (const std::string& type, |
4219
|
94 const std::list<octave_value_list>& idx, |
3933
|
95 const octave_value& rhs); |
|
96 |
5885
|
97 octave_value do_index_op (const octave_value_list& idx, |
|
98 bool resize_ok = false); |
3220
|
99 |
3928
|
100 void assign (const octave_value_list& idx, const MT& rhs); |
|
101 |
4513
|
102 dim_vector dims (void) const { return matrix.dims (); } |
|
103 |
5602
|
104 octave_idx_type nnz (void) const { return matrix.nnz (); } |
|
105 |
4567
|
106 octave_value reshape (const dim_vector& new_dims) const |
|
107 { return MT (matrix.reshape (new_dims)); } |
|
108 |
4593
|
109 octave_value permute (const Array<int>& vec, bool inv = false) const |
|
110 { return MT (matrix.permute (vec, inv)); } |
|
111 |
5731
|
112 octave_value resize (const dim_vector& dv, bool fill = false) const; |
4915
|
113 |
4017
|
114 octave_value all (int dim = 0) const { return matrix.all (dim); } |
|
115 octave_value any (int dim = 0) const { return matrix.any (dim); } |
3221
|
116 |
5785
|
117 MatrixType matrix_type (void) const { return typ; } |
|
118 MatrixType matrix_type (const MatrixType& _typ) const |
|
119 { MatrixType ret = typ; typ = _typ; return ret; } |
|
120 |
3221
|
121 bool is_matrix_type (void) const { return true; } |
|
122 |
|
123 bool is_numeric_type (void) const { return true; } |
|
124 |
3219
|
125 bool is_defined (void) const { return true; } |
|
126 |
|
127 bool is_constant (void) const { return true; } |
|
128 |
3220
|
129 bool is_true (void) const; |
|
130 |
4604
|
131 bool print_as_scalar (void) const; |
3219
|
132 |
3523
|
133 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
3219
|
134 |
3933
|
135 void print_info (std::ostream& os, const std::string& prefix) const; |
|
136 |
3219
|
137 protected: |
|
138 |
|
139 MT matrix; |
5785
|
140 |
|
141 mutable MatrixType typ; |
3219
|
142 }; |
|
143 |
|
144 #endif |
|
145 |
|
146 /* |
|
147 ;;; Local Variables: *** |
|
148 ;;; mode: C++ *** |
|
149 ;;; End: *** |
|
150 */ |