ov-lazy-idx.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2010-2012 VZLU Prague
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_lazy_idx_h)
00024 #define octave_lazy_idx_h 1
00025 
00026 #include "ov-re-mat.h"
00027 
00028 // Lazy indices that stay in idx_vector form until the conversion to NDArray is
00029 // actually needed.
00030 
00031 class
00032 OCTINTERP_API
00033 octave_lazy_index : public octave_base_value
00034 {
00035 public:
00036 
00037   octave_lazy_index (void)
00038     : octave_base_value (), index (), value () { }
00039 
00040   octave_lazy_index (const idx_vector& idx)
00041     : octave_base_value (), index (idx), value () { }
00042 
00043   octave_lazy_index (const octave_lazy_index& i)
00044     : octave_base_value (), index (i.index), value (i.value) { }
00045 
00046   ~octave_lazy_index (void) { }
00047 
00048   octave_base_value *clone (void) const { return new octave_lazy_index (*this); }
00049   octave_base_value *empty_clone (void) const { return new octave_matrix (); }
00050 
00051   type_conv_info numeric_conversion_function (void) const;
00052 
00053   octave_base_value *try_narrowing_conversion (void);
00054 
00055   size_t byte_size (void) const { return numel () * sizeof (octave_idx_type); }
00056 
00057   octave_value squeeze (void) const;
00058 
00059   octave_value full_value (void) const { return make_value (); }
00060 
00061   idx_vector index_vector (void) const
00062     { return index; }
00063 
00064   builtin_type_t builtin_type (void) const { return btyp_double; }
00065 
00066   bool is_real_matrix (void) const { return true; }
00067 
00068   bool is_real_type (void) const { return true; }
00069 
00070   bool is_double_type (void) const { return true; }
00071 
00072   bool is_float_type (void) const { return true; }
00073 
00074   octave_value subsref (const std::string& type,
00075                         const std::list<octave_value_list>& idx)
00076     { return make_value ().subsref (type, idx); }
00077 
00078   octave_value_list subsref (const std::string& type,
00079                              const std::list<octave_value_list>& idx, int)
00080     { return subsref (type, idx); }
00081 
00082   octave_value do_index_op (const octave_value_list& idx,
00083                             bool resize_ok = false)
00084     { return make_value ().do_index_op (idx, resize_ok); }
00085 
00086   dim_vector dims (void) const { return index.orig_dimensions (); }
00087 
00088   octave_idx_type numel (void) const { return index.length (0); }
00089 
00090   octave_idx_type nnz (void) const { return numel (); }
00091 
00092   octave_value reshape (const dim_vector& new_dims) const;
00093 
00094   octave_value permute (const Array<int>& vec, bool inv = false) const;
00095 
00096   octave_value resize (const dim_vector& dv, bool fill = false) const
00097     { return make_value ().resize (dv, fill); }
00098 
00099   octave_value all (int dim = 0) const { return make_value ().all (dim); }
00100   octave_value any (int dim = 0) const { return make_value ().any (dim); }
00101 
00102   MatrixType matrix_type (void) const { return make_value ().matrix_type (); }
00103   MatrixType matrix_type (const MatrixType& _typ) const
00104     { return make_value ().matrix_type (_typ); }
00105 
00106   octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
00107 
00108   octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
00109                      sortmode mode = ASCENDING) const;
00110 
00111   sortmode is_sorted (sortmode mode = UNSORTED) const;
00112 
00113   Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const;
00114 
00115   sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
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     { return make_value ().is_true (); }
00127 
00128   bool print_as_scalar (void) const
00129     { return make_value ().print_as_scalar (); }
00130 
00131   void print (std::ostream& os, bool pr_as_read_syntax = false) const
00132     { make_value ().print (os, pr_as_read_syntax); }
00133 
00134   void print_info (std::ostream& os, const std::string& prefix) const
00135     { make_value ().print_info (os, prefix); }
00136 
00137 #define FORWARD_VALUE_QUERY(TYPE,NAME) \
00138   TYPE \
00139   NAME (void) const { return make_value ().NAME (); }
00140 
00141   FORWARD_VALUE_QUERY (int8NDArray,  int8_array_value)
00142   FORWARD_VALUE_QUERY (int16NDArray, int16_array_value)
00143   FORWARD_VALUE_QUERY (int32NDArray, int32_array_value)
00144   FORWARD_VALUE_QUERY (int64NDArray, int64_array_value)
00145   FORWARD_VALUE_QUERY (uint8NDArray,  uint8_array_value)
00146   FORWARD_VALUE_QUERY (uint16NDArray, uint16_array_value)
00147   FORWARD_VALUE_QUERY (uint32NDArray, uint32_array_value)
00148   FORWARD_VALUE_QUERY (uint64NDArray, uint64_array_value)
00149 
00150 #define FORWARD_VALUE_QUERY1(TYPE,NAME) \
00151   TYPE \
00152   NAME (bool flag = false) const { return make_value ().NAME (flag); }
00153 
00154   FORWARD_VALUE_QUERY1 (double, double_value)
00155 
00156   FORWARD_VALUE_QUERY1 (float, float_value)
00157 
00158   FORWARD_VALUE_QUERY1 (double, scalar_value)
00159 
00160   FORWARD_VALUE_QUERY1 (Matrix, matrix_value)
00161 
00162   FORWARD_VALUE_QUERY1 (FloatMatrix, float_matrix_value)
00163 
00164   FORWARD_VALUE_QUERY1 (Complex, complex_value)
00165 
00166   FORWARD_VALUE_QUERY1 (FloatComplex, float_complex_value)
00167 
00168   FORWARD_VALUE_QUERY1 (ComplexMatrix, complex_matrix_value)
00169 
00170   FORWARD_VALUE_QUERY1 (FloatComplexMatrix, float_complex_matrix_value)
00171 
00172   FORWARD_VALUE_QUERY1 (ComplexNDArray, complex_array_value)
00173 
00174   FORWARD_VALUE_QUERY1 (FloatComplexNDArray, float_complex_array_value)
00175 
00176   FORWARD_VALUE_QUERY1 (boolNDArray, bool_array_value)
00177 
00178   FORWARD_VALUE_QUERY1 (charNDArray, char_array_value)
00179 
00180   FORWARD_VALUE_QUERY1 (NDArray, array_value)
00181 
00182   FORWARD_VALUE_QUERY1 (FloatNDArray, float_array_value)
00183 
00184   FORWARD_VALUE_QUERY1 (SparseMatrix, sparse_matrix_value)
00185 
00186   FORWARD_VALUE_QUERY1 (SparseComplexMatrix, sparse_complex_matrix_value)
00187 
00188   octave_value diag (octave_idx_type k = 0) const
00189     { return make_value ().diag (k); }
00190 
00191   octave_value convert_to_str_internal (bool pad, bool force, char type) const
00192     { return make_value ().convert_to_str_internal (pad, force, type); }
00193 
00194   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const
00195     { return make_value ().print_raw (os, pr_as_read_syntax); }
00196 
00197   bool save_ascii (std::ostream& os);
00198 
00199   bool load_ascii (std::istream& is);
00200 
00201   bool save_binary (std::ostream& os, bool& save_as_floats);
00202 
00203   bool load_binary (std::istream& is, bool swap,
00204                     oct_mach_info::float_format fmt);
00205 
00206   // HDF5 functions not defined.
00207 
00208   int write (octave_stream& os, int block_size,
00209              oct_data_conv::data_type output_type, int skip,
00210              oct_mach_info::float_format flt_fmt) const
00211     { return make_value ().write (os, block_size, output_type, skip, flt_fmt); }
00212 
00213   // Unsafe.  This function exists to support the MEX interface.
00214   // You should not use it anywhere else.
00215   void *mex_get_data (void) const
00216     { return make_value ().mex_get_data (); }
00217 
00218   mxArray *as_mxArray (void) const
00219     { return make_value ().as_mxArray (); }
00220 
00221   octave_value map (unary_mapper_t umap) const
00222     { return make_value ().map (umap); }
00223 
00224 private:
00225   const octave_value& make_value (void) const
00226     {
00227       if (value.is_undefined ())
00228         value = octave_value (index, false);
00229 
00230       return value;
00231     }
00232 
00233   octave_value& make_value (void)
00234     {
00235       if (value.is_undefined ())
00236         value = octave_value (index, false);
00237 
00238       return value;
00239     }
00240 
00241   idx_vector index;
00242   mutable octave_value value;
00243 
00244   static octave_base_value *numeric_conversion_function (const octave_base_value&);
00245 
00246   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00247 };
00248 
00249 #endif
00250 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines