00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_base_diag_h)
00024 #define octave_base_diag_h 1
00025
00026 #include <cstdlib>
00027
00028 #include <iosfwd>
00029 #include <string>
00030
00031 #include "mx-base.h"
00032 #include "str-vec.h"
00033
00034 #include "oct-obj.h"
00035 #include "ov-base.h"
00036 #include "ov-typeinfo.h"
00037
00038 class tree_walker;
00039
00040
00041
00042 template <class DMT, class MT>
00043 class
00044 octave_base_diag : public octave_base_value
00045 {
00046
00047 public:
00048
00049 octave_base_diag (void)
00050 : octave_base_value () { }
00051
00052 octave_base_diag (const DMT& m)
00053 : octave_base_value (), matrix (m)
00054 { }
00055
00056 octave_base_diag (const octave_base_diag& m)
00057 : octave_base_value (), matrix (m.matrix) { }
00058
00059 ~octave_base_diag (void) { }
00060
00061 size_t byte_size (void) const { return matrix.byte_size (); }
00062
00063 octave_value squeeze (void) const { return matrix; }
00064
00065 octave_value full_value (void) const { return to_dense (); }
00066
00067 octave_value subsref (const std::string& type,
00068 const std::list<octave_value_list>& idx);
00069
00070 octave_value_list subsref (const std::string& type,
00071 const std::list<octave_value_list>& idx, int)
00072 { return subsref (type, idx); }
00073
00074 octave_value do_index_op (const octave_value_list& idx,
00075 bool resize_ok = false);
00076
00077 octave_value subsasgn (const std::string& type,
00078 const std::list<octave_value_list>& idx,
00079 const octave_value& rhs);
00080
00081 dim_vector dims (void) const { return matrix.dims (); }
00082
00083 octave_idx_type nnz (void) const { return to_dense ().nnz (); }
00084
00085 octave_value reshape (const dim_vector& new_dims) const
00086 { return to_dense ().reshape (new_dims); }
00087
00088 octave_value permute (const Array<int>& vec, bool inv = false) const
00089 { return to_dense ().permute (vec, inv); }
00090
00091 octave_value resize (const dim_vector& dv, bool fill = false) const;
00092
00093 octave_value all (int dim = 0) const { return MT (matrix).all (dim); }
00094 octave_value any (int dim = 0) const { return MT (matrix).any (dim); }
00095
00096 MatrixType matrix_type (void) const { return MatrixType::Diagonal; }
00097 MatrixType matrix_type (const MatrixType&) const
00098 { return matrix_type (); }
00099
00100 octave_value diag (octave_idx_type k = 0) const
00101 { return octave_value (matrix.diag (k)); }
00102
00103 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
00104 { return to_dense ().sort (dim, mode); }
00105 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
00106 sortmode mode = ASCENDING) const
00107 { return to_dense ().sort (sidx, dim, mode); }
00108
00109 sortmode is_sorted (sortmode mode = UNSORTED) const
00110 { return to_dense ().is_sorted (mode); }
00111
00112 Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const
00113 { return to_dense ().sort_rows_idx (mode); }
00114
00115 sortmode is_sorted_rows (sortmode mode = UNSORTED) const
00116 { return to_dense ().is_sorted_rows (mode); }
00117
00118 bool is_matrix_type (void) const { return true; }
00119
00120 bool is_numeric_type (void) const { return true; }
00121
00122 bool is_defined (void) const { return true; }
00123
00124 bool is_constant (void) const { return true; }
00125
00126 bool is_true (void) const;
00127
00128 bool is_diag_matrix (void) const { return true; }
00129
00130 double double_value (bool = false) const;
00131
00132 float float_value (bool = false) const;
00133
00134 double scalar_value (bool frc_str_conv = false) const
00135 { return double_value (frc_str_conv); }
00136
00137 idx_vector index_vector (void) const;
00138
00139 Matrix matrix_value (bool = false) const;
00140
00141 FloatMatrix float_matrix_value (bool = false) const;
00142
00143 Complex complex_value (bool = false) const;
00144
00145 FloatComplex float_complex_value (bool = false) const;
00146
00147 ComplexMatrix complex_matrix_value (bool = false) const;
00148
00149 FloatComplexMatrix float_complex_matrix_value (bool = false) const;
00150
00151 ComplexNDArray complex_array_value (bool = false) const;
00152
00153 FloatComplexNDArray float_complex_array_value (bool = false) const;
00154
00155 boolNDArray bool_array_value (bool warn = false) const;
00156
00157 charNDArray char_array_value (bool = false) const;
00158
00159 NDArray array_value (bool = false) const;
00160
00161 FloatNDArray float_array_value (bool = false) const;
00162
00163 SparseMatrix sparse_matrix_value (bool = false) const;
00164
00165 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
00166
00167 int8NDArray
00168 int8_array_value (void) const { return to_dense ().int8_array_value (); }
00169
00170 int16NDArray
00171 int16_array_value (void) const { return to_dense ().int16_array_value (); }
00172
00173 int32NDArray
00174 int32_array_value (void) const { return to_dense ().int32_array_value (); }
00175
00176 int64NDArray
00177 int64_array_value (void) const { return to_dense ().int64_array_value (); }
00178
00179 uint8NDArray
00180 uint8_array_value (void) const { return to_dense ().uint8_array_value (); }
00181
00182 uint16NDArray
00183 uint16_array_value (void) const { return to_dense ().uint16_array_value (); }
00184
00185 uint32NDArray
00186 uint32_array_value (void) const { return to_dense ().uint32_array_value (); }
00187
00188 uint64NDArray
00189 uint64_array_value (void) const { return to_dense ().uint64_array_value (); }
00190
00191 octave_value convert_to_str_internal (bool pad, bool force, char type) const;
00192
00193 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
00194
00195 bool save_ascii (std::ostream& os);
00196
00197 bool load_ascii (std::istream& is);
00198
00199 int write (octave_stream& os, int block_size,
00200 oct_data_conv::data_type output_type, int skip,
00201 oct_mach_info::float_format flt_fmt) const;
00202
00203 mxArray *as_mxArray (void) const;
00204
00205 bool print_as_scalar (void) const;
00206
00207 void print (std::ostream& os, bool pr_as_read_syntax = false) const;
00208
00209 void print_info (std::ostream& os, const std::string& prefix) const;
00210
00211
00212 octave_value erf (void) const;
00213 octave_value erfc (void) const;
00214 octave_value gamma (void) const;
00215 octave_value lgamma (void) const;
00216 octave_value acos (void) const;
00217 octave_value acosh (void) const;
00218 octave_value angle (void) const;
00219 octave_value arg (void) const;
00220 octave_value asin (void) const;
00221 octave_value asinh (void) const;
00222 octave_value atan (void) const;
00223 octave_value atanh (void) const;
00224 octave_value ceil (void) const;
00225 octave_value cos (void) const;
00226 octave_value cosh (void) const;
00227 octave_value exp (void) const;
00228 octave_value expm1 (void) const;
00229 octave_value fix (void) const;
00230 octave_value floor (void) const;
00231 octave_value log (void) const;
00232 octave_value log2 (void) const;
00233 octave_value log10 (void) const;
00234 octave_value log1p (void) const;
00235 octave_value round (void) const;
00236 octave_value roundb (void) const;
00237 octave_value signum (void) const;
00238 octave_value sin (void) const;
00239 octave_value sinh (void) const;
00240 octave_value tan (void) const;
00241 octave_value tanh (void) const;
00242 octave_value finite (void) const;
00243 octave_value isinf (void) const;
00244 octave_value isna (void) const;
00245 octave_value isnan (void) const;
00246
00247 protected:
00248
00249 DMT matrix;
00250
00251 octave_value to_dense (void) const;
00252
00253 virtual bool chk_valid_scalar (const octave_value&,
00254 typename DMT::element_type&) const = 0;
00255
00256 private:
00257
00258 mutable octave_value dense_cache;
00259
00260 };
00261
00262 #endif