00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_base_matrix_h)
00025 #define octave_base_matrix_h 1
00026
00027 #include <cstdlib>
00028
00029 #include <iosfwd>
00030 #include <string>
00031
00032 #include "mx-base.h"
00033 #include "str-vec.h"
00034 #include "MatrixType.h"
00035
00036 #include "error.h"
00037 #include "oct-obj.h"
00038 #include "ov-base.h"
00039 #include "ov-typeinfo.h"
00040
00041 class Octave_map;
00042
00043 class tree_walker;
00044
00045
00046
00047 template <class MT>
00048 class
00049 octave_base_matrix : public octave_base_value
00050 {
00051 public:
00052
00053 octave_base_matrix (void)
00054 : octave_base_value (), typ (), idx_cache () { }
00055
00056 octave_base_matrix (const MT& m, const MatrixType& t = MatrixType ())
00057 : octave_base_value (), matrix (m),
00058 typ (t.is_known () ? new MatrixType(t) : 0), idx_cache ()
00059 {
00060 if (matrix.ndims () == 0)
00061 matrix.resize (dim_vector (0, 0));
00062 }
00063
00064 octave_base_matrix (const octave_base_matrix& m)
00065 : octave_base_value (), matrix (m.matrix),
00066 typ (m.typ ? new MatrixType (*m.typ) : 0),
00067 idx_cache (m.idx_cache ? new idx_vector (*m.idx_cache) : 0)
00068 { }
00069
00070 ~octave_base_matrix (void) { clear_cached_info (); }
00071
00072 octave_base_value *clone (void) const { return new octave_base_matrix (*this); }
00073 octave_base_value *empty_clone (void) const { return new octave_base_matrix (); }
00074
00075 size_t byte_size (void) const { return matrix.byte_size (); }
00076
00077 octave_value squeeze (void) const { return MT (matrix.squeeze ()); }
00078
00079 octave_value full_value (void) const { return matrix; }
00080
00081 void maybe_economize (void) { matrix.maybe_economize (); }
00082
00083 octave_value subsref (const std::string& type,
00084 const std::list<octave_value_list>& idx);
00085
00086 octave_value_list subsref (const std::string& type,
00087 const std::list<octave_value_list>& idx, int)
00088 { return subsref (type, idx); }
00089
00090 octave_value subsasgn (const std::string& type,
00091 const std::list<octave_value_list>& idx,
00092 const octave_value& rhs);
00093
00094 octave_value do_index_op (const octave_value_list& idx,
00095 bool resize_ok = false);
00096
00097 void assign (const octave_value_list& idx, const MT& rhs);
00098
00099 void assign (const octave_value_list& idx, typename MT::element_type rhs);
00100
00101 void delete_elements (const octave_value_list& idx);
00102
00103 dim_vector dims (void) const { return matrix.dims (); }
00104
00105 octave_idx_type numel (void) const { return matrix.numel (); }
00106
00107 octave_idx_type nnz (void) const { return matrix.nnz (); }
00108
00109 octave_value reshape (const dim_vector& new_dims) const
00110 { return MT (matrix.reshape (new_dims)); }
00111
00112 octave_value permute (const Array<int>& vec, bool inv = false) const
00113 { return MT (matrix.permute (vec, inv)); }
00114
00115 octave_value resize (const dim_vector& dv, bool fill = false) const;
00116
00117 octave_value all (int dim = 0) const { return matrix.all (dim); }
00118 octave_value any (int dim = 0) const { return matrix.any (dim); }
00119
00120 MatrixType matrix_type (void) const { return typ ? *typ : MatrixType (); }
00121 MatrixType matrix_type (const MatrixType& _typ) const;
00122
00123 octave_value diag (octave_idx_type k = 0) const
00124 { return octave_value (matrix.diag (k)); }
00125
00126 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
00127 { return octave_value (matrix.sort (dim, mode)); }
00128 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
00129 sortmode mode = ASCENDING) const
00130 { return octave_value (matrix.sort (sidx, dim, mode)); }
00131
00132 sortmode is_sorted (sortmode mode = UNSORTED) const
00133 { return matrix.is_sorted (mode); }
00134
00135 Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const
00136 { return matrix.sort_rows_idx (mode); }
00137
00138 sortmode is_sorted_rows (sortmode mode = UNSORTED) const
00139 { return matrix.is_sorted_rows (mode); }
00140
00141 bool is_matrix_type (void) const { return true; }
00142
00143 bool is_numeric_type (void) const { return true; }
00144
00145 bool is_defined (void) const { return true; }
00146
00147 bool is_constant (void) const { return true; }
00148
00149 bool is_true (void) const;
00150
00151 bool print_as_scalar (void) const;
00152
00153 void print (std::ostream& os, bool pr_as_read_syntax = false) const;
00154
00155 void print_info (std::ostream& os, const std::string& prefix) const;
00156
00157 MT& matrix_ref (void)
00158 {
00159 clear_cached_info ();
00160 return matrix;
00161 }
00162
00163 protected:
00164
00165 MT matrix;
00166
00167 idx_vector set_idx_cache (const idx_vector& idx) const
00168 {
00169 delete idx_cache;
00170 idx_cache = idx ? new idx_vector (idx) : 0;
00171 return idx;
00172 }
00173
00174 void clear_cached_info (void) const
00175 {
00176 delete typ; typ = 0;
00177 delete idx_cache; idx_cache = 0;
00178 }
00179
00180 mutable MatrixType *typ;
00181 mutable idx_vector *idx_cache;
00182 };
00183
00184 #endif
00185
00186
00187
00188
00189
00190