ov-base-diag.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2008-2012 Jaroslav Hajek
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
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 // Real matrix values.
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 (), matrix (), dense_cache () { }
00051 
00052   octave_base_diag (const DMT& m)
00053     : octave_base_value (), matrix (m), dense_cache ()
00054   { }
00055 
00056   octave_base_diag (const octave_base_diag& m)
00057     : octave_base_value (), matrix (m.matrix), dense_cache () { }
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 
00102   octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
00103     { return to_dense ().sort (dim, mode); }
00104   octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
00105                      sortmode mode = ASCENDING) const
00106     { return to_dense ().sort (sidx, dim, mode); }
00107 
00108   sortmode is_sorted (sortmode mode = UNSORTED) const
00109     { return to_dense ().is_sorted (mode); }
00110 
00111   Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const
00112     { return to_dense ().sort_rows_idx (mode); }
00113 
00114   sortmode is_sorted_rows (sortmode mode = UNSORTED) const
00115     { return to_dense ().is_sorted_rows (mode); }
00116 
00117   bool is_matrix_type (void) const { return true; }
00118 
00119   bool is_numeric_type (void) const { return true; }
00120 
00121   bool is_defined (void) const { return true; }
00122 
00123   bool is_constant (void) const { return true; }
00124 
00125   bool is_true (void) const;
00126 
00127   bool is_diag_matrix (void) const { return true; }
00128 
00129   double double_value (bool = false) const;
00130 
00131   float float_value (bool = false) const;
00132 
00133   double scalar_value (bool frc_str_conv = false) const
00134     { return double_value (frc_str_conv); }
00135 
00136   idx_vector index_vector (void) const;
00137 
00138   Matrix matrix_value (bool = false) const;
00139 
00140   FloatMatrix float_matrix_value (bool = false) const;
00141 
00142   Complex complex_value (bool = false) const;
00143 
00144   FloatComplex float_complex_value (bool = false) const;
00145 
00146   ComplexMatrix complex_matrix_value (bool = false) const;
00147 
00148   FloatComplexMatrix float_complex_matrix_value (bool = false) const;
00149 
00150   ComplexNDArray complex_array_value (bool = false) const;
00151 
00152   FloatComplexNDArray float_complex_array_value (bool = false) const;
00153 
00154   boolNDArray bool_array_value (bool warn = false) const;
00155 
00156   charNDArray char_array_value (bool = false) const;
00157 
00158   NDArray array_value (bool = false) const;
00159 
00160   FloatNDArray float_array_value (bool = false) const;
00161 
00162   SparseMatrix sparse_matrix_value (bool = false) const;
00163 
00164   SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
00165 
00166   int8NDArray
00167   int8_array_value (void) const { return to_dense ().int8_array_value (); }
00168 
00169   int16NDArray
00170   int16_array_value (void) const { return to_dense ().int16_array_value (); }
00171 
00172   int32NDArray
00173   int32_array_value (void) const { return to_dense ().int32_array_value (); }
00174 
00175   int64NDArray
00176   int64_array_value (void) const { return to_dense ().int64_array_value (); }
00177 
00178   uint8NDArray
00179   uint8_array_value (void) const { return to_dense ().uint8_array_value (); }
00180 
00181   uint16NDArray
00182   uint16_array_value (void) const { return to_dense ().uint16_array_value (); }
00183 
00184   uint32NDArray
00185   uint32_array_value (void) const { return to_dense ().uint32_array_value (); }
00186 
00187   uint64NDArray
00188   uint64_array_value (void) const { return to_dense ().uint64_array_value (); }
00189 
00190   octave_value convert_to_str_internal (bool pad, bool force, char type) const;
00191 
00192   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
00193 
00194   bool save_ascii (std::ostream& os);
00195 
00196   bool load_ascii (std::istream& is);
00197 
00198   int write (octave_stream& os, int block_size,
00199              oct_data_conv::data_type output_type, int skip,
00200              oct_mach_info::float_format flt_fmt) const;
00201 
00202   mxArray *as_mxArray (void) const;
00203 
00204   bool print_as_scalar (void) const;
00205 
00206   void print (std::ostream& os, bool pr_as_read_syntax = false) const;
00207 
00208   void print_info (std::ostream& os, const std::string& prefix) const;
00209 
00210 protected:
00211 
00212   DMT matrix;
00213 
00214   octave_value to_dense (void) const;
00215 
00216   virtual bool chk_valid_scalar (const octave_value&,
00217                                  typename DMT::element_type&) const = 0;
00218 
00219 private:
00220 
00221   mutable octave_value dense_cache;
00222 
00223 };
00224 
00225 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines