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 |
|
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) |
|
53 : octave_base_value () { } |
|
54 |
|
55 octave_base_matrix (const MT& m) |
4676
|
56 : octave_base_value (), matrix (m) |
|
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) |
|
63 : octave_base_value (), matrix (m.matrix) { } |
|
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 |
|
88 octave_value do_index_op (const octave_value_list& idx, int resize_ok); |
|
89 |
|
90 octave_value do_index_op (const octave_value_list& idx) |
|
91 { return do_index_op (idx, 0); } |
3220
|
92 |
3928
|
93 void assign (const octave_value_list& idx, const MT& rhs); |
|
94 |
4513
|
95 dim_vector dims (void) const { return matrix.dims (); } |
|
96 |
5602
|
97 octave_idx_type nnz (void) const { return matrix.nnz (); } |
|
98 |
4567
|
99 octave_value reshape (const dim_vector& new_dims) const |
|
100 { return MT (matrix.reshape (new_dims)); } |
|
101 |
4593
|
102 octave_value permute (const Array<int>& vec, bool inv = false) const |
|
103 { return MT (matrix.permute (vec, inv)); } |
|
104 |
5731
|
105 octave_value resize (const dim_vector& dv, bool fill = false) const; |
4915
|
106 |
4017
|
107 octave_value all (int dim = 0) const { return matrix.all (dim); } |
|
108 octave_value any (int dim = 0) const { return matrix.any (dim); } |
3221
|
109 |
|
110 bool is_matrix_type (void) const { return true; } |
|
111 |
|
112 bool is_numeric_type (void) const { return true; } |
|
113 |
3219
|
114 bool is_defined (void) const { return true; } |
|
115 |
|
116 bool is_constant (void) const { return true; } |
|
117 |
3220
|
118 bool is_true (void) const; |
|
119 |
4604
|
120 bool print_as_scalar (void) const; |
3219
|
121 |
3523
|
122 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
3219
|
123 |
3933
|
124 void print_info (std::ostream& os, const std::string& prefix) const; |
|
125 |
3219
|
126 protected: |
|
127 |
|
128 MT matrix; |
|
129 }; |
|
130 |
|
131 #endif |
|
132 |
|
133 /* |
|
134 ;;; Local Variables: *** |
|
135 ;;; mode: C++ *** |
|
136 ;;; End: *** |
|
137 */ |