GNU Octave  6.2.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-2021 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 <istream>
31 #include <limits>
32 #include <ostream>
33 #include <vector>
34 
35 #include "dNDArray.h"
36 #include "fNDArray.h"
37 #include "int8NDArray.h"
38 #include "int16NDArray.h"
39 #include "int32NDArray.h"
40 #include "int64NDArray.h"
41 #include "uint8NDArray.h"
42 #include "uint16NDArray.h"
43 #include "uint32NDArray.h"
44 #include "uint64NDArray.h"
45 
46 #include "data-conv.h"
47 #include "lo-ieee.h"
48 #include "lo-utils.h"
49 #include "lo-specfun.h"
50 #include "lo-mappers.h"
51 #include "mach-info.h"
52 #include "mx-base.h"
53 #include "quit.h"
54 #include "oct-locbuf.h"
55 
56 #include "defun.h"
57 #include "errwarn.h"
58 #include "mxarray.h"
59 #include "ovl.h"
60 #include "oct-lvalue.h"
61 #include "oct-hdf5.h"
62 #include "oct-stream.h"
63 #include "ops.h"
64 #include "ov-base.h"
65 #include "ov-base-mat.h"
66 #include "ov-base-mat.cc"
67 #include "ov-scalar.h"
68 #include "ov-re-mat.h"
69 #include "ov-flt-re-mat.h"
70 #include "ov-complex.h"
71 #include "ov-cx-mat.h"
72 #include "ov-re-sparse.h"
73 #include "ov-re-diag.h"
74 #include "ov-cx-diag.h"
75 #include "ov-lazy-idx.h"
76 #include "ov-perm.h"
77 #include "pr-flt-fmt.h"
78 #include "pr-output.h"
79 #include "variables.h"
80 
81 #include "byte-swap.h"
82 #include "ls-oct-text.h"
83 #include "ls-utils.h"
84 #include "ls-hdf5.h"
85 
86 
87 template class octave_base_matrix<NDArray>;
88 
90 
91 static octave_base_value *
93 {
94  const octave_matrix& v = dynamic_cast<const octave_matrix&> (a);
95 
96  return new octave_float_matrix (v.float_array_value ());
97 }
98 
101 {
105 }
106 
109 {
110  octave_base_value *retval = nullptr;
111 
112  if (matrix.numel () == 1)
113  retval = new octave_scalar (matrix (0));
114 
115  return retval;
116 }
117 
118 double
120 {
121  if (isempty ())
122  err_invalid_conversion ("real matrix", "real scalar");
123 
124  warn_implicit_conversion ("Octave:array-to-scalar",
125  "real matrix", "real scalar");
126 
127  return matrix(0, 0);
128 }
129 
130 float
132 {
133  if (isempty ())
134  err_invalid_conversion ("real matrix", "real scalar");
135 
136  warn_implicit_conversion ("Octave:array-to-scalar",
137  "real matrix", "real scalar");
138 
139  return matrix(0, 0);
140 }
141 
142 // FIXME
143 
144 Matrix
146 {
147  return Matrix (matrix);
148 }
149 
152 {
153  return FloatMatrix (Matrix (matrix));
154 }
155 
156 Complex
158 {
159  if (rows () == 0 || columns () == 0)
160  err_invalid_conversion ("real matrix", "complex scalar");
161 
162  warn_implicit_conversion ("Octave:array-to-scalar",
163  "real matrix", "complex scalar");
164 
165  return Complex (matrix(0, 0), 0);
166 }
167 
170 {
171  float tmp = lo_ieee_float_nan_value ();
172 
173  FloatComplex retval (tmp, tmp);
174 
175  if (rows () == 0 || columns () == 0)
176  err_invalid_conversion ("real matrix", "complex scalar");
177 
178  warn_implicit_conversion ("Octave:array-to-scalar",
179  "real matrix", "complex scalar");
180 
181  retval = matrix(0, 0);
182 
183  return retval;
184 }
185 
186 // FIXME
187 
190 {
191  return ComplexMatrix (Matrix (matrix));
192 }
193 
196 {
197  return FloatComplexMatrix (Matrix (matrix));
198 }
199 
202 {
203  return ComplexNDArray (matrix);
204 }
205 
208 {
209  return FloatComplexNDArray (matrix);
210 }
211 
214 {
215  if (matrix.any_element_is_nan ())
217  if (warn && matrix.any_element_not_one_or_zero ())
219 
220  return boolNDArray (matrix);
221 }
222 
225 {
226  charNDArray retval (dims ());
227 
228  octave_idx_type nel = numel ();
229 
230  for (octave_idx_type i = 0; i < nel; i++)
231  retval.elem (i) = static_cast<char> (matrix.elem (i));
232 
233  return retval;
234 }
235 
238 {
239  return SparseMatrix (Matrix (matrix));
240 }
241 
244 {
245  // FIXME: Need a SparseComplexMatrix (Matrix) constructor to make
246  // this function more efficient. Then this should become
247  // return SparseComplexMatrix (matrix.matrix_value ());
249 }
250 
253 {
254  return NDArray (matrix);
255 }
256 
259 {
260  return FloatNDArray (matrix);
261 }
262 
265 {
266  return int8NDArray (matrix);
267 }
268 
271 {
272  return int16NDArray (matrix);
273 }
274 
277 {
278  return int32NDArray (matrix);
279 }
280 
283 {
284  return int64NDArray (matrix);
285 }
286 
289 {
290  return uint8NDArray (matrix);
291 }
292 
295 {
296  return uint16NDArray (matrix);
297 }
298 
301 {
302  return uint32NDArray (matrix);
303 }
304 
307 {
308  return uint64NDArray (matrix);
309 }
310 
313 {
315  if (k == 0 && matrix.ndims () == 2
316  && (matrix.rows () == 1 || matrix.columns () == 1))
318  else
320 
321  return retval;
322 }
323 
326 {
327  if (matrix.ndims () != 2
328  || (matrix.rows () != 1 && matrix.columns () != 1))
329  error ("diag: expecting vector argument");
330 
331  Matrix mat (matrix);
332 
333  return mat.diag (m, n);
334 }
335 
336 // We override these two functions to allow reshaping both
337 // the matrix and the index cache.
339 octave_matrix::reshape (const dim_vector& new_dims) const
340 {
341  if (idx_cache)
342  {
343  return new octave_matrix (matrix.reshape (new_dims),
344  idx_vector (idx_cache->as_array ().reshape (new_dims),
345  idx_cache->extent (0)));
346  }
347  else
348  return octave_base_matrix<NDArray>::reshape (new_dims);
349 }
350 
353 {
354  if (idx_cache)
355  {
356  return new octave_matrix (matrix.squeeze (),
358  idx_cache->extent (0)));
359  }
360  else
362 }
363 
366 {
367  if (idx_cache)
368  {
369  // This is a valid index matrix, so sort via integers because it's
370  // generally more efficient.
371  return octave_lazy_index (*idx_cache).sort (dim, mode);
372  }
373  else
374  return octave_base_matrix<NDArray>::sort (dim, mode);
375 }
376 
379  sortmode mode) const
380 {
381  if (idx_cache)
382  {
383  // This is a valid index matrix, so sort via integers because it's
384  // generally more efficient.
385  return octave_lazy_index (*idx_cache).sort (sidx, dim, mode);
386  }
387  else
388  return octave_base_matrix<NDArray>::sort (sidx, dim, mode);
389 }
390 
391 sortmode
393 {
394  if (idx_cache)
395  {
396  // This is a valid index matrix, so check via integers because it's
397  // generally more efficient.
398  return idx_cache->as_array ().issorted (mode);
399  }
400  else
402 }
405 {
406  if (idx_cache)
407  {
408  // This is a valid index matrix, so sort via integers because it's
409  // generally more efficient.
410  return octave_lazy_index (*idx_cache).sort_rows_idx (mode);
411  }
412  else
414 }
415 
416 sortmode
418 {
419  if (idx_cache)
420  {
421  // This is a valid index matrix, so check via integers because it's
422  // generally more efficient.
423  return idx_cache->as_array ().is_sorted_rows (mode);
424  }
425  else
427 }
428 
431 {
433  dim_vector dv = dims ();
434  octave_idx_type nel = dv.numel ();
435 
436  charNDArray chm (dv);
437 
438  bool warned = false;
439 
440  for (octave_idx_type i = 0; i < nel; i++)
441  {
442  octave_quit ();
443 
444  double d = matrix(i);
445 
446  if (octave::math::isnan (d))
448 
449  int ival = octave::math::nint (d);
450 
451  if (ival < 0 || ival > std::numeric_limits<unsigned char>::max ())
452  {
453  // FIXME: is there something better we could do?
454 
455  ival = 0;
456 
457  if (! warned)
458  {
459  ::warning ("range error for conversion to character value");
460  warned = true;
461  }
462  }
463 
464  chm(i) = static_cast<char> (ival);
465  }
466 
467  retval = octave_value (chm, type);
468 
469  return retval;
470 }
471 
472 bool
473 octave_matrix::save_ascii (std::ostream& os)
474 {
475  dim_vector dv = dims ();
476 
477  if (dv.ndims () > 2)
478  {
479  NDArray tmp = array_value ();
480 
481  os << "# ndims: " << dv.ndims () << "\n";
482 
483  for (int i=0; i < dv.ndims (); i++)
484  os << ' ' << dv(i);
485 
486  os << "\n" << tmp;
487  }
488  else
489  {
490  // Keep this case, rather than use generic code above for backward
491  // compatibility. Makes load_ascii much more complex!!
492  os << "# rows: " << rows () << "\n"
493  << "# columns: " << columns () << "\n";
494 
495  os << matrix_value ();
496  }
497 
498  return true;
499 }
500 
501 bool
502 octave_matrix::load_ascii (std::istream& is)
503 {
504  string_vector keywords(2);
505 
506  keywords[0] = "ndims";
507  keywords[1] = "rows";
508 
509  std::string kw;
510  octave_idx_type val = 0;
511 
512  if (! extract_keyword (is, keywords, kw, val, true))
513  error ("load: failed to extract number of rows and columns");
514 
515  if (kw == "ndims")
516  {
517  int mdims = static_cast<int> (val);
518 
519  if (mdims < 0)
520  error ("load: failed to extract number of dimensions");
521 
522  dim_vector dv;
523  dv.resize (mdims);
524 
525  for (int i = 0; i < mdims; i++)
526  is >> dv(i);
527 
528  if (! is)
529  error ("load: failed to read dimensions");
530 
531  NDArray tmp(dv);
532 
533  is >> tmp;
534 
535  if (! is)
536  error ("load: failed to load matrix constant");
537 
538  matrix = tmp;
539  }
540  else if (kw == "rows")
541  {
542  octave_idx_type nr = val;
543  octave_idx_type nc = 0;
544 
545  if (nr < 0 || ! extract_keyword (is, "columns", nc) || nc < 0)
546  error ("load: failed to extract number of rows and columns");
547 
548  if (nr > 0 && nc > 0)
549  {
550  Matrix tmp (nr, nc);
551  is >> tmp;
552  if (! is)
553  error ("load: failed to load matrix constant");
554 
555  matrix = tmp;
556  }
557  else if (nr == 0 || nc == 0)
558  matrix = Matrix (nr, nc);
559  else
560  panic_impossible ();
561  }
562  else
563  panic_impossible ();
564 
565  return true;
566 }
567 
568 bool
569 octave_matrix::save_binary (std::ostream& os, bool save_as_floats)
570 {
571 
572  dim_vector dv = dims ();
573  if (dv.ndims () < 1)
574  return false;
575 
576  // Use negative value for ndims to differentiate with old format!!
577  int32_t tmp = - dv.ndims ();
578  os.write (reinterpret_cast<char *> (&tmp), 4);
579  for (int i = 0; i < dv.ndims (); i++)
580  {
581  tmp = dv(i);
582  os.write (reinterpret_cast<char *> (&tmp), 4);
583  }
584 
585  NDArray m = array_value ();
586  save_type st = LS_DOUBLE;
587  if (save_as_floats)
588  {
589  if (m.too_large_for_float ())
590  {
591  warning ("save: some values too large to save as floats --");
592  warning ("save: saving as doubles instead");
593  }
594  else
595  st = LS_FLOAT;
596  }
597  else if (dv.numel () > 8192) // FIXME: make this configurable.
598  {
599  double max_val, min_val;
600  if (m.all_integers (max_val, min_val))
601  st = get_save_type (max_val, min_val);
602  }
603 
604  const double *mtmp = m.data ();
605  write_doubles (os, mtmp, st, dv.numel ());
606 
607  return true;
608 }
609 
610 bool
611 octave_matrix::load_binary (std::istream& is, bool swap,
613 {
614  char tmp;
615  int32_t mdims;
616  if (! is.read (reinterpret_cast<char *> (&mdims), 4))
617  return false;
618  if (swap)
619  swap_bytes<4> (&mdims);
620  if (mdims < 0)
621  {
622  mdims = - mdims;
623  int32_t di;
624  dim_vector dv;
625  dv.resize (mdims);
626 
627  for (int i = 0; i < mdims; i++)
628  {
629  if (! is.read (reinterpret_cast<char *> (&di), 4))
630  return false;
631  if (swap)
632  swap_bytes<4> (&di);
633  dv(i) = di;
634  }
635 
636  // Convert an array with a single dimension to be a row vector.
637  // Octave should never write files like this, other software
638  // might.
639 
640  if (mdims == 1)
641  {
642  mdims = 2;
643  dv.resize (mdims);
644  dv(1) = dv(0);
645  dv(0) = 1;
646  }
647 
648  if (! is.read (reinterpret_cast<char *> (&tmp), 1))
649  return false;
650 
651  NDArray m(dv);
652  double *re = m.fortran_vec ();
653  read_doubles (is, re, static_cast<save_type> (tmp), dv.numel (),
654  swap, fmt);
655 
656  if (! is)
657  return false;
658 
659  matrix = m;
660  }
661  else
662  {
663  int32_t nr, nc;
664  nr = mdims;
665  if (! is.read (reinterpret_cast<char *> (&nc), 4))
666  return false;
667  if (swap)
668  swap_bytes<4> (&nc);
669  if (! is.read (reinterpret_cast<char *> (&tmp), 1))
670  return false;
671  Matrix m (nr, nc);
672  double *re = m.fortran_vec ();
673  octave_idx_type len = nr * nc;
674  read_doubles (is, re, static_cast<save_type> (tmp), len, swap, fmt);
675 
676  if (! is)
677  return false;
678 
679  matrix = m;
680  }
681  return true;
682 }
683 
684 bool
686  bool save_as_floats)
687 {
688  bool retval = false;
689 
690 #if defined (HAVE_HDF5)
691 
692  dim_vector dv = dims ();
693  int empty = save_hdf5_empty (loc_id, name, dv);
694  if (empty)
695  return (empty > 0);
696 
697  int rank = dv.ndims ();
698  hid_t space_hid, data_hid;
699  space_hid = data_hid = -1;
700  NDArray m = array_value ();
701 
702  OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
703 
704  // Octave uses column-major, while HDF5 uses row-major ordering
705  for (int i = 0; i < rank; i++)
706  hdims[i] = dv(rank-i-1);
707 
708  space_hid = H5Screate_simple (rank, hdims, nullptr);
709 
710  if (space_hid < 0) return false;
711 
712  hid_t save_type_hid = H5T_NATIVE_DOUBLE;
713 
714  if (save_as_floats)
715  {
716  if (m.too_large_for_float ())
717  {
718  warning ("save: some values too large to save as floats --");
719  warning ("save: saving as doubles instead");
720  }
721  else
722  save_type_hid = H5T_NATIVE_FLOAT;
723  }
724 #if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
725  // hdf5 currently doesn't support float/integer conversions
726  else
727  {
728  double max_val, min_val;
729 
730  if (m.all_integers (max_val, min_val))
731  save_type_hid
732  = save_type_to_hdf5 (get_save_type (max_val, min_val));
733  }
734 #endif
735 
736 #if defined (HAVE_HDF5_18)
737  data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
739 #else
740  data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
742 #endif
743  if (data_hid < 0)
744  {
745  H5Sclose (space_hid);
746  return false;
747  }
748 
749  double *mtmp = m.fortran_vec ();
750  retval = H5Dwrite (data_hid, H5T_NATIVE_DOUBLE, octave_H5S_ALL, octave_H5S_ALL,
751  octave_H5P_DEFAULT, mtmp) >= 0;
752 
753  H5Dclose (data_hid);
754  H5Sclose (space_hid);
755 
756 #else
757  octave_unused_parameter (loc_id);
758  octave_unused_parameter (name);
759  octave_unused_parameter (save_as_floats);
760 
761  warn_save ("hdf5");
762 #endif
763 
764  return retval;
765 }
766 
767 bool
769 {
770  bool retval = false;
771 
772 #if defined (HAVE_HDF5)
773 
774  dim_vector dv;
775  int empty = load_hdf5_empty (loc_id, name, dv);
776  if (empty > 0)
777  matrix.resize (dv);
778  if (empty)
779  return (empty > 0);
780 
781 #if defined (HAVE_HDF5_18)
782  hid_t data_hid = H5Dopen (loc_id, name, octave_H5P_DEFAULT);
783 #else
784  hid_t data_hid = H5Dopen (loc_id, name);
785 #endif
786  hid_t space_id = H5Dget_space (data_hid);
787 
788  hsize_t rank = H5Sget_simple_extent_ndims (space_id);
789 
790  if (rank < 1)
791  {
792  H5Sclose (space_id);
793  H5Dclose (data_hid);
794  return false;
795  }
796 
797  OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
798  OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
799 
800  H5Sget_simple_extent_dims (space_id, hdims, maxdims);
801 
802  // Octave uses column-major, while HDF5 uses row-major ordering
803  if (rank == 1)
804  {
805  dv.resize (2);
806  dv(0) = 1;
807  dv(1) = hdims[0];
808  }
809  else
810  {
811  dv.resize (rank);
812  for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--)
813  dv(j) = hdims[i];
814  }
815 
816  NDArray m (dv);
817  double *re = m.fortran_vec ();
818  if (H5Dread (data_hid, H5T_NATIVE_DOUBLE, octave_H5S_ALL, octave_H5S_ALL,
819  octave_H5P_DEFAULT, re) >= 0)
820  {
821  retval = true;
822  matrix = m;
823  }
824 
825  H5Sclose (space_id);
826  H5Dclose (data_hid);
827 
828 #else
829  octave_unused_parameter (loc_id);
830  octave_unused_parameter (name);
831 
832  warn_load ("hdf5");
833 #endif
834 
835  return retval;
836 }
837 
838 void
839 octave_matrix::print_raw (std::ostream& os,
840  bool pr_as_read_syntax) const
841 {
842  octave_print_internal (os, matrix, pr_as_read_syntax,
844 }
845 
846 mxArray *
848 {
850 
851  double *pr = static_cast<double *> (retval->get_data ());
852 
853  mwSize nel = numel ();
854 
855  const double *p = matrix.data ();
856 
857  for (mwIndex i = 0; i < nel; i++)
858  pr[i] = p[i];
859 
860  return retval;
861 }
862 
863 // This uses a smarter strategy for doing the complex->real mappers. We
864 // allocate an array for a real result and keep filling it until a complex
865 // result is produced.
866 static octave_value
867 do_rc_map (const NDArray& a, Complex (&fcn) (double))
868 {
869  octave_idx_type n = a.numel ();
870  NDArray rr (a.dims ());
871 
872  for (octave_idx_type i = 0; i < n; i++)
873  {
874  octave_quit ();
875 
876  Complex tmp = fcn (a(i));
877  if (tmp.imag () == 0.0)
878  rr.xelem (i) = tmp.real ();
879  else
880  {
881  ComplexNDArray rc (a.dims ());
882 
883  for (octave_idx_type j = 0; j < i; j++)
884  rc.xelem (j) = rr.xelem (j);
885 
886  rc.xelem (i) = tmp;
887 
888  for (octave_idx_type j = i+1; j < n; j++)
889  {
890  octave_quit ();
891 
892  rc.xelem (j) = fcn (a(j));
893  }
894 
895  return new octave_complex_matrix (rc);
896  }
897  }
898 
899  return rr;
900 }
901 
904 {
905  switch (umap)
906  {
907  case umap_imag:
908  return NDArray (matrix.dims (), 0.0);
909 
910  case umap_real:
911  case umap_conj:
912  return matrix;
913 
914  // Mappers handled specially.
915 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \
916  case umap_ ## UMAP: \
917  return octave_value (matrix.FCN ())
918 
923 
924 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \
925  case umap_ ## UMAP: \
926  return octave_value (matrix.map<TYPE> (FCN))
927 
928 #define RC_ARRAY_MAPPER(UMAP, TYPE, FCN) \
929  case umap_ ## UMAP: \
930  return do_rc_map (matrix, FCN)
931 
934  ARRAY_MAPPER (angle, double, std::arg);
935  ARRAY_MAPPER (arg, double,std::arg);
938  ARRAY_MAPPER (atan, double, ::atan);
950  ARRAY_MAPPER (ceil, double, ::ceil);
951  ARRAY_MAPPER (cos, double, ::cos);
952  ARRAY_MAPPER (cosh, double, ::cosh);
953  ARRAY_MAPPER (exp, double, ::exp);
956  ARRAY_MAPPER (floor, double, ::floor);
964  ARRAY_MAPPER (sin, double, ::sin);
965  ARRAY_MAPPER (sinh, double, ::sinh);
967  ARRAY_MAPPER (tan, double, ::tan);
968  ARRAY_MAPPER (tanh, double, ::tanh);
970  ARRAY_MAPPER (xsignbit, double, octave::math::signbit);
971 
972  // Special cases for Matlab compatibility.
973  case umap_xtolower:
974  case umap_xtoupper:
975  return matrix;
976 
977  case umap_xisalnum:
978  case umap_xisalpha:
979  case umap_xisascii:
980  case umap_xiscntrl:
981  case umap_xisdigit:
982  case umap_xisgraph:
983  case umap_xislower:
984  case umap_xisprint:
985  case umap_xispunct:
986  case umap_xisspace:
987  case umap_xisupper:
988  case umap_xisxdigit:
989  {
990  octave_value str_conv = convert_to_str (true, true);
991  return str_conv.map (umap);
992  }
993 
994  default:
995  return octave_base_value::map (umap);
996  }
997 }
void swap_bytes< 4 >(void *ptr)
Definition: byte-swap.h:63
charNDArray max(char d, const charNDArray &m)
Definition: chNDArray.cc:230
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Definition: Array.cc:1011
sortmode issorted(sortmode mode=UNSORTED) const
Ordering is auto-detected or can be specified.
Definition: Array.cc:2034
Array< T > squeeze(void) const
Chop off leading singleton dimensions.
Definition: Array.cc:117
octave_idx_type columns(void) const
Definition: Array.h:424
T & xelem(octave_idx_type n)
Size of the specified dimension.
Definition: Array.h:469
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:377
T & elem(octave_idx_type n)
Size of the specified dimension.
Definition: Array.h:499
const T * data(void) const
Size of the specified dimension.
Definition: Array.h:581
octave_idx_type rows(void) const
Definition: Array.h:415
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Ordering is auto-detected or can be specified.
Definition: Array.cc:2084
Array< T > reshape(octave_idx_type nr, octave_idx_type nc) const
Size of the specified dimension.
Definition: Array.h:560
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Definition: Array.h:453
int ndims(void) const
Size of the specified dimension.
Definition: Array.h:589
MArray< T > reshape(const dim_vector &new_dims) const
Definition: MArray.h:93
Definition: dMatrix.h:42
Matrix diag(octave_idx_type k=0) const
Definition: dMatrix.cc:2391
bool any_element_is_nan(void) const
Definition: dNDArray.cc:318
bool any_element_not_one_or_zero(void) const
Definition: dNDArray.cc:330
NDArray squeeze(void) const
Definition: dNDArray.h:144
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:95
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
Definition: dim-vector.h:401
void resize(int n, int fill_value=0)
Definition: dim-vector.h:349
octave_idx_type ndims(void) const
Number of dimensions.
Definition: dim-vector.h:334
Array< octave_idx_type > as_array(void) const
Definition: idx-vector.cc:1273
octave_idx_type extent(octave_idx_type n) const
Definition: idx-vector.h:561
octave_idx_type numel(void) const
Definition: ov-base-mat.h:114
octave_value diag(octave_idx_type k=0) const
Definition: ov-base-mat.h:134
sortmode issorted(sortmode mode=UNSORTED) const
Definition: ov-base-mat.h:146
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Definition: ov-base-mat.h:152
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-base-mat.h:140
octave_value squeeze(void) const
Definition: ov-base-mat.h:74
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition: ov-base-mat.h:149
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-base-mat.h:120
dim_vector dims(void) const
Definition: ov-base-mat.h:112
octave_idx_type columns(void) const
Definition: ov-base.h:325
int current_print_indent_level(void) const
Definition: ov-base.h:847
virtual octave_value map(unary_mapper_t) const
Definition: ov-base.cc:1114
virtual octave_value convert_to_str(bool pad=false, bool force=false, char type='\'') const
Definition: ov-base.cc:377
void warn_load(const char *type) const
Definition: ov-base.cc:1090
octave_idx_type rows(void) const
Definition: ov-base.h:318
friend class octave_value
Definition: ov-base.h:228
void warn_save(const char *type) const
Definition: ov-base.cc:1099
bool isempty(void) const
Definition: ov-base.h:357
static int static_type_id(void)
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:195
boolNDArray bool_array_value(bool warn=false) const
Definition: ov-re-mat.cc:213
octave_value as_int32(void) const
Definition: ov-re-mat.cc:276
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition: ov-re-mat.cc:404
SparseMatrix sparse_matrix_value(bool=false) const
Definition: ov-re-mat.cc:237
bool load_ascii(std::istream &is)
Definition: ov-re-mat.cc:502
octave_matrix(void)
Definition: ov-re-mat.h:57
octave_value as_uint32(void) const
Definition: ov-re-mat.cc:300
mxArray * as_mxArray(void) const
Definition: ov-re-mat.cc:847
FloatComplex float_complex_value(bool=false) const
Definition: ov-re-mat.cc:169
float float_value(bool=false) const
Definition: ov-re-mat.cc:131
octave_value as_int64(void) const
Definition: ov-re-mat.cc:282
octave_value as_uint8(void) const
Definition: ov-re-mat.cc:288
octave_value as_double(void) const
Definition: ov-re-mat.cc:252
charNDArray char_array_value(bool=false) const
Definition: ov-re-mat.cc:224
FloatMatrix float_matrix_value(bool=false) const
Definition: ov-re-mat.cc:151
bool save_binary(std::ostream &os, bool save_as_floats)
Definition: ov-re-mat.cc:569
bool save_ascii(std::ostream &os)
Definition: ov-re-mat.cc:473
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Definition: ov-re-mat.cc:243
FloatComplexNDArray float_complex_array_value(bool=false) const
Definition: ov-re-mat.cc:207
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
Definition: ov-re-mat.cc:611
type_conv_info numeric_demotion_function(void) const
Definition: ov-re-mat.cc:100
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
Definition: ov-re-mat.cc:839
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-re-mat.cc:365
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
Definition: ov-re-mat.cc:685
octave_base_value * try_narrowing_conversion(void)
Definition: ov-re-mat.cc:108
Complex complex_value(bool=false) const
Definition: ov-re-mat.cc:157
ComplexNDArray complex_array_value(bool=false) const
Definition: ov-re-mat.cc:201
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-re-mat.cc:339
Matrix matrix_value(bool=false) const
Definition: ov-re-mat.cc:145
octave_value as_int8(void) const
Definition: ov-re-mat.cc:264
octave_value diag(octave_idx_type k=0) const
Definition: ov-re-mat.cc:312
octave_value map(unary_mapper_t umap) const
Definition: ov-re-mat.cc:903
octave_value squeeze(void) const
Definition: ov-re-mat.cc:352
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
Definition: ov-re-mat.cc:768
octave_value as_int16(void) const
Definition: ov-re-mat.cc:270
sortmode issorted(sortmode mode=UNSORTED) const
Definition: ov-re-mat.cc:392
ComplexMatrix complex_matrix_value(bool=false) const
Definition: ov-re-mat.cc:189
FloatNDArray float_array_value(bool=false) const
Definition: ov-re-mat.h:174
octave_value convert_to_str_internal(bool pad, bool force, char type) const
Definition: ov-re-mat.cc:430
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Definition: ov-re-mat.cc:417
octave_value as_uint64(void) const
Definition: ov-re-mat.cc:306
octave_value as_single(void) const
Definition: ov-re-mat.cc:258
NDArray array_value(bool=false) const
Definition: ov-re-mat.h:172
octave_value as_uint16(void) const
Definition: ov-re-mat.cc:294
double double_value(bool=false) const
Definition: ov-re-mat.cc:119
octave_value map(octave_base_value::unary_mapper_t umap) const
Definition: ov.h:1436
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:891
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:1050
void error(const char *fmt,...)
Definition: error.cc:968
#define panic_impossible()
Definition: error.h:380
void err_invalid_conversion(const std::string &from, const std::string &to)
Definition: errwarn.cc:71
void warn_logical_conversion(void)
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
QString name
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
float lo_ieee_float_nan_value(void)
Definition: lo-ieee.cc:126
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
int save_hdf5_empty(octave_hdf5_id loc_id, const char *name, const dim_vector &d)
Definition: ls-hdf5.cc:1224
int load_hdf5_empty(octave_hdf5_id loc_id, const char *name, dim_vector &d)
Definition: ls-hdf5.cc:1280
octave_hdf5_id save_type_to_hdf5(save_type st)
Definition: ls-hdf5.cc:1324
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:38
void mxArray
Definition: mex.h:58
T octave_idx_type m
Definition: mx-inlines.cc:773
octave_idx_type n
Definition: mx-inlines.cc:753
OCTAVE_IDX_TYPE mwSize
Definition: mxarray.in.h:97
@ mxDOUBLE_CLASS
Definition: mxarray.in.h:64
OCTAVE_IDX_TYPE mwIndex
Definition: mxarray.in.h:98
@ mxREAL
Definition: mxarray.in.h:80
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)
double fix(double x)
Definition: lo-mappers.h:118
Complex atan(const Complex &x)
Definition: lo-mappers.h:71
double signum(double x)
Definition: lo-mappers.h:222
double asinh(double x)
Definition: lo-specfun.h:69
double gamma(double x)
Definition: lo-specfun.cc:1912
bool isna(double x)
Definition: lo-mappers.cc:47
Complex rc_acos(double x)
Definition: lo-mappers.cc:230
double signbit(double x)
Definition: lo-mappers.h:54
double atanh(double x)
Definition: lo-specfun.h:74
bool isfinite(double x)
Definition: lo-mappers.h:192
int nint(double x)
Definition: lo-mappers.cc:208
double roundb(double x)
Definition: lo-mappers.h:147
bool isnan(bool)
Definition: lo-mappers.h:178
Complex log1p(const Complex &x)
Definition: lo-specfun.cc:1958
bool isinf(double x)
Definition: lo-mappers.h:203
Complex acos(const Complex &x)
Definition: lo-mappers.cc:85
double round(double x)
Definition: lo-mappers.h:136
Complex asin(const Complex &x)
Definition: lo-mappers.cc:107
double erfcx(double x)
Definition: lo-specfun.cc:1755
Complex rc_log2(double x)
Definition: lo-mappers.cc:294
Complex rc_log(double x)
Definition: lo-mappers.cc:281
Complex erfc(const Complex &x)
Definition: lo-specfun.cc:1652
double acosh(double x)
Definition: lo-specfun.h:51
Complex rc_sqrt(double x)
Definition: lo-mappers.cc:324
double erfcinv(double x)
Definition: lo-specfun.cc:1744
Complex rc_atanh(double x)
Definition: lo-mappers.cc:268
std::complex< T > ceil(const std::complex< T > &x)
Definition: lo-mappers.h:103
Complex rc_acosh(double x)
Definition: lo-mappers.cc:243
double erfi(double x)
Definition: lo-specfun.cc:1774
Complex rc_log1p(double x)
Definition: lo-specfun.cc:2247
double lgamma(double x)
Definition: lo-specfun.h:347
double erfinv(double x)
Definition: lo-specfun.cc:1863
Complex rc_log10(double x)
Definition: lo-mappers.cc:309
Complex rc_lgamma(double x)
Definition: lo-specfun.cc:2210
double dawson(double x)
Definition: lo-specfun.cc:1517
double cbrt(double x)
Definition: lo-specfun.h:300
Complex rc_asin(double x)
Definition: lo-mappers.cc:255
Complex log2(const Complex &x)
Definition: lo-mappers.cc:139
std::complex< T > floor(const std::complex< T > &x)
Definition: lo-mappers.h:130
Complex erf(const Complex &x)
Definition: lo-specfun.cc:1637
Complex expm1(const Complex &x)
Definition: lo-specfun.cc:1874
void err_nan_to_logical_conversion(void)
void err_nan_to_character_conversion(void)
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:95
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:180
static octave_value do_rc_map(const NDArray &a, Complex(&fcn)(double))
Definition: ov-re-mat.cc:867
#define RC_ARRAY_MAPPER(UMAP, TYPE, FCN)
#define ARRAY_MAPPER(UMAP, TYPE, FCN)
#define ARRAY_METHOD_MAPPER(UMAP, FCN)
static octave_base_value * default_numeric_demotion_function(const octave_base_value &a)
Definition: ov-re-mat.cc:92
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)
Definition: pr-output.cc:1762
static T abs(T x)
Definition: pr-output.cc:1678
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