Go to the documentation of this file.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_sparse_h)
00025 #define octave_base_sparse_h 1
00026
00027 #include <cstdlib>
00028
00029 #include <iosfwd>
00030 #include <string>
00031
00032 #include "str-vec.h"
00033
00034 #include "error.h"
00035 #include "oct-obj.h"
00036 #include "ov-base.h"
00037 #include "ov-typeinfo.h"
00038
00039 #include "boolSparse.h"
00040 #include "MatrixType.h"
00041
00042 class tree_walker;
00043
00044 class octave_sparse_bool_matrix;
00045
00046 template <class T>
00047 class
00048 octave_base_sparse : public octave_base_value
00049 {
00050 public:
00051
00052 octave_base_sparse (void)
00053 : octave_base_value (), matrix (), typ (MatrixType ())
00054 { }
00055
00056 octave_base_sparse (const T& a) : octave_base_value (), matrix (a),
00057 typ (MatrixType ())
00058 {
00059 if (matrix.ndims () == 0)
00060 matrix.resize (dim_vector (0, 0));
00061 }
00062
00063 octave_base_sparse (const T& a, const MatrixType& t) : octave_base_value (),
00064 matrix (a), typ (t)
00065 {
00066 if (matrix.ndims () == 0)
00067 matrix.resize (dim_vector (0, 0));
00068 }
00069
00070 octave_base_sparse (const octave_base_sparse& a) :
00071 octave_base_value (), matrix (a.matrix), typ (a.typ) { }
00072
00073 ~octave_base_sparse (void) { }
00074
00075 octave_idx_type nnz (void) const { return matrix.nnz (); }
00076
00077 octave_idx_type nzmax (void) const { return matrix.nzmax (); }
00078
00079 size_t byte_size (void) const { return matrix.byte_size (); }
00080
00081 octave_value squeeze (void) const { return matrix.squeeze (); }
00082
00083 octave_value full_value (void) const { return matrix.matrix_value (); }
00084
00085 octave_value subsref (const std::string& type,
00086 const std::list<octave_value_list>& idx);
00087
00088 octave_value_list subsref (const std::string& type,
00089 const std::list<octave_value_list>& idx, int)
00090 { return subsref (type, idx); }
00091
00092 octave_value subsasgn (const std::string& type,
00093 const std::list<octave_value_list>& idx,
00094 const octave_value& rhs);
00095
00096 void assign (const octave_value_list& idx, const T& rhs);
00097
00098 void delete_elements (const octave_value_list& idx);
00099
00100 dim_vector dims (void) const { return matrix.dims (); }
00101
00102 octave_value do_index_op (const octave_value_list& idx,
00103 bool resize_ok = false);
00104
00105 octave_value reshape (const dim_vector& new_dims) const
00106 { return T (matrix.reshape (new_dims)); }
00107
00108 octave_value permute (const Array<int>& vec, bool inv = false) const
00109 { return T (matrix.permute (vec, inv)); }
00110
00111 octave_value resize (const dim_vector& dv, bool = false) const;
00112
00113 octave_value all (int dim = 0) const { return matrix.all (dim); }
00114 octave_value any (int dim = 0) const { return matrix.any (dim); }
00115
00116 octave_value diag (octave_idx_type k = 0) const
00117 { return octave_value (matrix.diag (k)); }
00118
00119 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
00120 { return octave_value (matrix.sort (dim, mode)); }
00121 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
00122 sortmode mode = ASCENDING) const
00123 { return octave_value (matrix.sort (sidx, dim, mode)); }
00124
00125 sortmode is_sorted (sortmode mode = UNSORTED) const
00126 { return full_value ().is_sorted (mode); }
00127
00128 MatrixType matrix_type (void) const { return typ; }
00129 MatrixType matrix_type (const MatrixType& _typ) const
00130 { MatrixType ret = typ; typ = _typ; return ret; }
00131
00132 bool is_matrix_type (void) const { return true; }
00133
00134 bool is_numeric_type (void) const { return true; }
00135
00136 bool is_sparse_type (void) const { return true; }
00137
00138 bool is_defined (void) const { return true; }
00139
00140 bool is_constant (void) const { return true; }
00141
00142 bool is_true (void) const;
00143
00144 octave_idx_type capacity (void) const { return matrix.capacity (); }
00145
00146 bool print_as_scalar (void) const;
00147
00148 void print (std::ostream& os, bool pr_as_read_syntax = false) const;
00149
00150 void print_info (std::ostream& os, const std::string& prefix) const;
00151
00152 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
00153
00154 bool save_ascii (std::ostream& os);
00155
00156 bool load_ascii (std::istream& is);
00157
00158
00159
00160 void *mex_get_data (void) const { return matrix.mex_get_data (); }
00161
00162 octave_idx_type *mex_get_ir (void) const { return matrix.mex_get_ir (); }
00163
00164 octave_idx_type *mex_get_jc (void) const { return matrix.mex_get_jc (); }
00165
00166 protected:
00167
00168 octave_value map (octave_base_value::unary_mapper_t umap) const;
00169
00170 T matrix;
00171
00172 mutable MatrixType typ;
00173 };
00174
00175 #endif