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_matrix_h)
00025 #define octave_matrix_h 1
00026
00027 #include <cstdlib>
00028
00029 #include <iosfwd>
00030 #include <string>
00031
00032 #include "mx-base.h"
00033 #include "oct-alloc.h"
00034 #include "str-vec.h"
00035
00036 #include "error.h"
00037 #include "oct-stream.h"
00038 #include "ov-base.h"
00039 #include "ov-base-mat.h"
00040 #include "ov-typeinfo.h"
00041
00042 #include "MatrixType.h"
00043
00044 class Octave_map;
00045 class octave_value_list;
00046
00047 class tree_walker;
00048
00049
00050
00051 class
00052 OCTINTERP_API
00053 octave_matrix : public octave_base_matrix<NDArray>
00054 {
00055 public:
00056
00057 octave_matrix (void)
00058 : octave_base_matrix<NDArray> () { }
00059
00060 octave_matrix (const Matrix& m)
00061 : octave_base_matrix<NDArray> (m) { }
00062
00063 octave_matrix (const Matrix& m, const MatrixType& t)
00064 : octave_base_matrix<NDArray> (m, t) { }
00065
00066 octave_matrix (const NDArray& nda)
00067 : octave_base_matrix<NDArray> (nda) { }
00068
00069 octave_matrix (const Array<double>& m)
00070 : octave_base_matrix<NDArray> (NDArray (m)) { }
00071
00072 octave_matrix (const DiagMatrix& d)
00073 : octave_base_matrix<NDArray> (Matrix (d)) { }
00074
00075 octave_matrix (const RowVector& v)
00076 : octave_base_matrix<NDArray> (Matrix (v)) { }
00077
00078 octave_matrix (const ColumnVector& v)
00079 : octave_base_matrix<NDArray> (Matrix (v)) { }
00080
00081 octave_matrix (const octave_matrix& m)
00082 : octave_base_matrix<NDArray> (m) { }
00083
00084 octave_matrix (const Array<octave_idx_type>& idx,
00085 bool zero_based = false, bool cache_index = false)
00086 : octave_base_matrix<NDArray> (NDArray (idx, zero_based))
00087 {
00088
00089 if (zero_based && cache_index)
00090 set_idx_cache (idx_vector (idx));
00091 }
00092
00093 octave_matrix (const NDArray& nda, const idx_vector& cache)
00094 : octave_base_matrix<NDArray> (nda)
00095 {
00096 set_idx_cache (idx_vector (cache));
00097 }
00098
00099 ~octave_matrix (void) { }
00100
00101 octave_base_value *clone (void) const { return new octave_matrix (*this); }
00102 octave_base_value *empty_clone (void) const { return new octave_matrix (); }
00103
00104 type_conv_info numeric_demotion_function (void) const;
00105
00106 octave_base_value *try_narrowing_conversion (void);
00107
00108 idx_vector index_vector (void) const
00109 { return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); }
00110
00111 builtin_type_t builtin_type (void) const { return btyp_double; }
00112
00113 bool is_real_matrix (void) const { return true; }
00114
00115 bool is_real_type (void) const { return true; }
00116
00117 bool is_double_type (void) const { return true; }
00118
00119 bool is_float_type (void) const { return true; }
00120
00121 int8NDArray
00122 int8_array_value (void) const { return int8NDArray (matrix); }
00123
00124 int16NDArray
00125 int16_array_value (void) const { return int16NDArray (matrix); }
00126
00127 int32NDArray
00128 int32_array_value (void) const { return int32NDArray (matrix); }
00129
00130 int64NDArray
00131 int64_array_value (void) const { return int64NDArray (matrix); }
00132
00133 uint8NDArray
00134 uint8_array_value (void) const { return uint8NDArray (matrix); }
00135
00136 uint16NDArray
00137 uint16_array_value (void) const { return uint16NDArray (matrix); }
00138
00139 uint32NDArray
00140 uint32_array_value (void) const { return uint32NDArray (matrix); }
00141
00142 uint64NDArray
00143 uint64_array_value (void) const { return uint64NDArray (matrix); }
00144
00145 double double_value (bool = false) const;
00146
00147 float float_value (bool = false) const;
00148
00149 double scalar_value (bool frc_str_conv = false) const
00150 { return double_value (frc_str_conv); }
00151
00152 Matrix matrix_value (bool = false) const;
00153
00154 FloatMatrix float_matrix_value (bool = false) const;
00155
00156 Complex complex_value (bool = false) const;
00157
00158 FloatComplex float_complex_value (bool = false) const;
00159
00160 ComplexMatrix complex_matrix_value (bool = false) const;
00161
00162 FloatComplexMatrix float_complex_matrix_value (bool = false) const;
00163
00164 ComplexNDArray complex_array_value (bool = false) const;
00165
00166 FloatComplexNDArray float_complex_array_value (bool = false) const;
00167
00168 boolNDArray bool_array_value (bool warn = false) const;
00169
00170 charNDArray char_array_value (bool = false) const;
00171
00172 NDArray array_value (bool = false) const { return matrix; }
00173
00174 FloatNDArray float_array_value (bool = false) const { return matrix; }
00175
00176 SparseMatrix sparse_matrix_value (bool = false) const;
00177
00178 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
00179
00180 octave_value diag (octave_idx_type k = 0) const;
00181
00182
00183 void increment (void) { matrix_ref () += 1.0; }
00184
00185 void decrement (void) { matrix_ref () -= 1.0; }
00186
00187 void changesign (void) { matrix_ref ().changesign (); }
00188
00189 octave_value convert_to_str_internal (bool pad, bool force, char type) const;
00190
00191 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
00192
00193 bool save_ascii (std::ostream& os);
00194
00195 bool load_ascii (std::istream& is);
00196
00197 bool save_binary (std::ostream& os, bool& save_as_floats);
00198
00199 bool load_binary (std::istream& is, bool swap,
00200 oct_mach_info::float_format fmt);
00201
00202 #if defined (HAVE_HDF5)
00203 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
00204
00205 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug);
00206 #endif
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 os.write (matrix, block_size, output_type, skip, flt_fmt); }
00212
00213
00214
00215 void *mex_get_data (void) const { return matrix.mex_get_data (); }
00216
00217 mxArray *as_mxArray (void) const;
00218
00219 octave_value erf (void) const;
00220 octave_value erfc (void) const;
00221 octave_value gamma (void) const;
00222 octave_value lgamma (void) const;
00223 octave_value abs (void) const;
00224 octave_value acos (void) const;
00225 octave_value acosh (void) const;
00226 octave_value angle (void) const;
00227 octave_value arg (void) const;
00228 octave_value asin (void) const;
00229 octave_value asinh (void) const;
00230 octave_value atan (void) const;
00231 octave_value atanh (void) const;
00232 octave_value ceil (void) const;
00233 octave_value conj (void) const;
00234 octave_value cos (void) const;
00235 octave_value cosh (void) const;
00236 octave_value exp (void) const;
00237 octave_value expm1 (void) const;
00238 octave_value fix (void) const;
00239 octave_value floor (void) const;
00240 octave_value imag (void) const;
00241 octave_value log (void) const;
00242 octave_value log2 (void) const;
00243 octave_value log10 (void) const;
00244 octave_value log1p (void) const;
00245 octave_value real (void) const;
00246 octave_value round (void) const;
00247 octave_value roundb (void) const;
00248 octave_value signum (void) const;
00249 octave_value sin (void) const;
00250 octave_value sinh (void) const;
00251 octave_value sqrt (void) const;
00252 octave_value tan (void) const;
00253 octave_value tanh (void) const;
00254 octave_value finite (void) const;
00255 octave_value isinf (void) const;
00256 octave_value isna (void) const;
00257 octave_value isnan (void) const;
00258
00259 private:
00260 DECLARE_OCTAVE_ALLOCATOR
00261
00262 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00263 };
00264
00265 #endif
00266
00267
00268
00269
00270
00271