GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-cx-sparse.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2004-2017 David Bateman
4 Copyright (C) 1998-2004 Andy Adler
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if defined (HAVE_CONFIG_H)
25 # include "config.h"
26 #endif
27 
28 #include <iostream>
29 #include <limits>
30 #include <vector>
31 
32 #include "lo-specfun.h"
33 #include "lo-mappers.h"
34 #include "oct-locbuf.h"
35 
36 #include "mxarray.h"
37 #include "ov-base.h"
38 #include "ov-scalar.h"
39 #include "ov-complex.h"
40 #include "errwarn.h"
41 
42 #include "oct-hdf5.h"
43 
44 #include "ov-re-sparse.h"
45 #include "ov-cx-sparse.h"
46 
47 #include "ov-base-sparse.h"
48 #include "ov-base-sparse.cc"
49 
50 #include "ov-bool-sparse.h"
51 
52 
54 
56  "sparse complex matrix", "double");
57 
60 {
62 
64  {
65  int nr = matrix.rows ();
66  int nc = matrix.cols ();
67 
68  // Don't use numel, since it can overflow for very large matrices
69  // Note that for the tests on matrix size, they become approximative
70  // since they involves a cast to double to avoid issues of overflow
71  if (matrix.rows () == 1 && matrix.cols () == 1)
72  {
73  // Const copy of the matrix, so the right version of () operator used
75 
76  Complex c = tmp (0, 0);
77 
78  if (c.imag () == 0.0)
79  retval = new octave_scalar (c.real ());
80  else
81  retval = new octave_complex (c);
82  }
83  else if (nr == 0 || nc == 0)
84  retval = new octave_matrix (Matrix (nr, nc));
85  else if (matrix.all_elements_are_real ())
86  if (matrix.cols () > 0 && matrix.rows () > 0
87  && (double (matrix.byte_size ()) > double (matrix.rows ())
88  * double (matrix.cols ()) * sizeof (double)))
89  retval = new octave_matrix (::real (matrix.matrix_value ()));
90  else
91  retval = new octave_sparse_matrix (::real (matrix));
92  else if (matrix.cols () > 0 && matrix.rows () > 0
93  && (double (matrix.byte_size ()) > double (matrix.rows ())
94  * double (matrix.cols ()) * sizeof (Complex)))
95  retval = new octave_complex_matrix (matrix.matrix_value ());
96  }
97  else
98  {
100  retval = new octave_sparse_matrix (::real (matrix));
101  }
102 
103  return retval;
104 }
105 
106 double
107 octave_sparse_complex_matrix::double_value (bool force_conversion) const
108 {
109  if (! force_conversion)
110  warn_implicit_conversion ("Octave:imag-to-real",
111  "complex sparse matrix", "real scalar");
112 
113  // FIXME: maybe this should be a function, valid_as_scalar()
114  if (is_empty ())
115  err_invalid_conversion ("complex sparse matrix", "real scalar");
116 
117  if (numel () > 1)
118  warn_implicit_conversion ("Octave:array-to-scalar",
119  "complex sparse matrix", "real scalar");
120 
121  return octave::math::real (matrix(0, 0));
122 }
123 
124 Matrix
125 octave_sparse_complex_matrix::matrix_value (bool force_conversion) const
126 {
127  Matrix retval;
128 
129  if (! force_conversion)
130  warn_implicit_conversion ("Octave:imag-to-real",
131  "complex sparse matrix", "real matrix");
132 
133  retval = ::real (matrix.matrix_value ());
134 
135  return retval;
136 }
137 
138 Complex
140 {
141  // FIXME: maybe this should be a function, valid_as_scalar()
142  if (is_empty ())
143  err_invalid_conversion ("complex sparse matrix", "real scalar");
144 
145  if (numel () > 1)
146  warn_implicit_conversion ("Octave:array-to-scalar",
147  "complex sparse matrix", "real scalar");
148 
149  return matrix(0, 0);
150 }
151 
154 {
155  return matrix.matrix_value ();
156 }
157 
160 {
161  return ComplexNDArray (matrix.matrix_value ());
162 }
163 
166 {
168 
169  if (! frc_str_conv)
170  warn_implicit_conversion ("Octave:num-to-str",
171  "sparse complex matrix", "string");
172  else
173  {
174  retval = charNDArray (dims (), 0);
175  octave_idx_type nc = matrix.cols ();
176  octave_idx_type nr = matrix.rows ();
177 
178  for (octave_idx_type j = 0; j < nc; j++)
179  for (octave_idx_type i = matrix.cidx (j); i < matrix.cidx (j+1); i++)
180  retval(matrix.ridx (i) + nr * j) =
181  static_cast<char>(octave::math::real (matrix.data (i)));
182  }
183 
184  return retval;
185 }
186 
189 {
191 
192  if (! force_conversion)
193  warn_implicit_conversion ("Octave:imag-to-real",
194  "complex sparse matrix",
195  "real sparse matrix");
196 
197  retval = ::real (matrix);
198 
199  return retval;
200 }
201 
204 {
205  if (matrix.any_element_is_nan ())
207  if (warn && (! matrix.all_elements_are_real ()
208  || real (matrix).any_element_not_one_or_zero ()))
210 
211  return mx_el_ne (matrix, Complex (0.0));
212 }
213 
216 {
217  return this->matrix;
218 }
219 
220 bool
222  bool& save_as_floats)
223 {
224  dim_vector dv = this->dims ();
225  if (dv.ndims () < 1)
226  return false;
227 
228  // Ensure that additional memory is deallocated
230 
231  int nr = dv(0);
232  int nc = dv(1);
233  int nz = nnz ();
234 
235  int32_t itmp;
236  // Use negative value for ndims to be consistent with other formats
237  itmp = -2;
238  os.write (reinterpret_cast<char *> (&itmp), 4);
239 
240  itmp = nr;
241  os.write (reinterpret_cast<char *> (&itmp), 4);
242 
243  itmp = nc;
244  os.write (reinterpret_cast<char *> (&itmp), 4);
245 
246  itmp = nz;
247  os.write (reinterpret_cast<char *> (&itmp), 4);
248 
249  save_type st = LS_DOUBLE;
250  if (save_as_floats)
251  {
253  {
254  warning ("save: some values too large to save as floats --");
255  warning ("save: saving as doubles instead");
256  }
257  else
258  st = LS_FLOAT;
259  }
260  else if (matrix.nnz () > 8192) // FIXME: make this configurable.
261  {
262  double max_val, min_val;
263  if (matrix.all_integers (max_val, min_val))
264  st = get_save_type (max_val, min_val);
265  }
266 
267  // add one to the printed indices to go from
268  // zero-based to one-based arrays
269  for (int i = 0; i < nc+1; i++)
270  {
271  octave_quit ();
272  itmp = matrix.cidx (i);
273  os.write (reinterpret_cast<char *> (&itmp), 4);
274  }
275 
276  for (int i = 0; i < nz; i++)
277  {
278  octave_quit ();
279  itmp = matrix.ridx (i);
280  os.write (reinterpret_cast<char *> (&itmp), 4);
281  }
282 
283  write_doubles (os, reinterpret_cast<const double *> (matrix.data ()), st,
284  2 * nz);
285 
286  return true;
287 }
288 
289 bool
292 {
293  int32_t nz, nc, nr, tmp;
294  char ctmp;
295 
296  if (! is.read (reinterpret_cast<char *> (&tmp), 4))
297  return false;
298 
299  if (swap)
300  swap_bytes<4> (&tmp);
301 
302  if (tmp != -2)
303  error ("load: only 2-D sparse matrices are supported");
304 
305  if (! is.read (reinterpret_cast<char *> (&nr), 4))
306  return false;
307  if (! is.read (reinterpret_cast<char *> (&nc), 4))
308  return false;
309  if (! is.read (reinterpret_cast<char *> (&nz), 4))
310  return false;
311 
312  if (swap)
313  {
314  swap_bytes<4> (&nr);
315  swap_bytes<4> (&nc);
316  swap_bytes<4> (&nz);
317  }
318 
319  SparseComplexMatrix m (static_cast<octave_idx_type> (nr),
320  static_cast<octave_idx_type> (nc),
321  static_cast<octave_idx_type> (nz));
322 
323  for (int i = 0; i < nc+1; i++)
324  {
325  octave_quit ();
326  if (! is.read (reinterpret_cast<char *> (&tmp), 4))
327  return false;
328  if (swap)
329  swap_bytes<4> (&tmp);
330  m.cidx (i) = tmp;
331  }
332 
333  for (int i = 0; i < nz; i++)
334  {
335  octave_quit ();
336  if (! is.read (reinterpret_cast<char *> (&tmp), 4))
337  return false;
338  if (swap)
339  swap_bytes<4> (&tmp);
340  m.ridx (i) = tmp;
341  }
342 
343  if (! is.read (reinterpret_cast<char *> (&ctmp), 1))
344  return false;
345 
346  read_doubles (is, reinterpret_cast<double *> (m.data ()),
347  static_cast<save_type> (ctmp), 2 * nz, swap, fmt);
348 
349  if (! is)
350  return false;
351 
352  if (! m.indices_ok ())
353  return false;
354 
355  matrix = m;
356 
357  return true;
358 }
359 
360 bool
362  bool save_as_floats)
363 {
364  bool retval = false;
365 
366 #if defined (HAVE_HDF5)
367 
368  dim_vector dv = dims ();
369  int empty = save_hdf5_empty (loc_id, name, dv);
370  if (empty)
371  return (empty > 0);
372 
373  // Ensure that additional memory is deallocated
375 
376 #if defined (HAVE_HDF5_18)
377  hid_t group_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT,
379 #else
380  hid_t group_hid = H5Gcreate (loc_id, name, 0);
381 #endif
382  if (group_hid < 0)
383  return false;
384 
385  hid_t space_hid, data_hid;
386  space_hid = data_hid = -1;
389  hsize_t hdims[2];
390 
391  space_hid = H5Screate_simple (0, hdims, 0);
392  if (space_hid < 0)
393  {
394  H5Gclose (group_hid);
395  return false;
396  }
397 
398 #if defined (HAVE_HDF5_18)
399  data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid,
401 #else
402  data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid,
404 #endif
405  if (data_hid < 0)
406  {
407  H5Sclose (space_hid);
408  H5Gclose (group_hid);
409  return false;
410  }
411 
412  tmp = m.rows ();
413  retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
414  octave_H5P_DEFAULT, &tmp) >= 0;
415  H5Dclose (data_hid);
416  if (! retval)
417  {
418  H5Sclose (space_hid);
419  H5Gclose (group_hid);
420  return false;
421  }
422 
423 #if defined (HAVE_HDF5_18)
424  data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid,
426 #else
427  data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid,
429 #endif
430  if (data_hid < 0)
431  {
432  H5Sclose (space_hid);
433  H5Gclose (group_hid);
434  return false;
435  }
436 
437  tmp = m.cols ();
438  retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
439  octave_H5P_DEFAULT, &tmp) >= 0;
440  H5Dclose (data_hid);
441  if (! retval)
442  {
443  H5Sclose (space_hid);
444  H5Gclose (group_hid);
445  return false;
446  }
447 
448 #if defined (HAVE_HDF5_18)
449  data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid,
451 #else
452  data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid,
454 #endif
455  if (data_hid < 0)
456  {
457  H5Sclose (space_hid);
458  H5Gclose (group_hid);
459  return false;
460  }
461 
462  tmp = m.nnz ();
463  retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
464  octave_H5P_DEFAULT, &tmp) >= 0;
465  H5Dclose (data_hid);
466  if (! retval)
467  {
468  H5Sclose (space_hid);
469  H5Gclose (group_hid);
470  return false;
471  }
472 
473  H5Sclose (space_hid);
474 
475  hdims[0] = m.cols () + 1;
476  hdims[1] = 1;
477 
478  space_hid = H5Screate_simple (2, hdims, 0);
479 
480  if (space_hid < 0)
481  {
482  H5Gclose (group_hid);
483  return false;
484  }
485 
486 #if defined (HAVE_HDF5_18)
487  data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid,
489 #else
490  data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid,
492 #endif
493  if (data_hid < 0)
494  {
495  H5Sclose (space_hid);
496  H5Gclose (group_hid);
497  return false;
498  }
499 
500  octave_idx_type * itmp = m.xcidx ();
501  retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
502  octave_H5P_DEFAULT, itmp) >= 0;
503  H5Dclose (data_hid);
504  if (! retval)
505  {
506  H5Sclose (space_hid);
507  H5Gclose (group_hid);
508  return false;
509  }
510 
511  H5Sclose (space_hid);
512 
513  hdims[0] = m.nnz ();
514  hdims[1] = 1;
515 
516  space_hid = H5Screate_simple (2, hdims, 0);
517 
518  if (space_hid < 0)
519  {
520  H5Gclose (group_hid);
521  return false;
522  }
523 
524 #if defined (HAVE_HDF5_18)
525  data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid,
527 #else
528  data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid,
530 #endif
531  if (data_hid < 0)
532  {
533  H5Sclose (space_hid);
534  H5Gclose (group_hid);
535  return false;
536  }
537 
538  itmp = m.xridx ();
539  retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL, octave_H5S_ALL,
540  octave_H5P_DEFAULT, itmp) >= 0;
541  H5Dclose (data_hid);
542  if (! retval)
543  {
544  H5Sclose (space_hid);
545  H5Gclose (group_hid);
546  return false;
547  }
548 
549  hid_t save_type_hid = H5T_NATIVE_DOUBLE;
550 
551  if (save_as_floats)
552  {
553  if (m.too_large_for_float ())
554  {
555  warning ("save: some values too large to save as floats --");
556  warning ("save: saving as doubles instead");
557  }
558  else
559  save_type_hid = H5T_NATIVE_FLOAT;
560  }
561 #if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
562  // hdf5 currently doesn't support float/integer conversions
563  else
564  {
565  double max_val, min_val;
566 
567  if (m.all_integers (max_val, min_val))
568  save_type_hid
569  = save_type_to_hdf5 (get_save_type (max_val, min_val));
570  }
571 #endif
572 
573  hid_t type_hid = hdf5_make_complex_type (save_type_hid);
574  if (type_hid < 0)
575  {
576  H5Sclose (space_hid);
577  H5Gclose (group_hid);
578  return false;
579  }
580 #if defined (HAVE_HDF5_18)
581  data_hid = H5Dcreate (group_hid, "data", type_hid, space_hid,
583 #else
584  data_hid = H5Dcreate (group_hid, "data", type_hid, space_hid,
586 #endif
587  if (data_hid < 0)
588  {
589  H5Sclose (space_hid);
590  H5Tclose (type_hid);
591  H5Gclose (group_hid);
592  return false;
593  }
594 
595  hid_t complex_type_hid = hdf5_make_complex_type (H5T_NATIVE_DOUBLE);
596  retval = false;
597  if (complex_type_hid >= 0)
598  {
599  Complex * ctmp = m.xdata ();
600 
601  retval = H5Dwrite (data_hid, complex_type_hid, octave_H5S_ALL, octave_H5S_ALL,
602  octave_H5P_DEFAULT, ctmp) >= 0;
603  }
604 
605  H5Dclose (data_hid);
606  H5Sclose (space_hid);
607  H5Tclose (type_hid);
608  H5Gclose (group_hid);
609 
610 #else
611  octave_unused_parameter (loc_id);
612  octave_unused_parameter (name);
613  octave_unused_parameter (save_as_floats);
614 
615  warn_save ("hdf5");
616 #endif
617 
618  return retval;
619 }
620 
621 bool
623  const char *name)
624 {
625  bool retval = false;
626 
627 #if defined (HAVE_HDF5)
628 
629  octave_idx_type nr, nc, nz;
630  hid_t group_hid, data_hid, space_hid;
631  hsize_t rank;
632 
633  dim_vector dv;
634  int empty = load_hdf5_empty (loc_id, name, dv);
635  if (empty > 0)
636  matrix.resize (dv);
637  if (empty)
638  return (empty > 0);
639 
640 #if defined (HAVE_HDF5_18)
641  group_hid = H5Gopen (loc_id, name, octave_H5P_DEFAULT);
642 #else
643  group_hid = H5Gopen (loc_id, name);
644 #endif
645  if (group_hid < 0) return false;
646 
647 #if defined (HAVE_HDF5_18)
648  data_hid = H5Dopen (group_hid, "nr", octave_H5P_DEFAULT);
649 #else
650  data_hid = H5Dopen (group_hid, "nr");
651 #endif
652  space_hid = H5Dget_space (data_hid);
653  rank = H5Sget_simple_extent_ndims (space_hid);
654 
655  if (rank != 0)
656  {
657  H5Dclose (data_hid);
658  H5Gclose (group_hid);
659  return false;
660  }
661 
662  if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL,
664  {
665  H5Dclose (data_hid);
666  H5Gclose (group_hid);
667  return false;
668  }
669 
670  H5Dclose (data_hid);
671 
672 #if defined (HAVE_HDF5_18)
673  data_hid = H5Dopen (group_hid, "nc", octave_H5P_DEFAULT);
674 #else
675  data_hid = H5Dopen (group_hid, "nc");
676 #endif
677  space_hid = H5Dget_space (data_hid);
678  rank = H5Sget_simple_extent_ndims (space_hid);
679 
680  if (rank != 0)
681  {
682  H5Dclose (data_hid);
683  H5Gclose (group_hid);
684  return false;
685  }
686 
687  if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL,
689  {
690  H5Dclose (data_hid);
691  H5Gclose (group_hid);
692  return false;
693  }
694 
695  H5Dclose (data_hid);
696 
697 #if defined (HAVE_HDF5_18)
698  data_hid = H5Dopen (group_hid, "nz", octave_H5P_DEFAULT);
699 #else
700  data_hid = H5Dopen (group_hid, "nz");
701 #endif
702  space_hid = H5Dget_space (data_hid);
703  rank = H5Sget_simple_extent_ndims (space_hid);
704 
705  if (rank != 0)
706  {
707  H5Dclose (data_hid);
708  H5Gclose (group_hid);
709  return false;
710  }
711 
712  if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL,
714  {
715  H5Dclose (data_hid);
716  H5Gclose (group_hid);
717  return false;
718  }
719 
720  H5Dclose (data_hid);
721 
722  SparseComplexMatrix m (static_cast<octave_idx_type> (nr),
723  static_cast<octave_idx_type> (nc),
724  static_cast<octave_idx_type> (nz));
725 
726 #if defined (HAVE_HDF5_18)
727  data_hid = H5Dopen (group_hid, "cidx", octave_H5P_DEFAULT);
728 #else
729  data_hid = H5Dopen (group_hid, "cidx");
730 #endif
731  space_hid = H5Dget_space (data_hid);
732  rank = H5Sget_simple_extent_ndims (space_hid);
733 
734  if (rank != 2)
735  {
736  H5Sclose (space_hid);
737  H5Dclose (data_hid);
738  H5Gclose (group_hid);
739  return false;
740  }
741 
742  OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
743  OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
744 
745  H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
746 
747  if (static_cast<int> (hdims[0]) != nc + 1
748  || static_cast<int> (hdims[1]) != 1)
749  {
750  H5Sclose (space_hid);
751  H5Dclose (data_hid);
752  H5Gclose (group_hid);
753  return false;
754  }
755 
756  octave_idx_type *itmp = m.xcidx ();
757  if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL,
759  {
760  H5Sclose (space_hid);
761  H5Dclose (data_hid);
762  H5Gclose (group_hid);
763  return false;
764  }
765 
766  H5Sclose (space_hid);
767  H5Dclose (data_hid);
768 
769 #if defined (HAVE_HDF5_18)
770  data_hid = H5Dopen (group_hid, "ridx", octave_H5P_DEFAULT);
771 #else
772  data_hid = H5Dopen (group_hid, "ridx");
773 #endif
774  space_hid = H5Dget_space (data_hid);
775  rank = H5Sget_simple_extent_ndims (space_hid);
776 
777  if (rank != 2)
778  {
779  H5Sclose (space_hid);
780  H5Dclose (data_hid);
781  H5Gclose (group_hid);
782  return false;
783  }
784 
785  H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
786 
787  if (static_cast<int> (hdims[0]) != nz
788  || static_cast<int> (hdims[1]) != 1)
789  {
790  H5Sclose (space_hid);
791  H5Dclose (data_hid);
792  H5Gclose (group_hid);
793  return false;
794  }
795 
796  itmp = m.xridx ();
797  if (H5Dread (data_hid, H5T_NATIVE_IDX, octave_H5S_ALL,
799  {
800  H5Sclose (space_hid);
801  H5Dclose (data_hid);
802  H5Gclose (group_hid);
803  return false;
804  }
805 
806  H5Sclose (space_hid);
807  H5Dclose (data_hid);
808 
809 #if defined (HAVE_HDF5_18)
810  data_hid = H5Dopen (group_hid, "data", octave_H5P_DEFAULT);
811 #else
812  data_hid = H5Dopen (group_hid, "data");
813 #endif
814  hid_t type_hid = H5Dget_type (data_hid);
815 
816  hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE);
817 
818  if (! hdf5_types_compatible (type_hid, complex_type))
819  {
820  H5Tclose (complex_type);
821  H5Dclose (data_hid);
822  H5Gclose (group_hid);
823  return false;
824  }
825 
826  space_hid = H5Dget_space (data_hid);
827  rank = H5Sget_simple_extent_ndims (space_hid);
828 
829  if (rank != 2)
830  {
831  H5Sclose (space_hid);
832  H5Dclose (data_hid);
833  H5Gclose (group_hid);
834  return false;
835  }
836 
837  H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
838 
839  if (static_cast<int> (hdims[0]) != nz
840  || static_cast<int> (hdims[1]) != 1)
841  {
842  H5Sclose (space_hid);
843  H5Dclose (data_hid);
844  H5Gclose (group_hid);
845  return false;
846  }
847 
848  Complex *ctmp = m.xdata ();
849 
850  if (H5Dread (data_hid, complex_type, octave_H5S_ALL, octave_H5S_ALL,
851  octave_H5P_DEFAULT, ctmp) >= 0
852  && m.indices_ok ())
853  {
854  retval = true;
855  matrix = m;
856  }
857 
858  H5Tclose (complex_type);
859  H5Sclose (space_hid);
860  H5Dclose (data_hid);
861  H5Gclose (group_hid);
862 
863 #else
864  octave_unused_parameter (loc_id);
865  octave_unused_parameter (name);
866 
867  warn_load ("hdf5");
868 #endif
869 
870  return retval;
871 }
872 
873 mxArray *
875 {
876  mwSize nz = nzmax ();
878  nz, mxCOMPLEX);
879  double *pr = static_cast<double *> (retval->get_data ());
880  double *pi = static_cast<double *> (retval->get_imag_data ());
881  mwIndex *ir = retval->get_ir ();
882  mwIndex *jc = retval->get_jc ();
883 
884  for (mwIndex i = 0; i < nz; i++)
885  {
886  Complex val = matrix.data (i);
887  pr[i] = val.real ();
888  pi[i] = val.imag ();
889  ir[i] = matrix.ridx (i);
890  }
891 
892  for (mwIndex i = 0; i < columns () + 1; i++)
893  jc[i] = matrix.cidx (i);
894 
895  return retval;
896 }
897 
900 {
901  switch (umap)
902  {
903  // Mappers handled specially.
904  case umap_real:
906  case umap_imag:
908 
909 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \
910  case umap_ ## UMAP: \
911  return octave_value (matrix.FCN ())
912 
914 
915 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \
916  case umap_ ## UMAP: \
917  return octave_value (matrix.map<TYPE> (FCN))
918 
921  ARRAY_MAPPER (angle, double, std::arg);
922  ARRAY_MAPPER (arg, double, std::arg);
933  ARRAY_MAPPER (conj, Complex, std::conj<double>);
934  ARRAY_MAPPER (cos, Complex, std::cos);
935  ARRAY_MAPPER (cosh, Complex, std::cosh);
936  ARRAY_MAPPER (exp, Complex, std::exp);
942  ARRAY_MAPPER (log10, Complex, std::log10);
947  ARRAY_MAPPER (sin, Complex, std::sin);
948  ARRAY_MAPPER (sinh, Complex, std::sinh);
949  ARRAY_MAPPER (sqrt, Complex, std::sqrt);
950  ARRAY_MAPPER (tan, Complex, std::tan);
951  ARRAY_MAPPER (tanh, Complex, std::tanh);
953  ARRAY_MAPPER (isna, bool, octave::math::is_NA);
955  ARRAY_MAPPER (isfinite, bool, octave::math::finite);
956 
957  default: // Attempt to go via dense matrix.
959  }
960 }
save_type
Definition: data-conv.h:85
octave_idx_type * xridx(void)
Definition: Sparse.h:536
SparseMatrix sparse_matrix_value(bool=false) const
octave_idx_type cols(void) const
Definition: Sparse.h:272
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
T * data(void)
Definition: Sparse.h:521
octave_idx_type rows(void) const
Definition: Sparse.h:271
ComplexMatrix matrix_value(void) const
Definition: CSparse.cc:601
octave_base_value * try_narrowing_conversion(void)
Definition: ov-cx-sparse.cc:59
float erfcx(float x)
Definition: lo-specfun.cc:271
octave_idx_type columns(void) const
Definition: ov-base.h:319
function erf(X)
Definition: erf.f:2
std::complex< double > erfi(std::complex< double > z, double relerr=0)
Complex complex_value(bool=false) const
void warn_logical_conversion(void)
Definition: errwarn.cc:353
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
const octave_hdf5_id octave_H5S_ALL
int save_hdf5_empty(octave_hdf5_id loc_id, const char *name, const dim_vector d)
Definition: ls-hdf5.cc:897
save_type get_save_type(double, double)
Definition: ls-utils.cc:35
SparseBoolMatrix sparse_bool_matrix_value(bool warn=false) const
bool isnan(double x)
Definition: lo-mappers.cc:347
double atanh(double x)
Definition: lo-specfun.cc:149
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the base of natural logarithms The constant ex $e satisfies the equation log(e)
double ceil(double x)
Definition: lo-mappers.h:138
function atanh(X)
Definition: atanh.f:2
octave_idx_type * xcidx(void)
Definition: Sparse.h:549
void error(const char *fmt,...)
Definition: error.cc:570
void * get_data(void) const
Definition: mxarray.h:449
void write_doubles(std::ostream &os, const double *data, save_type type, octave_idx_type len)
Definition: data-conv.cc:886
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:169
octave_idx_type * cidx(void)
Definition: Sparse.h:543
int load_hdf5_empty(octave_hdf5_id loc_id, const char *name, dim_vector &d)
Definition: ls-hdf5.cc:953
Complex acos(const Complex &x)
Definition: lo-mappers.cc:90
double expm1(double x)
Definition: lo-specfun.cc:473
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Definition: ov-cx-sparse.h:125
double asinh(double x)
Definition: lo-specfun.cc:105
double fix(double x)
Definition: lo-mappers.h:158
Complex asin(const Complex &x)
Definition: lo-mappers.cc:150
bool indices_ok(void) const
Definition: Sparse.h:696
void err_nan_to_logical_conversion(void)
octave_idx_type nzmax(void) const
double real(double x)
Definition: lo-mappers.h:113
bool is_empty(void) const
Definition: ov-base.h:355
octave_value arg
Definition: pr-output.cc:3440
double acosh(double x)
Definition: lo-specfun.cc:61
double round(double x)
Definition: lo-mappers.cc:333
bool is_NA(double x)
Definition: lo-mappers.cc:54
octave_idx_type nnz(void) const
Actual number of nonzero terms.
Definition: Sparse.h:253
bool swap
Definition: load-save.cc:725
float erfi(float x)
Definition: lo-specfun.cc:289
void warn_load(const char *type) const
Definition: ov-base.cc:1151
mwIndex * get_ir(void) const
Definition: mxarray.h:458
#define ARRAY_MAPPER(UMAP, TYPE, FCN)
ComplexColumnVector conj(const ComplexColumnVector &a)
Definition: CColVector.cc:216
ComplexMatrix complex_matrix_value(bool=false) const
create a structure array and initialize its values The dimensions of each cell array of values must match Singleton cells and non cell values are repeated so that they fill the entire array If the cells are empty
Definition: ov-struct.cc:1688
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
void swap_bytes< 4 >(void *ptr)
Definition: byte-swap.h:60
Complex atan(const Complex &x)
Definition: lo-mappers.cc:210
#define OCTINTERP_API
Definition: mexproto.h:69
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
octave_idx_type numel(void) const
function asinh(X)
Definition: asinh.f:2
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:771
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
bool hdf5_types_compatible(octave_hdf5_id t1, octave_hdf5_id t2)
Definition: ls-hdf5.cc:192
Sparse< T > maybe_compress(bool remove_zeros=false)
Definition: Sparse.h:481
void resize(octave_idx_type r, octave_idx_type c)
Definition: Sparse.cc:948
double signum(double x)
Definition: lo-mappers.h:259
double double_value(bool=false) const
float dawson(float x)
Definition: lo-specfun.cc:307
octave_value map(octave_base_value::unary_mapper_t umap) const
bool save_as_floats
Definition: load-save.cc:1581
octave_hdf5_id save_type_to_hdf5(save_type st)
Definition: ls-hdf5.cc:997
double tmp
Definition: data.cc:6300
size_t byte_size(void) const
Definition: Sparse.h:284
octave_value retval
Definition: data.cc:6294
bool too_large_for_float(void) const
Definition: CSparse.cc:7215
bool finite(double x)
Definition: lo-mappers.cc:367
std::complex< double > erfcx(std::complex< double > z, double relerr=0)
int64_t octave_hdf5_id
boolMatrix mx_el_ne(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:90
Definition: dMatrix.h:37
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
void warn_save(const char *type) const
Definition: ov-base.cc:1160
void mxArray
Definition: mex.h:55
bool isinf(double x)
Definition: lo-mappers.cc:387
function acosh(X)
Definition: acosh.f:2
charNDArray char_array_value(bool frc_str_conv=false) const
mxArray * as_mxArray(void) const
void warning(const char *fmt,...)
Definition: error.cc:788
double erf(double x)
Definition: lo-specfun.cc:193
bool all_elements_are_real(void) const
Definition: CSparse.cc:7167
void err_invalid_conversion(const std::string &from, const std::string &to)
Definition: errwarn.cc:68
octave_idx_type * ridx(void)
Definition: Sparse.h:530
bool any_element_is_nan(void) const
Definition: CSparse.cc:7135
void * get_imag_data(void) const
Definition: mxarray.h:451
#define ARRAY_METHOD_MAPPER(UMAP, FCN)
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
double log1p(double x)
Definition: lo-specfun.cc:587
OCTAVE_EXPORT octave_value_list return the value of the option it must match the dimension of the state and the relative tolerance must also be a vector of the same length tem it must match the dimension of the state and the absolute tolerance must also be a vector of the same length The local error test applied at each integration step is xample roup abs(local error in x(i))<
T * xdata(void)
Definition: Sparse.h:523
void warn_implicit_conversion(const char *id, const char *from, const char *to)
Definition: errwarn.cc:332
issues an error eealso double
Definition: ov-bool-mat.cc:594
double roundb(double x)
Definition: lo-mappers.h:189
octave_idx_type ndims(void) const
Number of dimensions.
Definition: dim-vector.h:301
#define H5T_NATIVE_IDX
Definition: oct-hdf5.h:39
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition: oct-locbuf.h:200
mwIndex * get_jc(void) const
Definition: mxarray.h:460
bool Vsparse_auto_mutate
Definition: ov-base.cc:119
ColumnVector imag(const ComplexColumnVector &a)
Definition: dColVector.cc:142
double floor(double x)
Definition: lo-mappers.cc:330
const octave_hdf5_id octave_H5P_DEFAULT
double erfc(double x)
Definition: lo-specfun.cc:232
octave_value map(unary_mapper_t umap) const
std::complex< double > Complex
Definition: oct-cmplx.h:31
ColumnVector real(const ComplexColumnVector &a)
Definition: dColVector.cc:136
write the output to stdout if nargout is
Definition: load-save.cc:1576
Matrix matrix_value(bool=false) const
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
octave_hdf5_id hdf5_make_complex_type(octave_hdf5_id num_type)
Definition: ls-hdf5.cc:328
bool save_binary(std::ostream &os, bool &save_as_floats)
bool all_integers(double &max_val, double &min_val) const
Definition: CSparse.cc:7177
dim_vector dv
Definition: sub2ind.cc:263
octave_value as_double(void) const
double log2(double x)
Definition: lo-mappers.cc:233
octave_idx_type rows(void) const
Definition: ov-base.h:312
ComplexNDArray complex_array_value(bool=false) const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
static const double pi
Definition: lo-specfun.cc:3610
std::complex< double > erfc(std::complex< double > z, double relerr=0)