3219
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1998, 2000, 2002, 2003, 2004, 2005, 2006, 2007 |
|
4 John W. Eaton |
3219
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
3219
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
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" |
6376
|
34 #include "MatrixType.h" |
3219
|
35 |
|
36 #include "error.h" |
4649
|
37 #include "oct-obj.h" |
3219
|
38 #include "ov-base.h" |
|
39 #include "ov-typeinfo.h" |
|
40 |
|
41 class Octave_map; |
|
42 |
|
43 class tree_walker; |
|
44 |
|
45 // Real matrix values. |
|
46 |
3223
|
47 template <class MT> |
|
48 class |
3219
|
49 octave_base_matrix : public octave_base_value |
|
50 { |
|
51 public: |
|
52 |
|
53 octave_base_matrix (void) |
5785
|
54 : octave_base_value (), typ (MatrixType ()) { } |
3219
|
55 |
6376
|
56 octave_base_matrix (const MT& m, const MatrixType& t = MatrixType ()) |
5785
|
57 : octave_base_value (), matrix (m), typ (t) |
4676
|
58 { |
|
59 if (matrix.ndims () == 0) |
|
60 matrix.resize (dim_vector (0, 0)); |
|
61 } |
3219
|
62 |
|
63 octave_base_matrix (const octave_base_matrix& m) |
5785
|
64 : octave_base_value (), matrix (m.matrix), typ (m.typ) { } |
3219
|
65 |
|
66 ~octave_base_matrix (void) { } |
|
67 |
5759
|
68 octave_base_value *clone (void) const { return new octave_base_matrix (*this); } |
|
69 octave_base_value *empty_clone (void) const { return new octave_base_matrix (); } |
3933
|
70 |
4901
|
71 size_t byte_size (void) const { return matrix.byte_size (); } |
|
72 |
5147
|
73 octave_value squeeze (void) const { return MT (matrix.squeeze ()); } |
4532
|
74 |
4247
|
75 octave_value subsref (const std::string& type, |
4219
|
76 const std::list<octave_value_list>& idx); |
3219
|
77 |
4661
|
78 octave_value_list subsref (const std::string&, |
|
79 const std::list<octave_value_list>&, int) |
4271
|
80 { |
|
81 panic_impossible (); |
|
82 return octave_value_list (); |
|
83 } |
|
84 |
4247
|
85 octave_value subsasgn (const std::string& type, |
4219
|
86 const std::list<octave_value_list>& idx, |
3933
|
87 const octave_value& rhs); |
|
88 |
5885
|
89 octave_value do_index_op (const octave_value_list& idx, |
|
90 bool resize_ok = false); |
3220
|
91 |
3928
|
92 void assign (const octave_value_list& idx, const MT& rhs); |
|
93 |
4513
|
94 dim_vector dims (void) const { return matrix.dims (); } |
|
95 |
5602
|
96 octave_idx_type nnz (void) const { return matrix.nnz (); } |
|
97 |
4567
|
98 octave_value reshape (const dim_vector& new_dims) const |
|
99 { return MT (matrix.reshape (new_dims)); } |
|
100 |
4593
|
101 octave_value permute (const Array<int>& vec, bool inv = false) const |
|
102 { return MT (matrix.permute (vec, inv)); } |
|
103 |
5731
|
104 octave_value resize (const dim_vector& dv, bool fill = false) const; |
4915
|
105 |
4017
|
106 octave_value all (int dim = 0) const { return matrix.all (dim); } |
|
107 octave_value any (int dim = 0) const { return matrix.any (dim); } |
3221
|
108 |
5785
|
109 MatrixType matrix_type (void) const { return typ; } |
|
110 MatrixType matrix_type (const MatrixType& _typ) const |
|
111 { MatrixType ret = typ; typ = _typ; return ret; } |
|
112 |
7433
|
113 octave_value sort (octave_idx_type dim = 0, sortmode mode = UNDEFINED) const |
|
114 { return octave_value (matrix.sort (dim, mode)); } |
|
115 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, |
|
116 sortmode mode = UNDEFINED) const |
|
117 { return octave_value (matrix.sort (sidx, dim, mode)); } |
|
118 |
3221
|
119 bool is_matrix_type (void) const { return true; } |
|
120 |
|
121 bool is_numeric_type (void) const { return true; } |
|
122 |
3219
|
123 bool is_defined (void) const { return true; } |
|
124 |
|
125 bool is_constant (void) const { return true; } |
|
126 |
3220
|
127 bool is_true (void) const; |
|
128 |
4604
|
129 bool print_as_scalar (void) const; |
3219
|
130 |
3523
|
131 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
3219
|
132 |
3933
|
133 void print_info (std::ostream& os, const std::string& prefix) const; |
|
134 |
5900
|
135 // Unsafe. This function exists to support the MEX interface. |
|
136 // You should not use it anywhere else. |
|
137 void *mex_get_data (void) const { return matrix.mex_get_data (); } |
|
138 |
3219
|
139 protected: |
|
140 |
|
141 MT matrix; |
5785
|
142 |
|
143 mutable MatrixType typ; |
3219
|
144 }; |
|
145 |
|
146 #endif |
|
147 |
|
148 /* |
|
149 ;;; Local Variables: *** |
|
150 ;;; mode: C++ *** |
|
151 ;;; End: *** |
|
152 */ |