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