GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-cell.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1999-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 <istream>
31 #include <ostream>
32 #include <sstream>
33 #include <vector>
34 #include <queue>
35 
36 #include "Array-util.h"
37 #include "byte-swap.h"
38 #include "lo-utils.h"
39 #include "quit.h"
40 #include "oct-locbuf.h"
41 
42 #include "builtin-defun-decls.h"
43 #include "defun.h"
44 #include "error.h"
45 #include "mxarray.h"
46 #include "ov-cell.h"
47 #include "ovl.h"
48 #include "oct-hdf5.h"
49 #include "unwind-prot.h"
50 #include "utils.h"
51 #include "ov-base-mat.h"
52 #include "ov-base-mat.cc"
53 #include "ov-fcn-handle.h"
54 #include "ov-re-mat.h"
55 #include "ov-scalar.h"
56 #include "pr-output.h"
57 #include "ov-scalar.h"
58 #include "errwarn.h"
59 
60 #include "ls-oct-text.h"
61 #include "ls-oct-binary.h"
62 #include "ls-hdf5.h"
63 #include "ls-utils.h"
64 
65 // Cell is able to handle octave_value indexing by itself, so just forward
66 // everything.
67 
68 template <>
71  bool resize_ok)
72 {
73  return m_matrix.index (idx, resize_ok);
74 }
75 
76 template <>
77 void
79 {
80  m_matrix.assign (idx, rhs);
81 }
82 
83 template <>
84 void
86  octave_value rhs)
87 {
88  // FIXME: Really?
89  if (rhs.iscell ())
90  m_matrix.assign (idx, rhs.cell_value ());
91  else
92  m_matrix.assign (idx, Cell (rhs));
93 }
94 
95 template <>
96 void
98 {
99  m_matrix.delete_elements (idx);
100 }
101 
102 // FIXME: this list of specializations is becoming so long that we should
103 // really ask whether octave_cell should inherit from octave_base_matrix at all.
104 
105 template <>
106 std::string
108  octave_idx_type i,
109  octave_idx_type j) const
110 {
111  octave_value val = m_matrix(i, j);
112 
113  std::string tname = val.type_name ();
114  dim_vector dv = val.dims ();
115  std::string dimstr = dv.str ();
116  return "[" + dimstr + " " + tname + "]";
117 }
118 
119 template <>
122 {
123  if (n < m_matrix.numel ())
124  return Cell (m_matrix(n));
125  else
126  return octave_value ();
127 }
128 
129 template <>
130 bool
132  const octave_value& x)
133 {
134  const octave_cell *xrep = dynamic_cast<const octave_cell *> (&x.get_rep ());
135 
136  bool retval = xrep && xrep->m_matrix.numel () == 1 && n < m_matrix.numel ();
137  if (retval)
138  m_matrix(n) = xrep->m_matrix(0);
139 
140  return retval;
141 }
142 
143 template class octave_base_matrix<Cell>;
144 
146 
147 void
148 octave_cell::break_closure_cycles (const std::shared_ptr<octave::stack_frame>& frame)
149 {
150  for (octave_idx_type i = 0; i < m_matrix.numel (); i++)
151  m_matrix(i).break_closure_cycles (frame);
152 }
153 
156 {
157  octave_value_list retval;
158 
159  switch (type)
160  {
161  case '(':
162  retval(0) = do_index_op (idx);
163  break;
164 
165  case '{':
166  {
167  if (idx.empty ())
168  error ("invalid empty index expression {}, use {:} instead");
169 
170  octave_value tmp = do_index_op (idx);
171 
172  Cell tcell = tmp.cell_value ();
173 
174  if (tcell.numel () == 1)
175  retval(0) = tcell(0, 0);
176  else
177  {
178  // Return a comma-separated list.
179  retval = octave_value (octave_value_list (tcell));
180  }
181  }
182  break;
183 
184  case '.':
185  {
186  std::string nm = type_name ();
187  error ("%s cannot be indexed with %c", nm.c_str (), type);
188  }
189  break;
190 
191  default:
192  panic_impossible ();
193  }
194 
195  return retval;
196 }
197 
199 octave_cell::subsref (const std::string& type,
200  const std::list<octave_value_list>& idx,
201  int nargout)
202 {
203  octave_value_list retval;
204 
205  switch (type[0])
206  {
207  case '(':
208  retval(0) = do_index_op (idx.front ());
209  break;
210 
211  case '{':
212  {
213  if (idx.front ().empty ())
214  error ("invalid empty index expression {}, use {:} instead");
215 
216  octave_value tmp = do_index_op (idx.front ());
217 
218  Cell tcell = tmp.cell_value ();
219 
220  if (tcell.numel () == 1)
221  retval(0) = tcell(0, 0);
222  else
223  {
224  // Return a comma-separated list.
225  retval = octave_value (octave_value_list (tcell));
226  }
227  }
228  break;
229 
230  case '.':
231  {
232  std::string nm = type_name ();
233  error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
234  }
235  break;
236 
237  default:
238  panic_impossible ();
239  }
240 
241  // FIXME: perhaps there should be an
242  // octave_value_list::next_subsref member function? See also
243  // octave_user_function::subsref.
244 
245  if (idx.size () > 1)
246  retval = retval(0).next_subsref (nargout, type, idx);
247 
248  return retval;
249 }
250 
252 octave_cell::subsref (const std::string& type,
253  const std::list<octave_value_list>& idx,
254  bool auto_add)
255 {
256  octave_value retval;
257 
258  switch (type[0])
259  {
260  case '(':
261  retval = do_index_op (idx.front (), auto_add);
262  break;
263 
264  case '{':
265  {
266  octave_value tmp = do_index_op (idx.front (), auto_add);
267 
268  const Cell tcell = tmp.cell_value ();
269 
270  if (tcell.numel () == 1)
271  retval = tcell(0, 0);
272  else
273  {
274  // Return a comma-separated list.
275  retval = octave_value (octave_value_list (tcell));
276  }
277  }
278  break;
279 
280  case '.':
281  {
282  std::string nm = type_name ();
283  error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
284  }
285  break;
286 
287  default:
288  panic_impossible ();
289  }
290 
291  // FIXME: perhaps there should be an
292  // octave_value_list::next_subsref member function? See also
293  // octave_user_function::subsref.
294 
295  if (idx.size () > 1)
296  retval = retval.next_subsref (auto_add, type, idx);
297 
298  return retval;
299 }
300 
302 octave_cell::subsasgn (const std::string& type,
303  const std::list<octave_value_list>& idx,
304  const octave_value& rhs)
305 {
306  octave_value retval;
307 
308  int n = type.length ();
309 
310  octave_value t_rhs = rhs;
311 
312  clear_cellstr_cache ();
313 
314  if (idx.front ().empty ())
315  error ("missing index in indexed assignment");
316 
317  if (n > 1)
318  {
319  switch (type[0])
320  {
321  case '(':
322  {
323  if (isempty () && type[1] == '.')
324  {
325  // Allow conversion of empty cell array to some other
326  // type in cases like
327  //
328  // x = {}; x(i).f = rhs
329 
330  octave_value tmp = octave_value::empty_conv (type, rhs);
331 
332  return tmp.subsasgn (type, idx, rhs);
333  }
334  else
335  {
336  octave_value tmp = do_index_op (idx.front (), true);
337 
338  if (! tmp.is_defined ())
339  tmp = octave_value::empty_conv (type.substr (1), rhs);
340 
341  std::list<octave_value_list> next_idx (idx);
342 
343  next_idx.erase (next_idx.begin ());
344 
345  tmp.make_unique ();
346 
347  t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs);
348  }
349  }
350  break;
351 
352  case '{':
353  {
355  Cell tmpc = m_matrix.index (idx.front (), true);
356 
357  std::list<octave_value_list> next_idx (idx);
358 
359  next_idx.erase (next_idx.begin ());
360 
361  std::string next_type = type.substr (1);
362 
363  if (tmpc.numel () != 1)
365 
366  octave_value tmp = tmpc(0);
367  tmpc = Cell ();
368 
369  if (! tmp.is_defined () || tmp.is_zero_by_zero ())
370  {
371  tmp = octave_value::empty_conv (type.substr (1), rhs);
372  tmp.make_unique (); // probably a no-op.
373  }
374  else
375  // optimization: ignore copy still stored inside array.
376  tmp.make_unique (1);
377 
378  t_rhs = tmp.subsasgn (next_type, next_idx, rhs);
379  }
380  break;
381 
382  case '.':
383  {
384  if (! isempty ())
385  {
386  std::string nm = type_name ();
387  error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
388  }
389 
390  // Do nothing; the next branch will handle it.
391  }
392  break;
393 
394  default:
395  panic_impossible ();
396  }
397  }
398 
399  switch (type[0])
400  {
401  case '(':
402  {
403  octave_value_list i = idx.front ();
404 
405  if (t_rhs.iscell ())
407  else if (t_rhs.isnull ())
409  else
411 
412  m_count++;
413  retval = octave_value (this);
414  }
415  break;
416 
417  case '{':
418  {
419  octave_value_list idxf = idx.front ();
420 
421  if (t_rhs.is_cs_list ())
422  {
423  Cell tmp_cell = Cell (t_rhs.list_value ());
424 
425  // Inquire the proper shape of the RHS.
426 
427  dim_vector didx = dims ().redim (idxf.length ());
428  for (octave_idx_type k = 0; k < idxf.length (); k++)
429  if (! idxf(k).is_magic_colon ()) didx(k) = idxf(k).numel ();
430 
431  if (didx.numel () == tmp_cell.numel ())
432  tmp_cell = tmp_cell.reshape (didx);
433 
434  octave_base_matrix<Cell>::assign (idxf, tmp_cell);
435  }
436  else if (idxf.all_scalars ()
437  || do_index_op (idxf, true).numel () == 1)
438  // Regularize a null matrix if stored into a cell.
440  Cell (t_rhs.storable_value ()));
441  else
443 
444  m_count++;
445  retval = octave_value (this);
446  }
447  break;
448 
449  case '.':
450  {
451  if (! isempty ())
452  {
453  std::string nm = type_name ();
454  error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
455  }
456 
457  // Allow conversion of empty cell array to some other
458  // type in cases like
459  //
460  // x = {}; x.f = rhs
461 
462  octave_value tmp = octave_value::empty_conv (type, rhs);
463 
464  return tmp.subsasgn (type, idx, rhs);
465  }
466  break;
467 
468  default:
469  panic_impossible ();
470  }
471 
472  return retval;
473 }
474 
475 bool
477 {
478  bool retval;
479  if (m_cellstr_cache.get ())
480  retval = true;
481  else
482  {
483  retval = m_matrix.iscellstr ();
484  // Allocate empty cache to mark that this is indeed a cellstr.
485  if (retval)
486  m_cellstr_cache.reset (new Array<std::string> ());
487  }
488 
489  return retval;
490 }
491 
492 void
494 {
495  clear_cellstr_cache ();
497 }
498 
499 void
501 {
502  clear_cellstr_cache ();
504 }
505 
506 void
508 {
509  clear_cellstr_cache ();
511 }
512 
513 std::size_t
515 {
516  std::size_t retval = 0;
517 
518  for (octave_idx_type i = 0; i < numel (); i++)
519  retval += m_matrix(i).byte_size ();
520 
521  return retval;
522 }
523 
526 {
527  octave_value retval;
528 
529  if (! iscellstr ())
530  error ("sort: only cell arrays of character strings may be sorted");
531 
533 
534  tmp = tmp.sort (dim, mode);
535 
536  // We already have the cache.
537  retval = new octave_cell (tmp);
538 
539  return retval;
540 }
541 
544  sortmode mode) const
545 {
546  octave_value retval;
547 
548  if (! iscellstr ())
549  error ("sort: only cell arrays of character strings may be sorted");
550 
552 
553  tmp = tmp.sort (sidx, dim, mode);
554 
555  // We already have the cache.
556  retval = new octave_cell (tmp);
557 
558  return retval;
559 }
560 
561 sortmode
563 {
564  sortmode retval = UNSORTED;
565 
566  if (! iscellstr ())
567  error ("issorted: A is not a cell array of strings");
568 
570 
571  retval = tmp.issorted (mode);
572 
573  return retval;
574 }
575 
578 {
579  Array<octave_idx_type> retval;
580 
581  if (! iscellstr ())
582  error ("sortrows: only cell arrays of character strings may be sorted");
583 
585 
586  retval = tmp.sort_rows_idx (mode);
587 
588  return retval;
589 }
590 
591 sortmode
593 {
594  sortmode retval = UNSORTED;
595 
596  if (! iscellstr ())
597  error ("issorted: A is not a cell array of strings");
598 
600 
601  retval = tmp.is_sorted_rows (mode);
602 
603  return retval;
604 }
605 
606 bool
608 {
609  error ("invalid conversion from cell array to logical value");
610 }
611 
614 {
615  return octave_value_list (m_matrix);
616 }
617 
620 {
621  string_vector retval;
622 
623  octave_idx_type nel = numel ();
624 
625  int n_elts = 0;
626 
627  octave_idx_type max_len = 0;
628 
629  std::queue<string_vector> strvec_queue;
630 
631  for (octave_idx_type i = 0; i < nel; i++)
632  {
634 
635  octave_idx_type s_len = s.numel ();
636 
637  n_elts += s_len ? s_len : 1;
638 
639  octave_idx_type s_max_len = s.max_length ();
640 
641  if (s_max_len > max_len)
642  max_len = s_max_len;
643 
644  strvec_queue.push (s);
645  }
646 
647  retval = string_vector (n_elts);
648 
649  octave_idx_type k = 0;
650 
651  for (octave_idx_type i = 0; i < nel; i++)
652  {
653  const string_vector s = strvec_queue.front ();
654  strvec_queue.pop ();
655 
656  octave_idx_type s_len = s.numel ();
657 
658  if (s_len)
659  {
660  for (octave_idx_type j = 0; j < s_len; j++)
661  {
662  std::string t = s[j];
663  int t_len = t.length ();
664 
665  if (pad && max_len > t_len)
666  t += std::string (max_len - t_len, ' ');
667 
668  retval[k++] = t;
669  }
670  }
671  else if (pad)
672  retval[k++] = std::string (max_len, ' ');
673  else
674  retval[k++] = "";
675  }
676 
677  return retval;
678 }
679 
682 {
683  if (! iscellstr ())
684  error ("invalid conversion from cell array to array of strings");
685 
686  if (m_cellstr_cache->isempty ())
687  *m_cellstr_cache = m_matrix.cellstr_value ();
688 
689  return *m_cellstr_cache;
690 }
691 
692 bool
694 {
695  return true;
696 }
697 
698 void
699 octave_cell::print (std::ostream& os, bool)
700 {
701  print_raw (os);
702 }
703 
704 void
705 octave_cell::print_raw (std::ostream& os, bool) const
706 {
707  int nd = m_matrix.ndims ();
708 
709  if (nd == 2)
710  {
711  octave_idx_type nr = rows ();
712  octave_idx_type nc = columns ();
713 
714  if (nr > 0 && nc > 0)
715  {
716  indent (os);
717  os << '{';
718  newline (os);
719 
721 
722  for (octave_idx_type j = 0; j < nc; j++)
723  {
724  for (octave_idx_type i = 0; i < nr; i++)
725  {
726  octave_quit ();
727 
728  std::ostringstream buf;
729  buf << '[' << i+1 << ',' << j+1 << ']';
730 
731  octave_value val = m_matrix(i, j);
732 
733  val.print_with_name (os, buf.str ());
734  }
735  }
736 
738 
739  indent (os);
740  os << '}';
741  newline (os);
742  }
743  else
744  {
745  indent (os);
746  os << "{}";
748  os << '(' << nr << 'x' << nc << ')';
749  newline (os);
750  }
751  }
752  else
753  {
754  indent (os);
755  dim_vector dv = m_matrix.dims ();
756  os << '{' << dv.str () << " Cell Array}";
757  newline (os);
758  }
759 }
760 
761 bool
762 octave_cell::print_name_tag (std::ostream& os, const std::string& name) const
763 {
764  bool retval = false;
765 
766  indent (os);
767 
768  if (isempty () || ndims () > 2)
769  os << name << " = ";
770  else
771  {
772  os << name << " =";
773  newline (os);
774  retval = true;
775  }
776 
777  return retval;
778 }
779 
780 void
781 octave_cell::short_disp (std::ostream& os) const
782 {
783  os << (m_matrix.isempty () ? "{}" : "...");
784 }
785 
786 #define CELL_ELT_TAG "<cell-element>"
787 
788 bool
789 octave_cell::save_ascii (std::ostream& os)
790 {
791  dim_vector dv = dims ();
792  if (dv.ndims () > 2)
793  {
794  os << "# ndims: " << dv.ndims () << "\n";
795 
796  for (int i = 0; i < dv.ndims (); i++)
797  os << ' ' << dv(i);
798  os << "\n";
799 
800  Cell tmp = cell_value ();
801 
802  for (octave_idx_type i = 0; i < dv.numel (); i++)
803  {
804  octave_value o_val = tmp.elem (i);
805 
806  // Recurse to save sub-value.
807  bool b = save_text_data (os, o_val, CELL_ELT_TAG, false, 0);
808 
809  if (! b)
810  return ! os.fail ();
811  }
812  }
813  else
814  {
815  // Keep this case, rather than use generic code above for backward
816  // compatibility. Makes load_ascii much more complex!!
817  os << "# rows: " << rows () << "\n"
818  << "# columns: " << columns () << "\n";
819 
820  Cell tmp = cell_value ();
821 
822  for (octave_idx_type j = 0; j < tmp.cols (); j++)
823  {
824  for (octave_idx_type i = 0; i < tmp.rows (); i++)
825  {
826  octave_value o_val = tmp.elem (i, j);
827 
828  // Recurse to save sub-value.
829  bool b = save_text_data (os, o_val, CELL_ELT_TAG, false, 0);
830 
831  if (! b)
832  return ! os.fail ();
833  }
834 
835  os << "\n";
836  }
837  }
838 
839  return true;
840 }
841 
842 bool
843 octave_cell::load_ascii (std::istream& is)
844 {
845  clear_cellstr_cache ();
846 
847  string_vector keywords(2);
848 
849  keywords[0] = "ndims";
850  keywords[1] = "rows";
851 
852  std::string kw;
853  octave_idx_type val = 0;
854 
855  if (! extract_keyword (is, keywords, kw, val, true))
856  error ("load: failed to extract number of rows and columns");
857 
858  if (kw == "ndims")
859  {
860  int mdims = static_cast<int> (val);
861 
862  if (mdims < 0)
863  error ("load: failed to extract number of rows and columns");
864 
865  dim_vector dv;
866  dv.resize (mdims);
867 
868  for (int i = 0; i < mdims; i++)
869  is >> dv(i);
870 
871  Cell tmp(dv);
872 
873  for (octave_idx_type i = 0; i < dv.numel (); i++)
874  {
875  octave_value t2;
876  bool dummy;
877 
878  // recurse to read cell elements
879  std::string nm = read_text_data (is, "",
880  dummy, t2, i);
881 
882  if (nm != CELL_ELT_TAG)
883  error ("load: cell array element had unexpected name");
884 
885  if (is)
886  tmp.elem (i) = t2;
887  }
888 
889  if (! is)
890  error ("load: failed to load matrix constant");
891 
892  m_matrix = tmp;
893  }
894  else if (kw == "rows")
895  {
896  octave_idx_type nr = val;
897  octave_idx_type nc = 0;
898 
899  if (nr < 0 || ! extract_keyword (is, "columns", nc) || nc < 0)
900  error ("load: failed to extract number of rows and columns for cell array");
901 
902  if (nr > 0 && nc > 0)
903  {
904  Cell tmp (nr, nc);
905 
906  for (octave_idx_type j = 0; j < nc; j++)
907  {
908  for (octave_idx_type i = 0; i < nr; i++)
909  {
910  octave_value t2;
911  bool dummy;
912 
913  // recurse to read cell elements
914  std::string nm = read_text_data (is, "",
915  dummy, t2, i);
916 
917  if (nm != CELL_ELT_TAG)
918  error ("load: cell array element had unexpected name");
919 
920  if (is)
921  tmp.elem (i, j) = t2;
922  }
923  }
924 
925  if (! is)
926  error ("load: failed to load cell element");
927 
928  m_matrix = tmp;
929  }
930  else if (nr == 0 || nc == 0)
931  m_matrix = Cell (nr, nc);
932  else
933  panic_impossible ();
934  }
935  else
936  panic_impossible ();
937 
938  return true;
939 }
940 
941 bool
942 octave_cell::save_binary (std::ostream& os, bool save_as_floats)
943 {
944  dim_vector dv = dims ();
945  if (dv.ndims () < 1)
946  return false;
947 
948  // Use negative value for ndims
949  int32_t di = - dv.ndims ();
950  os.write (reinterpret_cast<char *> (&di), 4);
951  for (int i = 0; i < dv.ndims (); i++)
952  {
953  di = dv(i);
954  os.write (reinterpret_cast<char *> (&di), 4);
955  }
956 
957  Cell tmp = cell_value ();
958 
959  for (octave_idx_type i = 0; i < dv.numel (); i++)
960  {
961  octave_value o_val = tmp.elem (i);
962 
963  // Recurse to save sub-value.
964  bool b = save_binary_data (os, o_val, CELL_ELT_TAG, "", 0,
965  save_as_floats);
966 
967  if (! b)
968  return false;
969  }
970 
971  return true;
972 }
973 
974 bool
975 octave_cell::load_binary (std::istream& is, bool swap,
977 {
978  clear_cellstr_cache ();
979 
980  int32_t mdims;
981  if (! is.read (reinterpret_cast<char *> (&mdims), 4))
982  return false;
983  if (swap)
984  swap_bytes<4> (&mdims);
985  if (mdims >= 0)
986  return false;
987 
988  mdims = -mdims;
989  int32_t di;
990  dim_vector dv;
991  dv.resize (mdims);
992 
993  for (int i = 0; i < mdims; i++)
994  {
995  if (! is.read (reinterpret_cast<char *> (&di), 4))
996  return false;
997  if (swap)
998  swap_bytes<4> (&di);
999  dv(i) = di;
1000  }
1001 
1002  // Convert an array with a single dimension to be a row vector.
1003  // Octave should never write files like this, other software
1004  // might.
1005 
1006  if (mdims == 1)
1007  {
1008  mdims = 2;
1009  dv.resize (mdims);
1010  dv(1) = dv(0);
1011  dv(0) = 1;
1012  }
1013 
1014  octave_idx_type nel = dv.numel ();
1015  Cell tmp(dv);
1016 
1017  for (octave_idx_type i = 0; i < nel; i++)
1018  {
1019  octave_value t2;
1020  bool dummy;
1021  std::string doc;
1022 
1023  // recurse to read cell elements
1024  std::string nm = read_binary_data (is, swap, fmt, "",
1025  dummy, t2, doc);
1026 
1027  if (nm != CELL_ELT_TAG)
1028  error ("load: cell array element had unexpected name");
1029 
1030  if (is)
1031  tmp.elem (i) = t2;
1032  }
1033 
1034  if (! is)
1035  error ("load: failed to load matrix constant");
1036 
1037  m_matrix = tmp;
1038 
1039  return true;
1040 }
1041 
1042 const void *
1044 {
1045  clear_cellstr_cache ();
1046  return m_matrix.data ();
1047 }
1048 
1049 bool
1050 octave_cell::save_hdf5 (octave_hdf5_id loc_id, const char *name,
1051  bool save_as_floats)
1052 {
1053 #if defined (HAVE_HDF5)
1054 
1055  dim_vector dv = dims ();
1056  int empty = save_hdf5_empty (loc_id, name, dv);
1057  if (empty)
1058  return (empty > 0);
1059 
1060  hsize_t rank = dv.ndims ();
1061  hid_t space_hid, data_hid, size_hid;
1062  space_hid = data_hid = size_hid = -1;
1063 
1064 #if defined (HAVE_HDF5_18)
1065  data_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT, octave_H5P_DEFAULT,
1067 #else
1068  data_hid = H5Gcreate (loc_id, name, 0);
1069 #endif
1070 
1071  if (data_hid < 0)
1072  return false;
1073 
1074  // Have to save cell array shape, since can't have a
1075  // dataset of groups....
1076 
1077  space_hid = H5Screate_simple (1, &rank, nullptr);
1078 
1079  if (space_hid < 0)
1080  {
1081  H5Gclose (data_hid);
1082  return false;
1083  }
1084 
1085  OCTAVE_LOCAL_BUFFER (octave_idx_type, hdims, rank);
1086 
1087  // Octave uses column-major, while HDF5 uses row-major ordering
1088  for (hsize_t i = 0; i < rank; i++)
1089  hdims[i] = dv(rank-i-1);
1090 
1091 #if defined (HAVE_HDF5_18)
1092  size_hid = H5Dcreate (data_hid, "dims", H5T_NATIVE_IDX, space_hid,
1095 #else
1096  size_hid = H5Dcreate (data_hid, "dims", H5T_NATIVE_IDX, space_hid,
1098 #endif
1099  if (size_hid < 0)
1100  {
1101  H5Sclose (space_hid);
1102  H5Gclose (data_hid);
1103  return false;
1104  }
1105 
1106  if (H5Dwrite (size_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
1107  octave_H5P_DEFAULT, hdims) < 0)
1108  {
1109  H5Dclose (size_hid);
1110  H5Sclose (space_hid);
1111  H5Gclose (data_hid);
1112  return false;
1113  }
1114 
1115  H5Dclose (size_hid);
1116  H5Sclose (space_hid);
1117 
1118  // Recursively add each element of the cell to this group.
1119 
1120  Cell tmp = cell_value ();
1121 
1122  octave_idx_type nel = dv.numel ();
1123 
1124  for (octave_idx_type i = 0; i < nel; i++)
1125  {
1126  std::ostringstream buf;
1127  int digits = static_cast<int> (std::floor (::log10 (static_cast<double>
1128  (nel)) + 1.0));
1129  buf << '_' << std::setw (digits) << std::setfill ('0') << i;
1130  std::string s = buf.str ();
1131 
1132  if (! add_hdf5_data (data_hid, tmp.elem (i), s.c_str (), "", false,
1133  save_as_floats))
1134  {
1135  H5Gclose (data_hid);
1136  return false;
1137  }
1138  }
1139 
1140  H5Gclose (data_hid);
1141 
1142  return true;
1143 
1144 #else
1145  octave_unused_parameter (loc_id);
1146  octave_unused_parameter (name);
1147  octave_unused_parameter (save_as_floats);
1148 
1149  warn_save ("hdf5");
1150 
1151  return false;
1152 #endif
1153 }
1154 
1155 bool
1156 octave_cell::load_hdf5 (octave_hdf5_id loc_id, const char *name)
1157 {
1158  bool retval = false;
1159 
1160 #if defined (HAVE_HDF5)
1161 
1162  clear_cellstr_cache ();
1163 
1164  dim_vector dv;
1165  int empty = load_hdf5_empty (loc_id, name, dv);
1166  if (empty > 0)
1167  m_matrix.resize (dv);
1168  if (empty)
1169  return (empty > 0);
1170 
1171 #if defined (HAVE_HDF5_18)
1172  hid_t group_id = H5Gopen (loc_id, name, octave_H5P_DEFAULT);
1173 #else
1174  hid_t group_id = H5Gopen (loc_id, name);
1175 #endif
1176 
1177  if (group_id < 0)
1178  return false;
1179 
1180 #if defined (HAVE_HDF5_18)
1181  hid_t data_hid = H5Dopen (group_id, "dims", octave_H5P_DEFAULT);
1182 #else
1183  hid_t data_hid = H5Dopen (group_id, "dims");
1184 #endif
1185  hid_t space_hid = H5Dget_space (data_hid);
1186  hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
1187  if (rank != 1)
1188  {
1189  H5Dclose (data_hid);
1190  H5Gclose (group_id);
1191  return false;
1192  }
1193 
1194  OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
1195  OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
1196 
1197  H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
1198 
1199  // Octave uses column-major, while HDF5 uses row-major ordering.
1200 
1201  dv.resize (hdims[0]);
1202 
1203  OCTAVE_LOCAL_BUFFER (octave_idx_type, tmp, hdims[0]);
1204 
1205  if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
1206  octave_H5P_DEFAULT, tmp) < 0)
1207  {
1208  H5Dclose (data_hid);
1209  H5Gclose (group_id);
1210  return false;
1211  }
1212 
1213  H5Dclose (data_hid);
1214  H5Gclose (group_id);
1215 
1216  for (hsize_t i = 0, j = hdims[0] - 1; i < hdims[0]; i++, j--)
1217  dv(j) = tmp[i];
1218 
1219  hdf5_callback_data dsub;
1220 
1221  herr_t retval2 = -1;
1222 
1223  Cell m (dv);
1224 
1225  int current_item = 0;
1226 
1227  hsize_t num_obj = 0;
1228 #if defined (HAVE_HDF5_18)
1229  group_id = H5Gopen (loc_id, name, octave_H5P_DEFAULT);
1230 #else
1231  group_id = H5Gopen (loc_id, name);
1232 #endif
1233  H5Gget_num_objs (group_id, &num_obj);
1234  H5Gclose (group_id);
1235 
1236  for (octave_idx_type i = 0; i < dv.numel (); i++)
1237  {
1238 
1239  if (current_item >= static_cast<int> (num_obj))
1240  retval2 = -1;
1241  else
1242  retval2 = hdf5_h5g_iterate (loc_id, name, &current_item, &dsub);
1243 
1244  if (retval2 <= 0)
1245  break;
1246 
1247  octave_value ov = dsub.tc;
1248  m.elem (i) = ov;
1249 
1250  }
1251 
1252  if (retval2 >= 0)
1253  {
1254  m_matrix = m;
1255  retval = true;
1256  }
1257 
1258 #else
1259  octave_unused_parameter (loc_id);
1260  octave_unused_parameter (name);
1261 
1262  warn_load ("hdf5");
1263 #endif
1264 
1265  return retval;
1266 }
1267 
1269 
1270 DEFUN (iscell, args, ,
1271  doc: /* -*- texinfo -*-
1272 @deftypefn {} {@var{tf} =} iscell (@var{x})
1273 Return true if @var{x} is a cell array object.
1274 @seealso{ismatrix, isstruct, iscellstr, isa}
1275 @end deftypefn */)
1276 {
1277  if (args.length () != 1)
1278  print_usage ();
1279 
1280  return ovl (args(0).iscell ());
1281 }
1282 
1283 DEFUN (cell, args, ,
1284  doc: /* -*- texinfo -*-
1285 @deftypefn {} {@var{C} =} cell (@var{n})
1286 @deftypefnx {} {@var{C} =} cell (@var{m}, @var{n})
1287 @deftypefnx {} {@var{C} =} cell (@var{m}, @var{n}, @var{k}, @dots{})
1288 @deftypefnx {} {@var{C} =} cell ([@var{m} @var{n} @dots{}])
1289 Create a new cell array object.
1290 
1291 If invoked with a single scalar integer argument, return a square
1292 @nospell{NxN} cell array. If invoked with two or more scalar integer
1293 arguments, or a vector of integer values, return an array with the given
1294 dimensions.
1295 @seealso{cellstr, mat2cell, num2cell, struct2cell}
1296 @end deftypefn */)
1297 {
1298  int nargin = args.length ();
1299 
1300  dim_vector dims;
1301 
1302  switch (nargin)
1303  {
1304  case 0:
1305  dims = dim_vector (0, 0);
1306  break;
1307 
1308  case 1:
1309  if (args(0).iscell ())
1310  return args(0); // shortcut path for input which is already a Cell
1311  else
1312  get_dimensions (args(0), "cell", dims);
1313  break;
1314 
1315  default:
1316  {
1317  dims.resize (nargin);
1318 
1319  for (int i = 0; i < nargin; i++)
1320  dims(i) = (args(i).isempty ()
1321  ? 0 : args(i).xidx_type_value ("cell: dimension must be a scalar integer"));
1322  }
1323  break;
1324  }
1325 
1326  dims.chop_trailing_singletons ();
1327 
1328  check_dimensions (dims, "cell");
1329 
1330  return ovl (Cell (dims));
1331 }
1332 
1333 /*
1334 ## Note: Matlab compatibility requires using 0 for negative dimensions.
1335 %!assert (size (cell (2, -3)), [2, 0])
1336 
1337 %!test <*63132>
1338 %! x = {1, 3};
1339 %! y = cell (x);
1340 %! assert (x, y);
1341 %! x = cell (0, 3);
1342 %! y = cell (x);
1343 %! assert (x, y);
1344 
1345 ## This might work on some system someday, but for now, who has a system
1346 ## where a 16 yottabyte array can be allocated? See bug #50934.
1347 %!error <out of memory> cell (1e24, 1)
1348 */
1349 
1350 DEFUN (iscellstr, args, ,
1351  doc: /* -*- texinfo -*-
1352 @deftypefn {} {@var{tf} =} iscellstr (@var{cell})
1353 Return true if every element of the cell array @var{cell} is a character
1354 string.
1355 @seealso{ischar, isstring}
1356 @end deftypefn */)
1357 {
1358  if (args.length () != 1)
1359  print_usage ();
1360 
1361  return ovl (args(0).iscellstr ());
1362 }
1363 
1364 DEFUN (cellstr, args, ,
1365  doc: /* -*- texinfo -*-
1366 @deftypefn {} {@var{cstr} =} cellstr (@var{strmat})
1367 Create a new cell array object from the elements of the string array
1368 @var{strmat}.
1369 
1370 Each row of @var{strmat} becomes an element of @var{cstr}. Any trailing
1371 spaces in a row are deleted before conversion.
1372 
1373 To convert back from a cellstr to a character array use @code{char}.
1374 @seealso{cell, char}
1375 @end deftypefn */)
1376 {
1377  if (args.length () != 1)
1378  print_usage ();
1379 
1380  octave_value_list tmp = Fiscellstr (args, 1);
1381 
1382  if (tmp(0).is_true ())
1383  return ovl (args(0));
1384  else
1385  {
1386  string_vector s = args(0).xstring_vector_value ("cellstr: argument STRING must be a 2-D character array");
1387 
1388  return ovl (s.isempty () ? Cell (octave_value (""))
1389  : Cell (s, true));
1390  }
1391 }
1392 
1393 DEFUN (struct2cell, args, ,
1394  doc: /* -*- texinfo -*-
1395 @deftypefn {} {@var{c} =} struct2cell (@var{s})
1396 Create a new cell array from the objects stored in the struct object.
1397 
1398 If @var{f} is the number of fields in the structure, the resulting cell
1399 array will have a dimension vector corresponding to
1400 @code{[@var{f} size(@var{s})]}. For example:
1401 
1402 @example
1403 @group
1404 s = struct ("name", @{"Peter", "Hannah", "Robert"@},
1405  "age", @{23, 16, 3@});
1406 c = struct2cell (s)
1407  @result{} c = @{2x1x3 Cell Array@}
1408 c(1,1,:)(:)
1409  @result{}
1410  @{
1411  [1,1] = Peter
1412  [2,1] = Hannah
1413  [3,1] = Robert
1414  @}
1415 c(2,1,:)(:)
1416  @result{}
1417  @{
1418  [1,1] = 23
1419  [2,1] = 16
1420  [3,1] = 3
1421  @}
1422 @end group
1423 @end example
1424 
1425 @seealso{cell2struct, namedargs2cell, fieldnames}
1426 @end deftypefn */)
1427 {
1428  if (args.length () != 1)
1429  print_usage ();
1430 
1431  const octave_map m = args(0).xmap_value ("struct2cell: argument S must be a structure");
1432 
1433  const dim_vector m_dv = m.dims ();
1434 
1435  octave_idx_type num_fields = m.nfields ();
1436 
1437  // The resulting dim_vector should have dimensions:
1438  // [numel(fields) size(struct)]
1439  // except if the struct is a column vector.
1440 
1441  dim_vector result_dv;
1442  if (m_dv(m_dv.ndims () - 1) == 1)
1443  result_dv.resize (m_dv.ndims ());
1444  else
1445  result_dv.resize (m_dv.ndims () + 1); // Add 1 for the fields.
1446 
1447  result_dv(0) = num_fields;
1448 
1449  for (int i = 1; i < result_dv.ndims (); i++)
1450  result_dv(i) = m_dv(i-1);
1451 
1452  Cell c (result_dv);
1453 
1454  octave_idx_type n_elts = m.numel ();
1455 
1456  // Fill c in one sweep. Note that thanks to octave_map structure,
1457  // we don't need a key lookup at all.
1458  for (octave_idx_type j = 0; j < n_elts; j++)
1459  for (octave_idx_type i = 0; i < num_fields; i++)
1460  c.xelem (i, j) = m.contents(i)(j);
1461 
1462  return ovl (c);
1463 }
1464 
1465 /*
1466 %!test
1467 %! keys = cellstr (char (floor (rand (11,10)*24+65)))';
1468 %! vals = cellfun (@(x) mat2cell (rand (19,1), ones (19,1), 1), ...
1469 %! mat2cell ([1:11]', ones (11,1), 1), "uniformoutput", false)';
1470 %! s = struct ([keys; vals]{:});
1471 %! t = cell2struct ([vals{:}], keys, 2);
1472 %! assert (s, t);
1473 %! assert (struct2cell (s), [vals{:}]');
1474 %! assert (fieldnames (s), keys');
1475 */
1476 
1477 OCTAVE_END_NAMESPACE(octave)
1478 
1479 mxArray *
1480 octave_cell::as_mxArray (bool interleaved) const
1481 {
1482  mxArray *retval = new mxArray (interleaved, dims ());
1483 
1484  mxArray **elts = static_cast<mxArray **> (retval->get_data ());
1485 
1486  mwSize nel = numel ();
1487 
1488  const octave_value *p = m_matrix.data ();
1489 
1490  for (mwIndex i = 0; i < nel; i++)
1491  elts[i] = new mxArray (interleaved, p[i]);
1492 
1493  return retval;
1494 }
1495 
1498 {
1499  switch (umap)
1500  {
1501 #define FORWARD_MAPPER(UMAP) \
1502  case umap_ ## UMAP: \
1503  return m_matrix.UMAP ()
1504 
1505  FORWARD_MAPPER (xisalnum);
1506  FORWARD_MAPPER (xisalpha);
1507  FORWARD_MAPPER (xisascii);
1508  FORWARD_MAPPER (xiscntrl);
1509  FORWARD_MAPPER (xisdigit);
1510  FORWARD_MAPPER (xisgraph);
1511  FORWARD_MAPPER (xislower);
1512  FORWARD_MAPPER (xisprint);
1513  FORWARD_MAPPER (xispunct);
1514  FORWARD_MAPPER (xisspace);
1515  FORWARD_MAPPER (xisupper);
1516  FORWARD_MAPPER (xisxdigit);
1517  FORWARD_MAPPER (xtolower);
1518  FORWARD_MAPPER (xtoupper);
1519 
1520  default:
1521  return octave_base_value::map (umap);
1522  }
1523 }
void swap_bytes< 4 >(void *ptr)
Definition: byte-swap.h:63
T & elem(octave_idx_type n)
Size of the specified dimension.
Definition: Array.h:562
std::size_t byte_size() const
Size of the specified dimension.
Definition: Array.h:499
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
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Sort by rows returns only indices.
Definition: Array-base.cc:2079
octave_idx_type cols() const
Definition: Array.h:469
void make_unique()
Definition: Array.h:216
Array< T, Alloc > sort(int dim=0, sortmode mode=ASCENDING) const
Size of the specified dimension.
Definition: Array-base.cc:1781
bool isempty() const
Size of the specified dimension.
Definition: Array.h:651
sortmode issorted(sortmode mode=UNSORTED) const
Ordering is auto-detected or can be specified.
Definition: Array-base.cc:2047
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
Definition: Array.h:503
T & xelem(octave_idx_type n)
Size of the specified dimension.
Definition: Array.h:524
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Ordering is auto-detected or can be specified.
Definition: Array-base.cc:2097
octave_idx_type numel() const
Number of elements in the array.
Definition: Array.h:414
Definition: Cell.h:43
Cell reshape(const dim_vector &new_dims) const
Definition: Cell.h:119
Cell index(const octave_value_list &idx, bool resize_ok=false) const
Definition: Cell.cc:171
Array< std::string > cellstr_value() const
Definition: Cell.cc:145
string_vector string_vector_value() const
Definition: Cell.cc:158
bool iscellstr() const
Definition: Cell.cc:126
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
std::string str(char sep='x') const
Definition: dim-vector.cc:68
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 chop_trailing_singletons()
Definition: dim-vector.h:164
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
dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
Definition: dim-vector.cc:226
void * get_data() const
Definition: mxarray.h:473
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-base.cc:248
bool fast_elem_insert(octave_idx_type n, const octave_value &x)
Definition: ov-base-mat.cc:577
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov-base-mat.cc:156
virtual void assign(const std::string &, const octave_value &)
Definition: ov-base.h:354
void delete_elements(const octave_value_list &idx)
Definition: ov-base-mat.cc:416
octave_value fast_elem_extract(octave_idx_type n) const
Definition: ov-base-mat.cc:567
octave_idx_type numel() const
Definition: ov-base-mat.h:122
dim_vector dims() const
Definition: ov-base-mat.h:120
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
Definition: ov-base-mat.cc:556
octave_idx_type rows() const
Definition: ov-base.h:374
octave_idx_type columns() const
Definition: ov-base.h:381
void increment_indent_level() const
Definition: ov-base.h:914
void indent(std::ostream &os) const
Definition: ov-base.cc:1369
void newline(std::ostream &os) const
Definition: ov-base.cc:1388
virtual octave_value map(unary_mapper_t) const
Definition: ov-base.cc:1181
octave::refcount< octave_idx_type > m_count
Definition: ov-base.h:933
void warn_load(const char *type) const
Definition: ov-base.cc:1157
virtual bool is_magic_colon() const
Definition: ov-base.h:465
void decrement_indent_level() const
Definition: ov-base.h:917
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
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
Definition: ov-cell.cc:302
void short_disp(std::ostream &os) const
Definition: ov-cell.cc:781
bool is_true() const
Definition: ov-cell.cc:607
octave_value map(unary_mapper_t umap) const
Definition: ov-cell.cc:1497
std::size_t byte_size() const
Definition: ov-cell.cc:514
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Definition: ov-cell.cc:592
void print(std::ostream &os, bool pr_as_read_syntax=false)
Definition: ov-cell.cc:699
bool print_as_scalar() const
Definition: ov-cell.cc:693
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-cell.cc:525
const void * mex_get_data() const
Definition: ov-cell.cc:1043
Array< std::string > cellstr_value() const
Definition: ov-cell.cc:681
bool save_binary(std::ostream &os, bool save_as_floats)
Definition: ov-cell.cc:942
bool print_name_tag(std::ostream &os, const std::string &name) const
Definition: ov-cell.cc:762
virtual void assign(const std::string &, const octave_value &)
Definition: ov-base.h:354
bool save_ascii(std::ostream &os)
Definition: ov-cell.cc:789
std::string type_name() const
Definition: ov-cell.h:193
Cell cell_value() const
Definition: ov-cell.h:137
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
Definition: ov-cell.cc:1156
octave_value_list simple_subsref(char type, octave_value_list &idx, int nargout)
Definition: ov-cell.cc:155
void break_closure_cycles(const std::shared_ptr< octave::stack_frame > &frame)
Definition: ov-cell.cc:148
void delete_elements(const octave_value_list &idx)
Definition: ov-cell.cc:507
bool load_ascii(std::istream &is)
Definition: ov-cell.cc:843
string_vector string_vector_value(bool pad=false) const
Definition: ov-cell.cc:619
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition: ov-cell.cc:577
bool iscellstr() const
Definition: ov-cell.cc:476
sortmode issorted(sortmode mode=UNSORTED) const
Definition: ov-cell.cc:562
mxArray * as_mxArray(bool interleaved) const
Definition: ov-cell.cc:1480
octave_value_list list_value() const
Definition: ov-cell.cc:613
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
Definition: ov-cell.cc:705
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
Definition: ov-cell.cc:1050
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
Definition: ov-cell.cc:975
octave_cell()
Definition: ov-cell.h:54
bool all_scalars() const
Definition: ovl.cc:188
bool empty() const
Definition: ovl.h:115
octave_idx_type length() const
Definition: ovl.h:113
octave_value_list list_value() const
Cell cell_value() const
void print_with_name(std::ostream &os, const std::string &name) const
Definition: ov.h:1330
void make_unique()
Definition: ov.h:352
static octave_value empty_conv(const std::string &type, const octave_value &rhs=octave_value())
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, std::size_t skip=1)
bool is_defined() const
Definition: ov.h:592
octave_value storable_value() const
bool is_zero_by_zero() const
Definition: ov.h:556
bool iscell() const
Definition: ov.h:604
bool isnull() const
Definition: ov.h:679
bool is_cs_list() const
Definition: ov.h:670
std::string type_name() const
Definition: ov.h:1345
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
dim_vector dims() const
Definition: ov.h:541
octave_idx_type max_length() const
Definition: str-vec.h:79
bool isempty() const
Definition: str-vec.h:102
octave_idx_type numel() const
Definition: str-vec.h:100
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void print_usage(void)
Definition: defun-int.h:72
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:56
void() error(const char *fmt,...)
Definition: error.cc:988
#define panic_impossible()
Definition: error.h:503
void err_indexed_cs_list()
Definition: errwarn.cc:65
void err_nonbraced_cs_list_assignment()
Definition: errwarn.cc:89
std::complex< T > floor(const std::complex< T > &x)
Definition: lo-mappers.h:130
F77_RET_T const F77_DBLE * x
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_err hdf5_h5g_iterate(octave_hdf5_id loc_id, const char *name, int *idx, void *operator_data)
Definition: ls-hdf5.cc:1059
bool add_hdf5_data(octave_hdf5_id loc_id, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
Definition: ls-hdf5.cc:1406
std::string read_binary_data(std::istream &is, bool swap, octave::mach_info::float_format fmt, const std::string &filename, bool &global, octave_value &tc, std::string &doc)
bool save_binary_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
std::string read_text_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, octave_idx_type count, const bool do_name_validation)
Definition: ls-oct-text.cc:286
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
Definition: ls-oct-text.cc:84
bool save_text_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_global, int precision)
Definition: ls-oct-text.cc:361
float_format
Definition: mach-info.h:38
void mxArray
Definition: mex.h:58
bool is_true(const std::string &s)
Definition: mkoctfile.cc:604
T octave_idx_type m
Definition: mx-inlines.cc:781
octave_idx_type n
Definition: mx-inlines.cc:761
int64_t mwIndex
Definition: mxtypes.h:125
int64_t mwSize
Definition: mxtypes.h:124
void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
Definition: utils.cc:1348
int64_t octave_hdf5_id
#define H5T_NATIVE_IDX
Definition: oct-hdf5.h:42
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition: oct-locbuf.h:44
sortmode
Definition: oct-sort.h:97
@ UNSORTED
Definition: oct-sort.h:97
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:235
octave_value_list Fiscellstr(const octave_value_list &args, int)
Definition: ov-cell.cc:1356
#define CELL_ELT_TAG
Definition: ov-cell.cc:786
#define FORWARD_MAPPER(UMAP)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:219
bool Vprint_empty_dimensions
Definition: pr-output.cc:71
octave_value tc
Definition: ls-hdf5.h:121
void check_dimensions(dim_vector &dim, const char *warnfor)