ov-perm.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_perm_matrix_h)
00024 #define octave_perm_matrix_h 1
00025 
00026 #include "mx-base.h"
00027 #include "str-vec.h"
00028 
00029 #include "ov-base.h"
00030 #include "ov-typeinfo.h"
00031 #include "oct-obj.h"
00032 
00033 class
00034 OCTINTERP_API
00035 octave_perm_matrix : public octave_base_value
00036 {
00037 public:
00038   octave_perm_matrix (void) : matrix (), dense_cache () { }
00039 
00040   octave_perm_matrix (const PermMatrix& p) : matrix (p), dense_cache () { }
00041 
00042   octave_base_value *clone (void) const { return new octave_perm_matrix (*this); }
00043   octave_base_value *empty_clone (void) const { return new octave_perm_matrix (); }
00044 
00045   type_conv_info numeric_conversion_function (void) const;
00046 
00047   octave_base_value *try_narrowing_conversion (void);
00048 
00049   size_t byte_size (void) const { return matrix.byte_size (); }
00050 
00051   octave_value squeeze (void) const { return matrix; }
00052 
00053   octave_value full_value (void) const { return to_dense (); }
00054 
00055   octave_value subsref (const std::string& type,
00056                         const std::list<octave_value_list>& idx);
00057 
00058   octave_value_list subsref (const std::string& type,
00059                              const std::list<octave_value_list>& idx, int)
00060     { return subsref (type, idx); }
00061 
00062   octave_value do_index_op (const octave_value_list& idx,
00063                             bool resize_ok = false);
00064 
00065   dim_vector dims (void) const { return matrix.dims (); }
00066 
00067   octave_idx_type nnz (void) const { return matrix.rows (); }
00068 
00069   octave_value reshape (const dim_vector& new_dims) const
00070     { return to_dense ().reshape (new_dims); }
00071 
00072   octave_value permute (const Array<int>& vec, bool inv = false) const
00073     { return to_dense ().permute (vec, inv); }
00074 
00075   octave_value resize (const dim_vector& dv, bool fill = false) const
00076     { return to_dense ().resize (dv, fill); }
00077 
00078   octave_value all (int dim = 0) const { return to_dense ().all (dim); }
00079   octave_value any (int dim = 0) const { return to_dense ().any (dim); }
00080 
00081   MatrixType matrix_type (void) const { return MatrixType::Permuted_Diagonal; }
00082   MatrixType matrix_type (const MatrixType&) const
00083     { return matrix_type (); }
00084 
00085   octave_value diag (octave_idx_type k = 0) const
00086     { return to_dense () .diag (k); }
00087 
00088   octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
00089     { return to_dense ().sort (dim, mode); }
00090   octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
00091                      sortmode mode = ASCENDING) const
00092     { return to_dense ().sort (sidx, dim, mode); }
00093 
00094   sortmode is_sorted (sortmode mode = UNSORTED) const
00095     { return to_dense ().is_sorted (mode); }
00096 
00097   Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const
00098     { return to_dense ().sort_rows_idx (mode); }
00099 
00100   sortmode is_sorted_rows (sortmode mode = UNSORTED) const
00101     { return to_dense ().is_sorted_rows (mode); }
00102 
00103   builtin_type_t builtin_type (void) const { return btyp_double; }
00104 
00105   bool is_perm_matrix (void) const { return true; }
00106 
00107   bool is_matrix_type (void) const { return true; }
00108 
00109   bool is_numeric_type (void) const { return true; }
00110 
00111   bool is_defined (void) const { return true; }
00112 
00113   bool is_constant (void) const { return true; }
00114 
00115   bool is_real_matrix (void) const { return true; }
00116 
00117   bool is_real_type (void) const { return true; }
00118 
00119   bool is_double_type (void) const { return true; }
00120 
00121   bool is_float_type (void) const { return true; }
00122 
00123   bool is_true (void) const;
00124 
00125   double double_value (bool = false) const;
00126 
00127   float float_value (bool = false) const;
00128 
00129   double scalar_value (bool frc_str_conv = false) const
00130     { return double_value (frc_str_conv); }
00131 
00132   idx_vector index_vector (void) const;
00133 
00134   PermMatrix perm_matrix_value (void) const
00135     { return matrix; }
00136 
00137   Matrix matrix_value (bool = false) const;
00138 
00139   FloatMatrix float_matrix_value (bool = false) const;
00140 
00141   Complex complex_value (bool = false) const;
00142 
00143   FloatComplex float_complex_value (bool = false) const;
00144 
00145   ComplexMatrix complex_matrix_value (bool = false) const;
00146 
00147   FloatComplexMatrix float_complex_matrix_value (bool = false) const;
00148 
00149   ComplexNDArray complex_array_value (bool = false) const;
00150 
00151   FloatComplexNDArray float_complex_array_value (bool = false) const;
00152 
00153   boolNDArray bool_array_value (bool warn = false) const;
00154 
00155   charNDArray char_array_value (bool = false) const;
00156 
00157   NDArray array_value (bool = false) const;
00158 
00159   FloatNDArray float_array_value (bool = false) const;
00160 
00161   SparseMatrix sparse_matrix_value (bool = false) const;
00162 
00163   SparseBoolMatrix sparse_bool_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   bool save_binary (std::ostream& os, bool& save_as_floats);
00200 
00201   bool load_binary (std::istream& is, bool swap,
00202                     oct_mach_info::float_format fmt);
00203 
00204   int write (octave_stream& os, int block_size,
00205              oct_data_conv::data_type output_type, int skip,
00206              oct_mach_info::float_format flt_fmt) const;
00207 
00208   mxArray *as_mxArray (void) const;
00209 
00210   bool print_as_scalar (void) const;
00211 
00212   void print (std::ostream& os, bool pr_as_read_syntax = false) const;
00213 
00214   void print_info (std::ostream& os, const std::string& prefix) const;
00215 
00216   octave_value map (unary_mapper_t umap) const
00217     { return to_dense ().map (umap); }
00218 
00219 protected:
00220 
00221   PermMatrix matrix;
00222 
00223   virtual octave_value to_dense (void) const;
00224 
00225   mutable octave_value dense_cache;
00226 
00227 private:
00228 
00229   DECLARE_OCTAVE_ALLOCATOR
00230 
00231   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00232 };
00233 
00234 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines