comparison libinterp/octave-value/ov-base-diag.cc @ 30135:606652e9f446

maint: use "m_" prefix for member variables in class octave_base_diag. * ov-base-diag.cc, ov-base-diag.h, ov-cx-diag.cc, ov-flt-cx-diag.cc, ov-flt-re-diag.cc, ov-re-diag.cc: Use "m_" prefix for member variables in class octave_base_diag.
author Rik <rik@octave.org>
date Tue, 07 Sep 2021 16:07:34 -0700
parents 938794bc82b7
children 2dca5c25237d
comparison
equal deleted inserted replaced
30134:71d738ed015d 30135:606652e9f446
77 template <typename DMT, typename MT> 77 template <typename DMT, typename MT>
78 octave_value 78 octave_value
79 octave_base_diag<DMT,MT>::diag (octave_idx_type k) const 79 octave_base_diag<DMT,MT>::diag (octave_idx_type k) const
80 { 80 {
81 octave_value retval; 81 octave_value retval;
82 if (matrix.rows () == 1 || matrix.cols () == 1) 82 if (m_matrix.rows () == 1 || m_matrix.cols () == 1)
83 { 83 {
84 // Rather odd special case. This is a row or column vector 84 // Rather odd special case. This is a row or column vector
85 // represented as a diagonal matrix with a single nonzero entry, but 85 // represented as a diagonal matrix with a single nonzero entry, but
86 // Fdiag semantics are to product a diagonal matrix for vector 86 // Fdiag semantics are to product a diagonal matrix for vector
87 // inputs. 87 // inputs.
88 if (k == 0) 88 if (k == 0)
89 // Returns Diag2Array<T> with nnz <= 1. 89 // Returns Diag2Array<T> with nnz <= 1.
90 retval = matrix.build_diag_matrix (); 90 retval = m_matrix.build_diag_matrix ();
91 else 91 else
92 // Returns Array<T> matrix 92 // Returns Array<T> matrix
93 retval = matrix.array_value ().diag (k); 93 retval = m_matrix.array_value ().diag (k);
94 } 94 }
95 else 95 else
96 // Returns Array<T> vector 96 // Returns Array<T> vector
97 retval = matrix.extract_diag (k); 97 retval = m_matrix.extract_diag (k);
98 return retval; 98 return retval;
99 } 99 }
100 100
101 template <typename DMT, typename MT> 101 template <typename DMT, typename MT>
102 octave_value 102 octave_value
114 k = 1; 114 k = 1;
115 octave::idx_vector idx1 = idx(1).index_vector (); 115 octave::idx_vector idx1 = idx(1).index_vector ();
116 116
117 if (idx0.is_scalar () && idx1.is_scalar ()) 117 if (idx0.is_scalar () && idx1.is_scalar ())
118 { 118 {
119 retval = matrix.checkelem (idx0(0), idx1(0)); 119 retval = m_matrix.checkelem (idx0(0), idx1(0));
120 } 120 }
121 else 121 else
122 { 122 {
123 octave_idx_type m = idx0.length (matrix.rows ()); 123 octave_idx_type m = idx0.length (m_matrix.rows ());
124 octave_idx_type n = idx1.length (matrix.columns ()); 124 octave_idx_type n = idx1.length (m_matrix.columns ());
125 if (idx0.is_colon_equiv (m) && idx1.is_colon_equiv (n) 125 if (idx0.is_colon_equiv (m) && idx1.is_colon_equiv (n)
126 && m <= matrix.rows () && n <= matrix.rows ()) 126 && m <= m_matrix.rows () && n <= m_matrix.rows ())
127 { 127 {
128 DMT rm (matrix); 128 DMT rm (m_matrix);
129 rm.resize (m, n); 129 rm.resize (m, n);
130 retval = rm; 130 retval = rm;
131 } 131 }
132 else 132 else
133 retval = to_dense ().index_op (idx, resize_ok); 133 retval = to_dense ().index_op (idx, resize_ok);
180 int k = 0; 180 int k = 0;
181 try 181 try
182 { 182 {
183 octave::idx_vector ind = jdx(0).index_vector (); 183 octave::idx_vector ind = jdx(0).index_vector ();
184 k = 1; 184 k = 1;
185 dim_vector dv (matrix.rows (), matrix.cols ()); 185 dim_vector dv (m_matrix.rows (), m_matrix.cols ());
186 Array<octave::idx_vector> ivec = ind2sub (dv, ind); 186 Array<octave::idx_vector> ivec = ind2sub (dv, ind);
187 octave::idx_vector i0 = ivec(0); 187 octave::idx_vector i0 = ivec(0);
188 octave::idx_vector i1 = ivec(1); 188 octave::idx_vector i1 = ivec(1);
189 189
190 if (i0(0) == i1(0) 190 if (i0(0) == i1(0)
191 && chk_valid_scalar (rhs, val)) 191 && chk_valid_scalar (rhs, val))
192 { 192 {
193 matrix.dgelem (i0(0)) = val; 193 m_matrix.dgelem (i0(0)) = val;
194 retval = this; 194 retval = this;
195 this->m_count++; 195 this->m_count++;
196 // invalidate cache 196 // invalidate cache
197 dense_cache = octave_value (); 197 m_dense_cache = octave_value ();
198 } 198 }
199 } 199 }
200 catch (octave::index_exception& ie) 200 catch (octave::index_exception& ie)
201 { 201 {
202 // Rethrow to allow more info to be reported later. 202 // Rethrow to allow more info to be reported later.
213 { 213 {
214 octave::idx_vector i0 = jdx(0).index_vector (); 214 octave::idx_vector i0 = jdx(0).index_vector ();
215 k = 1; 215 k = 1;
216 octave::idx_vector i1 = jdx(1).index_vector (); 216 octave::idx_vector i1 = jdx(1).index_vector ();
217 if (i0(0) == i1(0) 217 if (i0(0) == i1(0)
218 && i0(0) < matrix.rows () && i1(0) < matrix.cols () 218 && i0(0) < m_matrix.rows () && i1(0) < m_matrix.cols ()
219 && chk_valid_scalar (rhs, val)) 219 && chk_valid_scalar (rhs, val))
220 { 220 {
221 matrix.dgelem (i0(0)) = val; 221 m_matrix.dgelem (i0(0)) = val;
222 retval = this; 222 retval = this;
223 this->m_count++; 223 this->m_count++;
224 // invalidate cache 224 // invalidate cache
225 dense_cache = octave_value (); 225 m_dense_cache = octave_value ();
226 } 226 }
227 } 227 }
228 catch (octave::index_exception& ie) 228 catch (octave::index_exception& ie)
229 { 229 {
230 // Rethrow to allow more info to be reported later. 230 // Rethrow to allow more info to be reported later.
265 octave_base_diag<DMT, MT>::resize (const dim_vector& dv, bool fill) const 265 octave_base_diag<DMT, MT>::resize (const dim_vector& dv, bool fill) const
266 { 266 {
267 octave_value retval; 267 octave_value retval;
268 if (dv.ndims () == 2) 268 if (dv.ndims () == 2)
269 { 269 {
270 DMT rm (matrix); 270 DMT rm (m_matrix);
271 rm.resize (dv(0), dv(1)); 271 rm.resize (dv(0), dv(1));
272 retval = rm; 272 retval = rm;
273 } 273 }
274 else 274 else
275 retval = to_dense ().resize (dv, fill); 275 retval = to_dense ().resize (dv, fill);
283 { 283 {
284 if (dims ().numel () > 1) 284 if (dims ().numel () > 1)
285 { 285 {
286 warn_array_as_logical (dims ()); 286 warn_array_as_logical (dims ());
287 // Throw error if any NaN or NA by calling is_true(). 287 // Throw error if any NaN or NA by calling is_true().
288 octave_value (matrix.extract_diag ()).is_true (); 288 octave_value (m_matrix.extract_diag ()).is_true ();
289 return false; // > 1x1 diagonal always has zeros 289 return false; // > 1x1 diagonal always has zeros
290 } 290 }
291 else 291 else
292 return to_dense ().is_true (); // 0x0 or 1x1, handle NaN etc. 292 return to_dense ().is_true (); // 0x0 or 1x1, handle NaN etc.
293 } 293 }
307 { 307 {
308 typedef typename DMT::element_type el_type; 308 typedef typename DMT::element_type el_type;
309 309
310 if (helper_iscomplex (el_type ()) && ! force_conversion) 310 if (helper_iscomplex (el_type ()) && ! force_conversion)
311 warn_implicit_conversion ("Octave:imag-to-real", 311 warn_implicit_conversion ("Octave:imag-to-real",
312 "complex matrix", "real scalar"); 312 "complex m_matrix", "real scalar");
313 313
314 if (isempty ()) 314 if (isempty ())
315 err_invalid_conversion (type_name (), "real scalar"); 315 err_invalid_conversion (type_name (), "real scalar");
316 316
317 warn_implicit_conversion ("Octave:array-to-scalar", 317 warn_implicit_conversion ("Octave:array-to-scalar",
318 type_name (), "real scalar"); 318 type_name (), "real scalar");
319 319
320 return helper_getreal (el_type (matrix (0, 0))); 320 return helper_getreal (el_type (m_matrix (0, 0)));
321 } 321 }
322 322
323 template <typename DMT, typename MT> 323 template <typename DMT, typename MT>
324 float 324 float
325 octave_base_diag<DMT, MT>::float_value (bool force_conversion) const 325 octave_base_diag<DMT, MT>::float_value (bool force_conversion) const
326 { 326 {
327 typedef typename DMT::element_type el_type; 327 typedef typename DMT::element_type el_type;
328 328
329 if (helper_iscomplex (el_type ()) && ! force_conversion) 329 if (helper_iscomplex (el_type ()) && ! force_conversion)
330 warn_implicit_conversion ("Octave:imag-to-real", 330 warn_implicit_conversion ("Octave:imag-to-real",
331 "complex matrix", "real scalar"); 331 "complex m_matrix", "real scalar");
332 332
333 if (! (numel () > 0)) 333 if (! (numel () > 0))
334 err_invalid_conversion (type_name (), "real scalar"); 334 err_invalid_conversion (type_name (), "real scalar");
335 335
336 warn_implicit_conversion ("Octave:array-to-scalar", 336 warn_implicit_conversion ("Octave:array-to-scalar",
337 type_name (), "real scalar"); 337 type_name (), "real scalar");
338 338
339 return helper_getreal (el_type (matrix (0, 0))); 339 return helper_getreal (el_type (m_matrix (0, 0)));
340 } 340 }
341 341
342 template <typename DMT, typename MT> 342 template <typename DMT, typename MT>
343 Complex 343 Complex
344 octave_base_diag<DMT, MT>::complex_value (bool) const 344 octave_base_diag<DMT, MT>::complex_value (bool) const
347 err_invalid_conversion (type_name (), "complex scalar"); 347 err_invalid_conversion (type_name (), "complex scalar");
348 348
349 warn_implicit_conversion ("Octave:array-to-scalar", 349 warn_implicit_conversion ("Octave:array-to-scalar",
350 type_name (), "complex scalar"); 350 type_name (), "complex scalar");
351 351
352 return matrix(0, 0); 352 return m_matrix(0, 0);
353 } 353 }
354 354
355 template <typename DMT, typename MT> 355 template <typename DMT, typename MT>
356 FloatComplex 356 FloatComplex
357 octave_base_diag<DMT, MT>::float_complex_value (bool) const 357 octave_base_diag<DMT, MT>::float_complex_value (bool) const
364 err_invalid_conversion (type_name (), "complex scalar"); 364 err_invalid_conversion (type_name (), "complex scalar");
365 365
366 warn_implicit_conversion ("Octave:array-to-scalar", 366 warn_implicit_conversion ("Octave:array-to-scalar",
367 type_name (), "complex scalar"); 367 type_name (), "complex scalar");
368 368
369 retval = matrix (0, 0); 369 retval = m_matrix (0, 0);
370 370
371 return retval; 371 return retval;
372 } 372 }
373 373
374 template <typename DMT, typename MT> 374 template <typename DMT, typename MT>
483 octave_base_diag<DMT, MT>::edit_display (const float_display_format& fmt, 483 octave_base_diag<DMT, MT>::edit_display (const float_display_format& fmt,
484 octave_idx_type i, 484 octave_idx_type i,
485 octave_idx_type j) const 485 octave_idx_type j) const
486 { 486 {
487 std::ostringstream buf; 487 std::ostringstream buf;
488 octave_print_internal (buf, fmt, matrix(i,j)); 488 octave_print_internal (buf, fmt, m_matrix(i,j));
489 return buf.str (); 489 return buf.str ();
490 } 490 }
491 491
492 template <typename DMT, typename MT> 492 template <typename DMT, typename MT>
493 bool 493 bool
494 octave_base_diag<DMT, MT>::save_ascii (std::ostream& os) 494 octave_base_diag<DMT, MT>::save_ascii (std::ostream& os)
495 { 495 {
496 os << "# rows: " << matrix.rows () << "\n" 496 os << "# rows: " << m_matrix.rows () << "\n"
497 << "# columns: " << matrix.columns () << "\n"; 497 << "# columns: " << m_matrix.columns () << "\n";
498 498
499 os << matrix.extract_diag (); 499 os << m_matrix.extract_diag ();
500 500
501 return true; 501 return true;
502 } 502 }
503 503
504 template <typename DMT, typename MT> 504 template <typename DMT, typename MT>
515 octave_idx_type l = (r < c ? r : c); 515 octave_idx_type l = (r < c ? r : c);
516 MT tmp (l, 1); 516 MT tmp (l, 1);
517 is >> tmp; 517 is >> tmp;
518 518
519 if (! is) 519 if (! is)
520 error ("load: failed to load diagonal matrix constant"); 520 error ("load: failed to load diagonal m_matrix constant");
521 521
522 // This is a little tricky, as we have the Matrix type, but 522 // This is a little tricky, as we have the Matrix type, but
523 // not ColumnVector type. We need to help the compiler get 523 // not ColumnVector type. We need to help the compiler get
524 // through the inheritance tree. 524 // through the inheritance tree.
525 typedef typename DMT::element_type el_type; 525 typedef typename DMT::element_type el_type;
526 matrix = DMT (MDiagArray2<el_type> (MArray<el_type> (tmp))); 526 m_matrix = DMT (MDiagArray2<el_type> (MArray<el_type> (tmp)));
527 matrix.resize (r, c); 527 m_matrix.resize (r, c);
528 528
529 // Invalidate cache. Probably not necessary, but safe. 529 // Invalidate cache. Probably not necessary, but safe.
530 dense_cache = octave_value (); 530 m_dense_cache = octave_value ();
531 531
532 return true; 532 return true;
533 } 533 }
534 534
535 template <typename DMT, typename MT> 535 template <typename DMT, typename MT>
536 void 536 void
537 octave_base_diag<DMT, MT>::print_raw (std::ostream& os, 537 octave_base_diag<DMT, MT>::print_raw (std::ostream& os,
538 bool pr_as_read_syntax) const 538 bool pr_as_read_syntax) const
539 { 539 {
540 return octave_print_internal (os, matrix, pr_as_read_syntax, 540 return octave_print_internal (os, m_matrix, pr_as_read_syntax,
541 current_print_indent_level ()); 541 current_print_indent_level ());
542 } 542 }
543 543
544 template <typename DMT, typename MT> 544 template <typename DMT, typename MT>
545 mxArray * 545 mxArray *
577 template <typename DMT, typename MT> 577 template <typename DMT, typename MT>
578 void 578 void
579 octave_base_diag<DMT, MT>::print_info (std::ostream& os, 579 octave_base_diag<DMT, MT>::print_info (std::ostream& os,
580 const std::string& prefix) const 580 const std::string& prefix) const
581 { 581 {
582 matrix.print_info (os, prefix); 582 m_matrix.print_info (os, prefix);
583 } 583 }
584 584
585 // FIXME: this function is duplicated in octave_base_matrix<T>. Could 585 // FIXME: this function is duplicated in octave_base_matrix<T>. Could
586 // it somehow be shared instead? 586 // it somehow be shared instead?
587 587
588 template <typename DMT, typename MT> 588 template <typename DMT, typename MT>
589 void 589 void
590 octave_base_diag<DMT, MT>::short_disp (std::ostream& os) const 590 octave_base_diag<DMT, MT>::short_disp (std::ostream& os) const
591 { 591 {
592 if (matrix.isempty ()) 592 if (m_matrix.isempty ())
593 os << "[]"; 593 os << "[]";
594 else if (matrix.ndims () == 2) 594 else if (m_matrix.ndims () == 2)
595 { 595 {
596 // FIXME: should this be configurable? 596 // FIXME: should this be configurable?
597 octave_idx_type max_elts = 10; 597 octave_idx_type max_elts = 10;
598 octave_idx_type elts = 0; 598 octave_idx_type elts = 0;
599 599
600 octave_idx_type nel = matrix.numel (); 600 octave_idx_type nel = m_matrix.numel ();
601 601
602 octave_idx_type nr = matrix.rows (); 602 octave_idx_type nr = m_matrix.rows ();
603 octave_idx_type nc = matrix.columns (); 603 octave_idx_type nc = m_matrix.columns ();
604 604
605 os << '['; 605 os << '[';
606 606
607 for (octave_idx_type i = 0; i < nr; i++) 607 for (octave_idx_type i = 0; i < nr; i++)
608 { 608 {
609 for (octave_idx_type j = 0; j < nc; j++) 609 for (octave_idx_type j = 0; j < nc; j++)
610 { 610 {
611 std::ostringstream buf; 611 std::ostringstream buf;
612 octave_print_internal (buf, matrix(i,j)); 612 octave_print_internal (buf, m_matrix(i,j));
613 std::string tmp = buf.str (); 613 std::string tmp = buf.str ();
614 std::size_t pos = tmp.find_first_not_of (' '); 614 std::size_t pos = tmp.find_first_not_of (' ');
615 if (pos != std::string::npos) 615 if (pos != std::string::npos)
616 os << tmp.substr (pos); 616 os << tmp.substr (pos);
617 else if (! tmp.empty ()) 617 else if (! tmp.empty ())
639 639
640 template <typename DMT, typename MT> 640 template <typename DMT, typename MT>
641 octave_value 641 octave_value
642 octave_base_diag<DMT, MT>::fast_elem_extract (octave_idx_type n) const 642 octave_base_diag<DMT, MT>::fast_elem_extract (octave_idx_type n) const
643 { 643 {
644 if (n < matrix.numel ()) 644 if (n < m_matrix.numel ())
645 { 645 {
646 octave_idx_type nr = matrix.rows (); 646 octave_idx_type nr = m_matrix.rows ();
647 647
648 octave_idx_type r = n % nr; 648 octave_idx_type r = n % nr;
649 octave_idx_type c = n / nr; 649 octave_idx_type c = n / nr;
650 650
651 return octave_value (matrix.elem (r, c)); 651 return octave_value (m_matrix.elem (r, c));
652 } 652 }
653 else 653 else
654 return octave_value (); 654 return octave_value ();
655 } 655 }
656 656
657 template <typename DMT, typename MT> 657 template <typename DMT, typename MT>
658 octave_value 658 octave_value
659 octave_base_diag<DMT, MT>::to_dense (void) const 659 octave_base_diag<DMT, MT>::to_dense (void) const
660 { 660 {
661 if (! dense_cache.is_defined ()) 661 if (! m_dense_cache.is_defined ())
662 dense_cache = MT (matrix); 662 m_dense_cache = MT (m_matrix);
663 663
664 return dense_cache; 664 return m_dense_cache;
665 } 665 }