Mercurial > hg > octave-lyh
annotate src/ov-base-mat.h @ 7635:ba7a3e20ee3d
add -struct modifier to save
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 25 Mar 2008 15:29:26 -0400 |
parents | 36594d5bbe13 |
children | 443a8f5a50fd |
rev | line source |
---|---|
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 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
113 octave_value diag (octave_idx_type k = 0) const |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
114 { return octave_value (matrix.diag (k)); } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
115 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
116 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const |
7433 | 117 { return octave_value (matrix.sort (dim, mode)); } |
118 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, | |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
119 sortmode mode = ASCENDING) const |
7433 | 120 { return octave_value (matrix.sort (sidx, dim, mode)); } |
121 | |
3221 | 122 bool is_matrix_type (void) const { return true; } |
123 | |
124 bool is_numeric_type (void) const { return true; } | |
125 | |
3219 | 126 bool is_defined (void) const { return true; } |
127 | |
128 bool is_constant (void) const { return true; } | |
129 | |
3220 | 130 bool is_true (void) const; |
131 | |
4604 | 132 bool print_as_scalar (void) const; |
3219 | 133 |
3523 | 134 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
3219 | 135 |
3933 | 136 void print_info (std::ostream& os, const std::string& prefix) const; |
137 | |
5900 | 138 // Unsafe. This function exists to support the MEX interface. |
139 // You should not use it anywhere else. | |
140 void *mex_get_data (void) const { return matrix.mex_get_data (); } | |
141 | |
3219 | 142 protected: |
143 | |
144 MT matrix; | |
5785 | 145 |
146 mutable MatrixType typ; | |
3219 | 147 }; |
148 | |
149 #endif | |
150 | |
151 /* | |
152 ;;; Local Variables: *** | |
153 ;;; mode: C++ *** | |
154 ;;; End: *** | |
155 */ |