comparison libinterp/octave-value/ov-cx-mat.cc @ 31138:b3ca7f891750

maint: use "m_" prefix for member variables in class octave_base_matrix. * ov-base-int.cc, ov-base-mat.cc, ov-base-mat.h, ov-base.h, ov-bool-mat.cc, ov-bool-mat.h, ov-cell.cc, ov-cell.h, ov-ch-mat.cc, ov-ch-mat.h, ov-cx-mat.cc, ov-cx-mat.h, ov-flt-cx-mat.cc, ov-flt-cx-mat.h, ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-intx.h, ov-re-mat.cc, ov-re-mat.h, ov-str-mat.cc, ov-str-mat.h: use "m_" prefix for member variables in class octave_base_matrix.
author Rik <rik@octave.org>
date Sun, 10 Jul 2022 18:26:24 -0700
parents 83f9f8bda883
children aac27ad79be6
comparison
equal deleted inserted replaced
31137:6308ce73bdca 31138:b3ca7f891750
89 octave_base_value * 89 octave_base_value *
90 octave_complex_matrix::try_narrowing_conversion (void) 90 octave_complex_matrix::try_narrowing_conversion (void)
91 { 91 {
92 octave_base_value *retval = nullptr; 92 octave_base_value *retval = nullptr;
93 93
94 if (matrix.numel () == 1) 94 if (m_matrix.numel () == 1)
95 { 95 {
96 Complex c = matrix (0); 96 Complex c = m_matrix (0);
97 97
98 if (c.imag () == 0.0) 98 if (c.imag () == 0.0)
99 retval = new octave_scalar (c.real ()); 99 retval = new octave_scalar (c.real ());
100 else 100 else
101 retval = new octave_complex (c); 101 retval = new octave_complex (c);
102 } 102 }
103 else if (matrix.all_elements_are_real ()) 103 else if (m_matrix.all_elements_are_real ())
104 retval = new octave_matrix (::real (matrix)); 104 retval = new octave_matrix (::real (m_matrix));
105 105
106 return retval; 106 return retval;
107 } 107 }
108 108
109 double 109 double
117 err_invalid_conversion ("complex matrix", "real scalar"); 117 err_invalid_conversion ("complex matrix", "real scalar");
118 118
119 warn_implicit_conversion ("Octave:array-to-scalar", 119 warn_implicit_conversion ("Octave:array-to-scalar",
120 "complex matrix", "real scalar"); 120 "complex matrix", "real scalar");
121 121
122 return std::real (matrix(0, 0)); 122 return std::real (m_matrix(0, 0));
123 } 123 }
124 124
125 float 125 float
126 octave_complex_matrix::float_value (bool force_conversion) const 126 octave_complex_matrix::float_value (bool force_conversion) const
127 { 127 {
133 err_invalid_conversion ("complex matrix", "real scalar"); 133 err_invalid_conversion ("complex matrix", "real scalar");
134 134
135 warn_implicit_conversion ("Octave:array-to-scalar", 135 warn_implicit_conversion ("Octave:array-to-scalar",
136 "complex matrix", "real scalar"); 136 "complex matrix", "real scalar");
137 137
138 return std::real (matrix(0, 0)); 138 return std::real (m_matrix(0, 0));
139 } 139 }
140 140
141 NDArray 141 NDArray
142 octave_complex_matrix::array_value (bool force_conversion) const 142 octave_complex_matrix::array_value (bool force_conversion) const
143 { 143 {
145 145
146 if (! force_conversion) 146 if (! force_conversion)
147 warn_implicit_conversion ("Octave:imag-to-real", 147 warn_implicit_conversion ("Octave:imag-to-real",
148 "complex matrix", "real matrix"); 148 "complex matrix", "real matrix");
149 149
150 retval = ::real (matrix); 150 retval = ::real (m_matrix);
151 151
152 return retval; 152 return retval;
153 } 153 }
154 154
155 Matrix 155 Matrix
159 159
160 if (! force_conversion) 160 if (! force_conversion)
161 warn_implicit_conversion ("Octave:imag-to-real", 161 warn_implicit_conversion ("Octave:imag-to-real",
162 "complex matrix", "real matrix"); 162 "complex matrix", "real matrix");
163 163
164 retval = ::real (ComplexMatrix (matrix)); 164 retval = ::real (ComplexMatrix (m_matrix));
165 165
166 return retval; 166 return retval;
167 } 167 }
168 168
169 FloatMatrix 169 FloatMatrix
173 173
174 if (! force_conversion) 174 if (! force_conversion)
175 warn_implicit_conversion ("Octave:imag-to-real", 175 warn_implicit_conversion ("Octave:imag-to-real",
176 "complex matrix", "real matrix"); 176 "complex matrix", "real matrix");
177 177
178 retval = ::real (ComplexMatrix (matrix)); 178 retval = ::real (ComplexMatrix (m_matrix));
179 179
180 return retval; 180 return retval;
181 } 181 }
182 182
183 Complex 183 Complex
187 err_invalid_conversion ("complex matrix", "complex scalar"); 187 err_invalid_conversion ("complex matrix", "complex scalar");
188 188
189 warn_implicit_conversion ("Octave:array-to-scalar", 189 warn_implicit_conversion ("Octave:array-to-scalar",
190 "complex matrix", "complex scalar"); 190 "complex matrix", "complex scalar");
191 191
192 return matrix(0, 0); 192 return m_matrix(0, 0);
193 } 193 }
194 194
195 FloatComplex 195 FloatComplex
196 octave_complex_matrix::float_complex_value (bool) const 196 octave_complex_matrix::float_complex_value (bool) const
197 { 197 {
203 err_invalid_conversion ("complex matrix", "complex scalar"); 203 err_invalid_conversion ("complex matrix", "complex scalar");
204 204
205 warn_implicit_conversion ("Octave:array-to-scalar", 205 warn_implicit_conversion ("Octave:array-to-scalar",
206 "complex matrix", "complex scalar"); 206 "complex matrix", "complex scalar");
207 207
208 retval = matrix(0, 0); 208 retval = m_matrix(0, 0);
209 209
210 return retval; 210 return retval;
211 } 211 }
212 212
213 ComplexMatrix 213 ComplexMatrix
214 octave_complex_matrix::complex_matrix_value (bool) const 214 octave_complex_matrix::complex_matrix_value (bool) const
215 { 215 {
216 return ComplexMatrix (matrix); 216 return ComplexMatrix (m_matrix);
217 } 217 }
218 218
219 FloatComplexMatrix 219 FloatComplexMatrix
220 octave_complex_matrix::float_complex_matrix_value (bool) const 220 octave_complex_matrix::float_complex_matrix_value (bool) const
221 { 221 {
222 return FloatComplexMatrix (ComplexMatrix (matrix)); 222 return FloatComplexMatrix (ComplexMatrix (m_matrix));
223 } 223 }
224 224
225 boolNDArray 225 boolNDArray
226 octave_complex_matrix::bool_array_value (bool warn) const 226 octave_complex_matrix::bool_array_value (bool warn) const
227 { 227 {
228 if (matrix.any_element_is_nan ()) 228 if (m_matrix.any_element_is_nan ())
229 octave::err_nan_to_logical_conversion (); 229 octave::err_nan_to_logical_conversion ();
230 if (warn && (! matrix.all_elements_are_real () 230 if (warn && (! m_matrix.all_elements_are_real ()
231 || real (matrix).any_element_not_one_or_zero ())) 231 || real (m_matrix).any_element_not_one_or_zero ()))
232 warn_logical_conversion (); 232 warn_logical_conversion ();
233 233
234 return mx_el_ne (matrix, Complex (0.0)); 234 return mx_el_ne (m_matrix, Complex (0.0));
235 } 235 }
236 236
237 charNDArray 237 charNDArray
238 octave_complex_matrix::char_array_value (bool frc_str_conv) const 238 octave_complex_matrix::char_array_value (bool frc_str_conv) const
239 { 239 {
246 { 246 {
247 retval = charNDArray (dims ()); 247 retval = charNDArray (dims ());
248 octave_idx_type nel = numel (); 248 octave_idx_type nel = numel ();
249 249
250 for (octave_idx_type i = 0; i < nel; i++) 250 for (octave_idx_type i = 0; i < nel; i++)
251 retval.elem (i) = static_cast<char> (std::real (matrix.elem (i))); 251 retval.elem (i) = static_cast<char> (std::real (m_matrix.elem (i)));
252 } 252 }
253 253
254 return retval; 254 return retval;
255 } 255 }
256 256
257 FloatComplexNDArray 257 FloatComplexNDArray
258 octave_complex_matrix::float_complex_array_value (bool) const 258 octave_complex_matrix::float_complex_array_value (bool) const
259 { 259 {
260 return FloatComplexNDArray (matrix); 260 return FloatComplexNDArray (m_matrix);
261 } 261 }
262 262
263 SparseMatrix 263 SparseMatrix
264 octave_complex_matrix::sparse_matrix_value (bool force_conversion) const 264 octave_complex_matrix::sparse_matrix_value (bool force_conversion) const
265 { 265 {
267 267
268 if (! force_conversion) 268 if (! force_conversion)
269 warn_implicit_conversion ("Octave:imag-to-real", 269 warn_implicit_conversion ("Octave:imag-to-real",
270 "complex matrix", "real matrix"); 270 "complex matrix", "real matrix");
271 271
272 retval = SparseMatrix (::real (ComplexMatrix (matrix))); 272 retval = SparseMatrix (::real (ComplexMatrix (m_matrix)));
273 273
274 return retval; 274 return retval;
275 } 275 }
276 276
277 SparseComplexMatrix 277 SparseComplexMatrix
278 octave_complex_matrix::sparse_complex_matrix_value (bool) const 278 octave_complex_matrix::sparse_complex_matrix_value (bool) const
279 { 279 {
280 return SparseComplexMatrix (ComplexMatrix (matrix)); 280 return SparseComplexMatrix (ComplexMatrix (m_matrix));
281 } 281 }
282 282
283 octave_value 283 octave_value
284 octave_complex_matrix::as_double (void) const 284 octave_complex_matrix::as_double (void) const
285 { 285 {
286 return matrix; 286 return m_matrix;
287 } 287 }
288 288
289 octave_value 289 octave_value
290 octave_complex_matrix::as_single (void) const 290 octave_complex_matrix::as_single (void) const
291 { 291 {
292 return FloatComplexNDArray (matrix); 292 return FloatComplexNDArray (m_matrix);
293 } 293 }
294 294
295 octave_value 295 octave_value
296 octave_complex_matrix::diag (octave_idx_type k) const 296 octave_complex_matrix::diag (octave_idx_type k) const
297 { 297 {
298 octave_value retval; 298 octave_value retval;
299 if (k == 0 && matrix.ndims () == 2 299 if (k == 0 && m_matrix.ndims () == 2
300 && (matrix.rows () == 1 || matrix.columns () == 1)) 300 && (m_matrix.rows () == 1 || m_matrix.columns () == 1))
301 retval = ComplexDiagMatrix (DiagArray2<Complex> (matrix)); 301 retval = ComplexDiagMatrix (DiagArray2<Complex> (m_matrix));
302 else 302 else
303 retval = octave_base_matrix<ComplexNDArray>::diag (k); 303 retval = octave_base_matrix<ComplexNDArray>::diag (k);
304 304
305 return retval; 305 return retval;
306 } 306 }
307 307
308 octave_value 308 octave_value
309 octave_complex_matrix::diag (octave_idx_type m, octave_idx_type n) const 309 octave_complex_matrix::diag (octave_idx_type m, octave_idx_type n) const
310 { 310 {
311 if (matrix.ndims () != 2 311 if (m_matrix.ndims () != 2
312 || (matrix.rows () != 1 && matrix.columns () != 1)) 312 || (m_matrix.rows () != 1 && m_matrix.columns () != 1))
313 error ("diag: expecting vector argument"); 313 error ("diag: expecting vector argument");
314 314
315 ComplexMatrix mat (matrix); 315 ComplexMatrix mat (m_matrix);
316 316
317 return mat.diag (m, n); 317 return mat.diag (m, n);
318 } 318 }
319 319
320 bool 320 bool
389 is >> tmp; 389 is >> tmp;
390 390
391 if (! is) 391 if (! is)
392 error ("load: failed to load matrix constant"); 392 error ("load: failed to load matrix constant");
393 393
394 matrix = tmp; 394 m_matrix = tmp;
395 } 395 }
396 else if (kw == "rows") 396 else if (kw == "rows")
397 { 397 {
398 octave_idx_type nr = val; 398 octave_idx_type nr = val;
399 octave_idx_type nc = 0; 399 octave_idx_type nc = 0;
406 ComplexMatrix tmp (nr, nc); 406 ComplexMatrix tmp (nr, nc);
407 is >> tmp; 407 is >> tmp;
408 if (! is) 408 if (! is)
409 error ("load: failed to load matrix constant"); 409 error ("load: failed to load matrix constant");
410 410
411 matrix = tmp; 411 m_matrix = tmp;
412 } 412 }
413 else if (nr == 0 || nc == 0) 413 else if (nr == 0 || nc == 0)
414 matrix = ComplexMatrix (nr, nc); 414 m_matrix = ComplexMatrix (nr, nc);
415 else 415 else
416 panic_impossible (); 416 panic_impossible ();
417 } 417 }
418 else 418 else
419 panic_impossible (); 419 panic_impossible ();
510 static_cast<save_type> (tmp), 2 * dv.numel (), swap, fmt); 510 static_cast<save_type> (tmp), 2 * dv.numel (), swap, fmt);
511 511
512 if (! is) 512 if (! is)
513 return false; 513 return false;
514 514
515 matrix = m; 515 m_matrix = m;
516 } 516 }
517 else 517 else
518 { 518 {
519 int32_t nr, nc; 519 int32_t nr, nc;
520 nr = mdims; 520 nr = mdims;
531 static_cast<save_type> (tmp), 2*len, swap, fmt); 531 static_cast<save_type> (tmp), 2*len, swap, fmt);
532 532
533 if (! is) 533 if (! is)
534 return false; 534 return false;
535 535
536 matrix = m; 536 m_matrix = m;
537 } 537 }
538 return true; 538 return true;
539 } 539 }
540 540
541 bool 541 bool
649 #if defined (HAVE_HDF5) 649 #if defined (HAVE_HDF5)
650 650
651 dim_vector dv; 651 dim_vector dv;
652 int empty = load_hdf5_empty (loc_id, name, dv); 652 int empty = load_hdf5_empty (loc_id, name, dv);
653 if (empty > 0) 653 if (empty > 0)
654 matrix.resize (dv); 654 m_matrix.resize (dv);
655 if (empty) 655 if (empty)
656 return (empty > 0); 656 return (empty > 0);
657 657
658 #if defined (HAVE_HDF5_18) 658 #if defined (HAVE_HDF5_18)
659 hid_t data_hid = H5Dopen (loc_id, name, octave_H5P_DEFAULT); 659 hid_t data_hid = H5Dopen (loc_id, name, octave_H5P_DEFAULT);
707 if (H5Dread (data_hid, complex_type, octave_H5S_ALL, octave_H5S_ALL, 707 if (H5Dread (data_hid, complex_type, octave_H5S_ALL, octave_H5S_ALL,
708 octave_H5P_DEFAULT, reim) 708 octave_H5P_DEFAULT, reim)
709 >= 0) 709 >= 0)
710 { 710 {
711 retval = true; 711 retval = true;
712 matrix = m; 712 m_matrix = m;
713 } 713 }
714 714
715 H5Tclose (complex_type); 715 H5Tclose (complex_type);
716 H5Sclose (space_id); 716 H5Sclose (space_id);
717 H5Dclose (data_hid); 717 H5Dclose (data_hid);
728 728
729 void 729 void
730 octave_complex_matrix::print_raw (std::ostream& os, 730 octave_complex_matrix::print_raw (std::ostream& os,
731 bool pr_as_read_syntax) const 731 bool pr_as_read_syntax) const
732 { 732 {
733 octave_print_internal (os, matrix, pr_as_read_syntax, 733 octave_print_internal (os, m_matrix, pr_as_read_syntax,
734 current_print_indent_level ()); 734 current_print_indent_level ());
735 } 735 }
736 736
737 mxArray * 737 mxArray *
738 octave_complex_matrix::as_mxArray (bool interleaved) const 738 octave_complex_matrix::as_mxArray (bool interleaved) const
740 mxArray *retval = new mxArray (interleaved, mxDOUBLE_CLASS, dims (), 740 mxArray *retval = new mxArray (interleaved, mxDOUBLE_CLASS, dims (),
741 mxCOMPLEX); 741 mxCOMPLEX);
742 742
743 mwSize nel = numel (); 743 mwSize nel = numel ();
744 744
745 const Complex *pdata = matrix.data (); 745 const Complex *pdata = m_matrix.data ();
746 746
747 if (interleaved) 747 if (interleaved)
748 { 748 {
749 mxComplexDouble *pd 749 mxComplexDouble *pd
750 = static_cast<mxComplexDouble *> (retval->get_data ()); 750 = static_cast<mxComplexDouble *> (retval->get_data ());
775 { 775 {
776 switch (umap) 776 switch (umap)
777 { 777 {
778 // Mappers handled specially. 778 // Mappers handled specially.
779 case umap_real: 779 case umap_real:
780 return ::real (matrix); 780 return ::real (m_matrix);
781 case umap_imag: 781 case umap_imag:
782 return ::imag (matrix); 782 return ::imag (m_matrix);
783 case umap_conj: 783 case umap_conj:
784 return ::conj (matrix); 784 return ::conj (m_matrix);
785 785
786 // Special cases for Matlab compatibility. 786 // Special cases for Matlab compatibility.
787 case umap_xtolower: 787 case umap_xtolower:
788 case umap_xtoupper: 788 case umap_xtoupper:
789 return matrix; 789 return m_matrix;
790 790
791 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \ 791 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \
792 case umap_ ## UMAP: \ 792 case umap_ ## UMAP: \
793 return octave_value (matrix.FCN ()) 793 return octave_value (m_matrix.FCN ())
794 794
795 ARRAY_METHOD_MAPPER (abs, abs); 795 ARRAY_METHOD_MAPPER (abs, abs);
796 ARRAY_METHOD_MAPPER (isnan, isnan); 796 ARRAY_METHOD_MAPPER (isnan, isnan);
797 ARRAY_METHOD_MAPPER (isinf, isinf); 797 ARRAY_METHOD_MAPPER (isinf, isinf);
798 ARRAY_METHOD_MAPPER (isfinite, isfinite); 798 ARRAY_METHOD_MAPPER (isfinite, isfinite);
799 799
800 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \ 800 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \
801 case umap_ ## UMAP: \ 801 case umap_ ## UMAP: \
802 return octave_value (matrix.map<TYPE> (FCN)) 802 return octave_value (m_matrix.map<TYPE> (FCN))
803 803
804 ARRAY_MAPPER (acos, Complex, octave::math::acos); 804 ARRAY_MAPPER (acos, Complex, octave::math::acos);
805 ARRAY_MAPPER (acosh, Complex, octave::math::acosh); 805 ARRAY_MAPPER (acosh, Complex, octave::math::acosh);
806 ARRAY_MAPPER (angle, double, std::arg); 806 ARRAY_MAPPER (angle, double, std::arg);
807 ARRAY_MAPPER (arg, double, std::arg); 807 ARRAY_MAPPER (arg, double, std::arg);