GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-re-mat.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <clocale>
31 #include <istream>
32 #include <limits>
33 #include <ostream>
34 #include <vector>
35 
36 #include "dNDArray.h"
37 #include "fNDArray.h"
38 #include "int8NDArray.h"
39 #include "int16NDArray.h"
40 #include "int32NDArray.h"
41 #include "int64NDArray.h"
42 #include "uint8NDArray.h"
43 #include "uint16NDArray.h"
44 #include "uint32NDArray.h"
45 #include "uint64NDArray.h"
46 
47 #include "data-conv.h"
48 #include "lo-ieee.h"
49 #include "lo-utils.h"
50 #include "lo-specfun.h"
51 #include "lo-mappers.h"
52 #include "mach-info.h"
53 #include "mx-base.h"
54 #include "quit.h"
55 #include "oct-locbuf.h"
56 
57 #include "defun.h"
58 #include "errwarn.h"
59 #include "mxarray.h"
60 #include "ovl.h"
61 #include "oct-lvalue.h"
62 #include "oct-hdf5.h"
63 #include "oct-stream.h"
64 #include "ops.h"
65 #include "ov-base.h"
66 #include "ov-base-mat.h"
67 #include "ov-base-mat.cc"
68 #include "ov-scalar.h"
69 #include "ov-re-mat.h"
70 #include "ov-flt-re-mat.h"
71 #include "ov-complex.h"
72 #include "ov-cx-mat.h"
73 #include "ov-re-sparse.h"
74 #include "ov-re-diag.h"
75 #include "ov-cx-diag.h"
76 #include "ov-lazy-idx.h"
77 #include "ov-perm.h"
78 #include "pr-flt-fmt.h"
79 #include "pr-output.h"
80 #include "variables.h"
81 
82 #include "byte-swap.h"
83 #include "ls-oct-text.h"
84 #include "ls-utils.h"
85 #include "ls-hdf5.h"
86 
87 
88 template class octave_base_matrix<NDArray>;
89 
91 
92 static octave_base_value *
93 default_numeric_demotion_function (const octave_base_value& a)
94 {
95  const octave_matrix& v = dynamic_cast<const octave_matrix&> (a);
96 
97  return new octave_float_matrix (v.float_array_value ());
98 }
99 
102 {
104  (default_numeric_demotion_function,
106 }
107 
110 {
111  octave_base_value *retval = nullptr;
112 
113  if (m_matrix.numel () == 1)
114  retval = new octave_scalar (m_matrix (0));
115 
116  return retval;
117 }
118 
119 double
121 {
122  if (isempty ())
123  err_invalid_conversion ("real matrix", "real scalar");
124 
125  warn_implicit_conversion ("Octave:array-to-scalar",
126  "real matrix", "real scalar");
127 
128  return m_matrix(0, 0);
129 }
130 
131 float
133 {
134  if (isempty ())
135  err_invalid_conversion ("real matrix", "real scalar");
136 
137  warn_implicit_conversion ("Octave:array-to-scalar",
138  "real matrix", "real scalar");
139 
140  return m_matrix(0, 0);
141 }
142 
143 // FIXME
144 
145 Matrix
147 {
148  return Matrix (m_matrix);
149 }
150 
153 {
154  return FloatMatrix (Matrix (m_matrix));
155 }
156 
157 Complex
159 {
160  if (rows () == 0 || columns () == 0)
161  err_invalid_conversion ("real matrix", "complex scalar");
162 
163  warn_implicit_conversion ("Octave:array-to-scalar",
164  "real matrix", "complex scalar");
165 
166  return Complex (m_matrix(0, 0), 0);
167 }
168 
171 {
172  float tmp = lo_ieee_float_nan_value ();
173 
174  FloatComplex retval (tmp, tmp);
175 
176  if (rows () == 0 || columns () == 0)
177  err_invalid_conversion ("real matrix", "complex scalar");
178 
179  warn_implicit_conversion ("Octave:array-to-scalar",
180  "real matrix", "complex scalar");
181 
182  retval = m_matrix(0, 0);
183 
184  return retval;
185 }
186 
187 // FIXME
188 
191 {
192  return ComplexMatrix (Matrix (m_matrix));
193 }
194 
197 {
199 }
200 
203 {
204  return ComplexNDArray (m_matrix);
205 }
206 
209 {
210  return FloatComplexNDArray (m_matrix);
211 }
212 
215 {
218  if (warn && m_matrix.any_element_not_one_or_zero ())
220 
221  return boolNDArray (m_matrix);
222 }
223 
226 {
227  charNDArray retval (dims ());
228 
229  octave_idx_type nel = numel ();
230 
231  for (octave_idx_type i = 0; i < nel; i++)
232  retval.elem (i) = static_cast<char> (m_matrix.elem (i));
233 
234  return retval;
235 }
236 
239 {
240  return SparseMatrix (Matrix (m_matrix));
241 }
242 
245 {
246  // FIXME: Need a SparseComplexMatrix (Matrix) constructor to make
247  // this function more efficient. Then this should become
248  // return SparseComplexMatrix (matrix.matrix_value ());
250 }
251 
254 {
255  return NDArray (m_matrix);
256 }
257 
260 {
261  return FloatNDArray (m_matrix);
262 }
263 
266 {
267  return int8NDArray (m_matrix);
268 }
269 
272 {
273  return int16NDArray (m_matrix);
274 }
275 
278 {
279  return int32NDArray (m_matrix);
280 }
281 
284 {
285  return int64NDArray (m_matrix);
286 }
287 
290 {
291  return uint8NDArray (m_matrix);
292 }
293 
296 {
297  return uint16NDArray (m_matrix);
298 }
299 
302 {
303  return uint32NDArray (m_matrix);
304 }
305 
308 {
309  return uint64NDArray (m_matrix);
310 }
311 
314 {
315  octave_value retval;
316  if (k == 0 && m_matrix.ndims () == 2
317  && (m_matrix.rows () == 1 || m_matrix.columns () == 1))
319  else
321 
322  return retval;
323 }
324 
327 {
328  if (m_matrix.ndims () != 2
329  || (m_matrix.rows () != 1 && m_matrix.columns () != 1))
330  error ("diag: expecting vector argument");
331 
332  Matrix mat (m_matrix);
333 
334  return mat.diag (m, n);
335 }
336 
337 // We override these two functions to allow reshaping both
338 // the matrix and the index cache.
340 octave_matrix::reshape (const dim_vector& new_dims) const
341 {
342  if (m_idx_cache)
343  {
344  return new octave_matrix (m_matrix.reshape (new_dims),
345  octave::idx_vector (m_idx_cache->as_array ().reshape (new_dims),
346  m_idx_cache->extent (0)));
347  }
348  else
349  return octave_base_matrix<NDArray>::reshape (new_dims);
350 }
351 
354 {
355  if (m_idx_cache)
356  {
357  return new octave_matrix (m_matrix.squeeze (),
358  octave::idx_vector (m_idx_cache->as_array ().squeeze (),
359  m_idx_cache->extent (0)));
360  }
361  else
363 }
364 
367 {
368  if (m_idx_cache)
369  {
370  // This is a valid index matrix, so sort via integers because it's
371  // generally more efficient.
372  return octave_lazy_index (*m_idx_cache).sort (dim, mode);
373  }
374  else
375  return octave_base_matrix<NDArray>::sort (dim, mode);
376 }
377 
380  sortmode mode) const
381 {
382  if (m_idx_cache)
383  {
384  // This is a valid index matrix, so sort via integers because it's
385  // generally more efficient.
386  return octave_lazy_index (*m_idx_cache).sort (sidx, dim, mode);
387  }
388  else
389  return octave_base_matrix<NDArray>::sort (sidx, dim, mode);
390 }
391 
392 sortmode
394 {
395  if (m_idx_cache)
396  {
397  // This is a valid index matrix, so check via integers because it's
398  // generally more efficient.
399  return m_idx_cache->as_array ().issorted (mode);
400  }
401  else
403 }
406 {
407  if (m_idx_cache)
408  {
409  // This is a valid index matrix, so sort via integers because it's
410  // generally more efficient.
411  return octave_lazy_index (*m_idx_cache).sort_rows_idx (mode);
412  }
413  else
415 }
416 
417 sortmode
419 {
420  if (m_idx_cache)
421  {
422  // This is a valid index matrix, so check via integers because it's
423  // generally more efficient.
424  return m_idx_cache->as_array ().is_sorted_rows (mode);
425  }
426  else
428 }
429 
431 octave_matrix::convert_to_str_internal (bool, bool, char type) const
432 {
433  octave_value retval;
434  dim_vector dv = dims ();
435  octave_idx_type nel = dv.numel ();
436 
437  charNDArray chm (dv);
438 
439  bool warned = false;
440 
441  for (octave_idx_type i = 0; i < nel; i++)
442  {
443  octave_quit ();
444 
445  double d = m_matrix(i);
446 
447  if (octave::math::isnan (d))
449 
450  int ival = octave::math::nint (d);
451 
452  if (ival < 0 || ival > std::numeric_limits<unsigned char>::max ())
453  {
454  // FIXME: is there something better we could do?
455 
456  ival = 0;
457 
458  if (! warned)
459  {
460  ::warning ("range error for conversion to character value");
461  warned = true;
462  }
463  }
464 
465  chm(i) = static_cast<char> (ival);
466  }
467 
468  retval = octave_value (chm, type);
469 
470  return retval;
471 }
472 
473 bool
474 octave_matrix::save_ascii (std::ostream& os)
475 {
476  dim_vector dv = dims ();
477 
478  if (dv.ndims () > 2)
479  {
480  NDArray tmp = array_value ();
481 
482  os << "# ndims: " << dv.ndims () << "\n";
483 
484  for (int i=0; i < dv.ndims (); i++)
485  os << ' ' << dv(i);
486 
487  os << "\n" << tmp;
488  }
489  else
490  {
491  // Keep this case, rather than use generic code above for backward
492  // compatibility. Makes load_ascii much more complex!!
493  os << "# rows: " << rows () << "\n"
494  << "# columns: " << columns () << "\n";
495 
496  os << matrix_value ();
497  }
498 
499  return true;
500 }
501 
502 bool
503 octave_matrix::load_ascii (std::istream& is)
504 {
505  string_vector keywords(2);
506 
507  keywords[0] = "ndims";
508  keywords[1] = "rows";
509 
510  std::string kw;
511  octave_idx_type val = 0;
512 
513  if (! extract_keyword (is, keywords, kw, val, true))
514  error ("load: failed to extract number of rows and columns");
515 
516  // Set "C" locale for the duration of this function to avoid the performance
517  // panelty of frequently switching the locale when reading floating point
518  // values from the stream.
519  char *prev_locale = std::setlocale (LC_ALL, nullptr);
520  std::string old_locale (prev_locale ? prev_locale : "");
521  std::setlocale (LC_ALL, "C");
522  octave::unwind_action act
523  ([&old_locale] () { std::setlocale (LC_ALL, old_locale.c_str ()); });
524 
525  if (kw == "ndims")
526  {
527  int mdims = static_cast<int> (val);
528 
529  if (mdims < 0)
530  error ("load: failed to extract number of dimensions");
531 
532  dim_vector dv;
533  dv.resize (mdims);
534 
535  for (int i = 0; i < mdims; i++)
536  is >> dv(i);
537 
538  if (! is)
539  error ("load: failed to read dimensions");
540 
541  NDArray tmp(dv);
542 
543  is >> tmp;
544 
545  if (! is)
546  error ("load: failed to load matrix constant");
547 
548  m_matrix = tmp;
549  }
550  else if (kw == "rows")
551  {
552  octave_idx_type nr = val;
553  octave_idx_type nc = 0;
554 
555  if (nr < 0 || ! extract_keyword (is, "columns", nc) || nc < 0)
556  error ("load: failed to extract number of rows and columns");
557 
558  if (nr > 0 && nc > 0)
559  {
560  Matrix tmp (nr, nc);
561  is >> tmp;
562  if (! is)
563  error ("load: failed to load matrix constant");
564 
565  m_matrix = tmp;
566  }
567  else if (nr == 0 || nc == 0)
568  m_matrix = Matrix (nr, nc);
569  else
570  panic_impossible ();
571  }
572  else
573  panic_impossible ();
574 
575  return true;
576 }
577 
578 bool
579 octave_matrix::save_binary (std::ostream& os, bool save_as_floats)
580 {
581 
582  dim_vector dv = dims ();
583  if (dv.ndims () < 1)
584  return false;
585 
586  // Use negative value for ndims to differentiate with old format!!
587  int32_t tmp = - dv.ndims ();
588  os.write (reinterpret_cast<char *> (&tmp), 4);
589  for (int i = 0; i < dv.ndims (); i++)
590  {
591  tmp = dv(i);
592  os.write (reinterpret_cast<char *> (&tmp), 4);
593  }
594 
595  NDArray m = array_value ();
596  save_type st = LS_DOUBLE;
597  if (save_as_floats)
598  {
599  if (m.too_large_for_float ())
600  {
601  warning ("save: some values too large to save as floats --");
602  warning ("save: saving as doubles instead");
603  }
604  else
605  st = LS_FLOAT;
606  }
607  else if (dv.numel () > 8192) // FIXME: make this configurable.
608  {
609  double max_val, min_val;
610  if (m.all_integers (max_val, min_val))
611  st = octave::get_save_type (max_val, min_val);
612  }
613 
614  const double *mtmp = m.data ();
615  write_doubles (os, mtmp, st, dv.numel ());
616 
617  return true;
618 }
619 
620 bool
621 octave_matrix::load_binary (std::istream& is, bool swap,
623 {
624  char tmp;
625  int32_t mdims;
626  if (! is.read (reinterpret_cast<char *> (&mdims), 4))
627  return false;
628  if (swap)
629  swap_bytes<4> (&mdims);
630  if (mdims < 0)
631  {
632  mdims = - mdims;
633  int32_t di;
634  dim_vector dv;
635  dv.resize (mdims);
636 
637  for (int i = 0; i < mdims; i++)
638  {
639  if (! is.read (reinterpret_cast<char *> (&di), 4))
640  return false;
641  if (swap)
642  swap_bytes<4> (&di);
643  dv(i) = di;
644  }
645 
646  // Convert an array with a single dimension to be a row vector.
647  // Octave should never write files like this, other software
648  // might.
649 
650  if (mdims == 1)
651  {
652  mdims = 2;
653  dv.resize (mdims);
654  dv(1) = dv(0);
655  dv(0) = 1;
656  }
657 
658  if (! is.read (reinterpret_cast<char *> (&tmp), 1))
659  return false;
660 
661  NDArray m(dv);
662  double *re = m.fortran_vec ();
663  read_doubles (is, re, static_cast<save_type> (tmp), dv.numel (),
664  swap, fmt);
665 
666  if (! is)
667  return false;
668 
669  m_matrix = m;
670  }
671  else
672  {
673  int32_t nr, nc;
674  nr = mdims;
675  if (! is.read (reinterpret_cast<char *> (&nc), 4))
676  return false;
677  if (swap)
678  swap_bytes<4> (&nc);
679  if (! is.read (reinterpret_cast<char *> (&tmp), 1))
680  return false;
681  Matrix m (nr, nc);
682  double *re = m.fortran_vec ();
683  octave_idx_type len = static_cast<octave_idx_type> (nr) * nc;
684  read_doubles (is, re, static_cast<save_type> (tmp), len, swap, fmt);
685 
686  if (! is)
687  return false;
688 
689  m_matrix = m;
690  }
691  return true;
692 }
693 
694 bool
695 octave_matrix::save_hdf5 (octave_hdf5_id loc_id, const char *name,
696  bool save_as_floats)
697 {
698  bool retval = false;
699 
700 #if defined (HAVE_HDF5)
701 
702  dim_vector dv = dims ();
703  int empty = save_hdf5_empty (loc_id, name, dv);
704  if (empty)
705  return (empty > 0);
706 
707  int rank = dv.ndims ();
708  hid_t space_hid, data_hid;
709  space_hid = data_hid = -1;
710  NDArray m = array_value ();
711 
712  OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
713 
714  // Octave uses column-major, while HDF5 uses row-major ordering
715  for (int i = 0; i < rank; i++)
716  hdims[i] = dv(rank-i-1);
717 
718  space_hid = H5Screate_simple (rank, hdims, nullptr);
719 
720  if (space_hid < 0) return false;
721 
722  hid_t save_type_hid = H5T_NATIVE_DOUBLE;
723 
724  if (save_as_floats)
725  {
726  if (m.too_large_for_float ())
727  {
728  warning ("save: some values too large to save as floats --");
729  warning ("save: saving as doubles instead");
730  }
731  else
732  save_type_hid = H5T_NATIVE_FLOAT;
733  }
734 #if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
735  // hdf5 currently doesn't support float/integer conversions
736  else
737  {
738  double max_val, min_val;
739 
740  if (m.all_integers (max_val, min_val))
741  save_type_hid
742  = save_type_to_hdf5 (octave::get_save_type (max_val, min_val));
743  }
744 #endif
745 
746 #if defined (HAVE_HDF5_18)
747  data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
750 #else
751  data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
753 #endif
754  if (data_hid < 0)
755  {
756  H5Sclose (space_hid);
757  return false;
758  }
759 
760  const double *mtmp = m.data ();
761  retval = H5Dwrite (data_hid, H5T_NATIVE_DOUBLE, octave_H5S_ALL,
762  octave_H5S_ALL, octave_H5P_DEFAULT, mtmp) >= 0;
763 
764  H5Dclose (data_hid);
765  H5Sclose (space_hid);
766 
767 #else
768  octave_unused_parameter (loc_id);
769  octave_unused_parameter (name);
770  octave_unused_parameter (save_as_floats);
771 
772  warn_save ("hdf5");
773 #endif
774 
775  return retval;
776 }
777 
778 bool
779 octave_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name)
780 {
781  bool retval = false;
782 
783 #if defined (HAVE_HDF5)
784 
785  dim_vector dv;
786  int empty = load_hdf5_empty (loc_id, name, dv);
787  if (empty > 0)
788  m_matrix.resize (dv);
789  if (empty)
790  return (empty > 0);
791 
792 #if defined (HAVE_HDF5_18)
793  hid_t data_hid = H5Dopen (loc_id, name, octave_H5P_DEFAULT);
794 #else
795  hid_t data_hid = H5Dopen (loc_id, name);
796 #endif
797  hid_t space_id = H5Dget_space (data_hid);
798 
799  hsize_t rank = H5Sget_simple_extent_ndims (space_id);
800 
801  if (rank < 1)
802  {
803  H5Sclose (space_id);
804  H5Dclose (data_hid);
805  return false;
806  }
807 
808  OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
809  OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
810 
811  H5Sget_simple_extent_dims (space_id, hdims, maxdims);
812 
813  // Octave uses column-major, while HDF5 uses row-major ordering
814  if (rank == 1)
815  {
816  dv.resize (2);
817  dv(0) = 1;
818  dv(1) = hdims[0];
819  }
820  else
821  {
822  dv.resize (rank);
823  for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--)
824  dv(j) = hdims[i];
825  }
826 
827  NDArray m (dv);
828  double *re = m.fortran_vec ();
829  if (H5Dread (data_hid, H5T_NATIVE_DOUBLE, octave_H5S_ALL, octave_H5S_ALL,
830  octave_H5P_DEFAULT, re) >= 0)
831  {
832  retval = true;
833  m_matrix = m;
834  }
835 
836  H5Sclose (space_id);
837  H5Dclose (data_hid);
838 
839 #else
840  octave_unused_parameter (loc_id);
841  octave_unused_parameter (name);
842 
843  warn_load ("hdf5");
844 #endif
845 
846  return retval;
847 }
848 
849 void
850 octave_matrix::print_raw (std::ostream& os,
851  bool pr_as_read_syntax) const
852 {
853  octave_print_internal (os, m_matrix, pr_as_read_syntax,
855 }
856 
857 mxArray *
858 octave_matrix::as_mxArray (bool interleaved) const
859 {
860  mxArray *retval = new mxArray (interleaved, mxDOUBLE_CLASS, dims (), mxREAL);
861 
862  mxDouble *pd = static_cast<mxDouble *> (retval->get_data ());
863 
864  mwSize nel = numel ();
865 
866  const double *pdata = m_matrix.data ();
867 
868  for (mwIndex i = 0; i < nel; i++)
869  pd[i] = pdata[i];
870 
871  return retval;
872 }
873 
874 // This uses a smarter strategy for doing the complex->real mappers. We
875 // allocate an array for a real result and keep filling it until a complex
876 // result is produced.
877 static octave_value
878 do_rc_map (const NDArray& a, Complex (&fcn) (double))
879 {
880  octave_idx_type n = a.numel ();
881  NDArray rr (a.dims ());
882 
883  for (octave_idx_type i = 0; i < n; i++)
884  {
885  octave_quit ();
886 
887  Complex tmp = fcn (a(i));
888  if (tmp.imag () == 0.0)
889  rr.xelem (i) = tmp.real ();
890  else
891  {
892  ComplexNDArray rc (a.dims ());
893 
894  for (octave_idx_type j = 0; j < i; j++)
895  rc.xelem (j) = rr.xelem (j);
896 
897  rc.xelem (i) = tmp;
898 
899  for (octave_idx_type j = i+1; j < n; j++)
900  {
901  octave_quit ();
902 
903  rc.xelem (j) = fcn (a(j));
904  }
905 
906  return new octave_complex_matrix (rc);
907  }
908  }
909 
910  return rr;
911 }
912 
915 {
916  switch (umap)
917  {
918  case umap_imag:
919  return NDArray (m_matrix.dims (), 0.0);
920 
921  case umap_real:
922  case umap_conj:
923  return m_matrix;
924 
925  // Mappers handled specially.
926 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \
927  case umap_ ## UMAP: \
928  return octave_value (m_matrix.FCN ())
929 
934 
935 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \
936  case umap_ ## UMAP: \
937  return octave_value (m_matrix.map<TYPE> (FCN))
938 
939 #define RC_ARRAY_MAPPER(UMAP, TYPE, FCN) \
940  case umap_ ## UMAP: \
941  return do_rc_map (m_matrix, FCN)
942 
945  ARRAY_MAPPER (angle, double, std::arg);
946  ARRAY_MAPPER (arg, double, std::arg);
949  ARRAY_MAPPER (atan, double, ::atan);
961  ARRAY_MAPPER (ceil, double, ::ceil);
962  ARRAY_MAPPER (cos, double, ::cos);
963  ARRAY_MAPPER (cosh, double, ::cosh);
964  ARRAY_MAPPER (exp, double, ::exp);
967  ARRAY_MAPPER (floor, double, ::floor);
975  ARRAY_MAPPER (sin, double, ::sin);
976  ARRAY_MAPPER (sinh, double, ::sinh);
978  ARRAY_MAPPER (tan, double, ::tan);
979  ARRAY_MAPPER (tanh, double, ::tanh);
981  ARRAY_MAPPER (xsignbit, double, octave::math::signbit);
982 
983  // Special cases for Matlab compatibility.
984  case umap_xtolower:
985  case umap_xtoupper:
986  return m_matrix;
987 
988  case umap_xisalnum:
989  case umap_xisalpha:
990  case umap_xisascii:
991  case umap_xiscntrl:
992  case umap_xisdigit:
993  case umap_xisgraph:
994  case umap_xislower:
995  case umap_xisprint:
996  case umap_xispunct:
997  case umap_xisspace:
998  case umap_xisupper:
999  case umap_xisxdigit:
1000  {
1001  octave_value str_conv = convert_to_str (true, true);
1002  return str_conv.map (umap);
1003  }
1004 
1005  default:
1006  return octave_base_value::map (umap);
1007  }
1008 }
void swap_bytes< 4 >(void *ptr)
Definition: byte-swap.h:63
charNDArray max(char d, const charNDArray &m)
Definition: chNDArray.cc:230
T & elem(octave_idx_type n)
Size of the specified dimension.
Definition: Array.h:562
int ndims() const
Size of the specified dimension.
Definition: Array.h:671
octave_idx_type rows() const
Definition: Array.h:459
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Definition: Array-base.cc:1023
const T * data() const
Size of the specified dimension.
Definition: Array.h:663
octave_idx_type columns() const
Definition: Array.h:471
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
Definition: Array.h:503
octave_idx_type numel() const
Number of elements in the array.
Definition: Array.h:414
MArray< T > reshape(const dim_vector &new_dims) const
Definition: MArray.h:87
Definition: dMatrix.h:42
Matrix diag(octave_idx_type k=0) const
Definition: dMatrix.cc:2407
bool any_element_not_one_or_zero() const
Definition: dNDArray.cc:330
bool any_element_is_nan() const
Definition: dNDArray.cc:318
NDArray squeeze() const
Definition: dNDArray.h:145
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
Definition: dim-vector.h:335
void resize(int n, int fill_value=0)
Definition: dim-vector.h:272
octave_idx_type ndims() const
Number of dimensions.
Definition: dim-vector.h:257
void * get_data() const
Definition: mxarray.h:473
octave::idx_vector * m_idx_cache
Definition: ov-base-mat.h:229
octave_value diag(octave_idx_type k=0) const
Definition: ov-base-mat.h:142
octave_idx_type numel() const
Definition: ov-base-mat.h:122
sortmode issorted(sortmode mode=UNSORTED) const
Definition: ov-base-mat.h:154
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Definition: ov-base-mat.h:160
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-base-mat.h:148
dim_vector dims() const
Definition: ov-base-mat.h:120
octave_value squeeze() const
Definition: ov-base-mat.h:78
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition: ov-base-mat.h:157
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-base-mat.h:128
octave_idx_type rows() const
Definition: ov-base.h:374
octave_idx_type columns() const
Definition: ov-base.h:381
int current_print_indent_level() const
Definition: ov-base.h:920
virtual octave_value map(unary_mapper_t) const
Definition: ov-base.cc:1181
virtual octave_value convert_to_str(bool pad=false, bool force=false, char type='\'') const
Definition: ov-base.cc:434
void warn_load(const char *type) const
Definition: ov-base.cc:1157
bool isempty() const
Definition: ov-base.h:417
friend class octave_value
Definition: ov-base.h:269
void warn_save(const char *type) const
Definition: ov-base.cc:1166
static int static_type_id()
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-lazy-idx.cc:107
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition: ov-lazy-idx.cc:152
FloatComplexMatrix float_complex_matrix_value(bool=false) const
Definition: ov-re-mat.cc:196
boolNDArray bool_array_value(bool warn=false) const
Definition: ov-re-mat.cc:214
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition: ov-re-mat.cc:405
type_conv_info numeric_demotion_function() const
Definition: ov-re-mat.cc:101
SparseMatrix sparse_matrix_value(bool=false) const
Definition: ov-re-mat.cc:238
octave_value as_uint32() const
Definition: ov-re-mat.cc:301
bool load_ascii(std::istream &is)
Definition: ov-re-mat.cc:503
octave_value as_int64() const
Definition: ov-re-mat.cc:283
FloatComplex float_complex_value(bool=false) const
Definition: ov-re-mat.cc:170
float float_value(bool=false) const
Definition: ov-re-mat.cc:132
octave_base_value * try_narrowing_conversion()
Definition: ov-re-mat.cc:109
octave_value as_int8() const
Definition: ov-re-mat.cc:265
charNDArray char_array_value(bool=false) const
Definition: ov-re-mat.cc:225
FloatMatrix float_matrix_value(bool=false) const
Definition: ov-re-mat.cc:152
bool save_binary(std::ostream &os, bool save_as_floats)
Definition: ov-re-mat.cc:579
octave_value squeeze() const
Definition: ov-re-mat.cc:353
bool save_ascii(std::ostream &os)
Definition: ov-re-mat.cc:474
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Definition: ov-re-mat.cc:244
octave_value as_uint64() const
Definition: ov-re-mat.cc:307
FloatComplexNDArray float_complex_array_value(bool=false) const
Definition: ov-re-mat.cc:208
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
Definition: ov-re-mat.cc:621
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
Definition: ov-re-mat.cc:850
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-re-mat.cc:366
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
Definition: ov-re-mat.cc:695
octave_value as_single() const
Definition: ov-re-mat.cc:259
octave_value as_int16() const
Definition: ov-re-mat.cc:271
Complex complex_value(bool=false) const
Definition: ov-re-mat.cc:158
ComplexNDArray complex_array_value(bool=false) const
Definition: ov-re-mat.cc:202
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-re-mat.cc:340
Matrix matrix_value(bool=false) const
Definition: ov-re-mat.cc:146
octave_value diag(octave_idx_type k=0) const
Definition: ov-re-mat.cc:313
octave_value map(unary_mapper_t umap) const
Definition: ov-re-mat.cc:914
mxArray * as_mxArray(bool interleaved) const
Definition: ov-re-mat.cc:858
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
Definition: ov-re-mat.cc:779
sortmode issorted(sortmode mode=UNSORTED) const
Definition: ov-re-mat.cc:393
ComplexMatrix complex_matrix_value(bool=false) const
Definition: ov-re-mat.cc:190
octave_value as_int32() const
Definition: ov-re-mat.cc:277
FloatNDArray float_array_value(bool=false) const
Definition: ov-re-mat.h:177
octave_value as_uint8() const
Definition: ov-re-mat.cc:289
octave_value as_double() const
Definition: ov-re-mat.cc:253
octave_value convert_to_str_internal(bool pad, bool force, char type) const
Definition: ov-re-mat.cc:431
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Definition: ov-re-mat.cc:418
octave_value as_uint16() const
Definition: ov-re-mat.cc:295
NDArray array_value(bool=false) const
Definition: ov-re-mat.h:175
double double_value(bool=false) const
Definition: ov-re-mat.cc:120
octave_value map(octave_base_value::unary_mapper_t umap) const
Definition: ov.h:1513
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
void read_doubles(std::istream &is, double *data, save_type type, octave_idx_type len, bool swap, octave::mach_info::float_format fmt)
Definition: data-conv.cc:776
void write_doubles(std::ostream &os, const double *data, save_type type, octave_idx_type len)
Definition: data-conv.cc:892
save_type
Definition: data-conv.h:87
@ LS_DOUBLE
Definition: data-conv.h:95
@ LS_FLOAT
Definition: data-conv.h:94
void warning(const char *fmt,...)
Definition: error.cc:1063
void() error(const char *fmt,...)
Definition: error.cc:988
#define panic_impossible()
Definition: error.h:503
void err_invalid_conversion(const std::string &from, const std::string &to)
Definition: errwarn.cc:71
void warn_logical_conversion()
Definition: errwarn.cc:365
void warn_implicit_conversion(const char *id, const char *from, const char *to)
Definition: errwarn.cc:344
function gamma(X)
Definition: gamma.f:3
octave::idx_vector idx_vector
Definition: idx-vector.h:1022
intNDArray< octave_int16 > int16NDArray
Definition: int16NDArray.h:36
intNDArray< octave_int32 > int32NDArray
Definition: int32NDArray.h:36
intNDArray< octave_int64 > int64NDArray
Definition: int64NDArray.h:36
intNDArray< octave_int8 > int8NDArray
Definition: int8NDArray.h:36
void err_nan_to_logical_conversion()
void err_nan_to_character_conversion()
float lo_ieee_float_nan_value()
Definition: lo-ieee.cc:116
Complex log2(const Complex &x)
Definition: lo-mappers.cc:141
Complex rc_acosh(double x)
Definition: lo-mappers.cc:253
Complex rc_atanh(double x)
Definition: lo-mappers.cc:278
Complex rc_log(double x)
Definition: lo-mappers.cc:291
Complex asin(const Complex &x)
Definition: lo-mappers.cc:107
int nint(double x)
Definition: lo-mappers.cc:216
Complex rc_asin(double x)
Definition: lo-mappers.cc:265
bool isna(double x)
Definition: lo-mappers.cc:47
Complex rc_acos(double x)
Definition: lo-mappers.cc:240
Complex rc_sqrt(double x)
Definition: lo-mappers.cc:334
Complex rc_log10(double x)
Definition: lo-mappers.cc:319
Complex acos(const Complex &x)
Definition: lo-mappers.cc:85
Complex rc_log2(double x)
Definition: lo-mappers.cc:304
Complex atan(const Complex &x)
Definition: lo-mappers.h:71
double roundb(double x)
Definition: lo-mappers.h:147
bool isfinite(double x)
Definition: lo-mappers.h:192
bool isinf(double x)
Definition: lo-mappers.h:203
double signbit(double x)
Definition: lo-mappers.h:54
double signum(double x)
Definition: lo-mappers.h:229
double round(double x)
Definition: lo-mappers.h:136
bool isnan(bool)
Definition: lo-mappers.h:178
std::complex< T > floor(const std::complex< T > &x)
Definition: lo-mappers.h:130
std::complex< T > ceil(const std::complex< T > &x)
Definition: lo-mappers.h:103
double fix(double x)
Definition: lo-mappers.h:118
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
double erfinv(double x)
Definition: lo-specfun.cc:1823
double dawson(double x)
Definition: lo-specfun.cc:1467
double erfcinv(double x)
Definition: lo-specfun.cc:1697
Complex rc_log1p(double x)
Definition: lo-specfun.cc:2215
Complex rc_lgamma(double x)
Definition: lo-specfun.cc:2177
Complex expm1(const Complex &x)
Definition: lo-specfun.cc:1835
Complex log1p(const Complex &x)
Definition: lo-specfun.cc:1919
double cbrt(double x)
Definition: lo-specfun.h:289
double asinh(double x)
Definition: lo-specfun.h:58
double atanh(double x)
Definition: lo-specfun.h:63
double acosh(double x)
Definition: lo-specfun.h:40
double lgamma(double x)
Definition: lo-specfun.h:336
int save_hdf5_empty(octave_hdf5_id loc_id, const char *name, const dim_vector &d)
Definition: ls-hdf5.cc:1249
int load_hdf5_empty(octave_hdf5_id loc_id, const char *name, dim_vector &d)
Definition: ls-hdf5.cc:1306
octave_hdf5_id save_type_to_hdf5(save_type st)
Definition: ls-hdf5.cc:1350
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
Definition: ls-oct-text.cc:84
save_type get_save_type(double, double)
Definition: ls-utils.cc:40
float_format
Definition: mach-info.h:38
void mxArray
Definition: mex.h:58
T octave_idx_type m
Definition: mx-inlines.cc:781
octave_idx_type n
Definition: mx-inlines.cc:761
@ mxDOUBLE_CLASS
Definition: mxtypes.h:64
int64_t mwIndex
Definition: mxtypes.h:125
double mxDouble
Definition: mxtypes.h:91
@ mxREAL
Definition: mxtypes.h:80
int64_t mwSize
Definition: mxtypes.h:124
std::complex< double > erfc(std::complex< double > z, double relerr=0)
std::complex< double > erfcx(std::complex< double > z, double relerr=0)
std::complex< double > erfi(std::complex< double > z, double relerr=0)
std::complex< double > erf(std::complex< double > z, double relerr=0)
std::complex< double > Complex
Definition: oct-cmplx.h:33
std::complex< float > FloatComplex
Definition: oct-cmplx.h:34
int64_t octave_hdf5_id
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition: oct-locbuf.h:44
sortmode
Definition: oct-sort.h:97
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:235
#define RC_ARRAY_MAPPER(UMAP, TYPE, FCN)
#define ARRAY_MAPPER(UMAP, TYPE, FCN)
#define ARRAY_METHOD_MAPPER(UMAP, FCN)
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)
Definition: pr-output.cc:1761
template int8_t abs(int8_t)
intNDArray< octave_uint16 > uint16NDArray
Definition: uint16NDArray.h:36
intNDArray< octave_uint32 > uint32NDArray
Definition: uint32NDArray.h:36
intNDArray< octave_uint64 > uint64NDArray
Definition: uint64NDArray.h:36
intNDArray< octave_uint8 > uint8NDArray
Definition: uint8NDArray.h:36
F77_RET_T len
Definition: xerbla.cc:61