55 "sparse complex matrix",
"double");
82 else if (nr == 0 || nc == 0)
110 if (! force_conversion)
112 "complex sparse matrix",
"real scalar");
119 "complex sparse matrix",
"real scalar");
134 if (! force_conversion)
136 "complex sparse matrix",
"real matrix");
155 "complex sparse matrix",
"real scalar");
184 "sparse complex matrix",
"string");
205 if (! force_conversion)
207 "complex sparse matrix",
208 "real sparse matrix");
221 ||
real (
matrix).any_element_not_one_or_zero ()))
245 os.write (reinterpret_cast<char *> (&itmp), 4);
248 os.write (reinterpret_cast<char *> (&itmp), 4);
251 os.write (reinterpret_cast<char *> (&itmp), 4);
254 os.write (reinterpret_cast<char *> (&itmp), 4);
261 warning (
"save: some values too large to save as floats --");
262 warning (
"save: saving as doubles instead");
269 double max_val, min_val;
276 for (
int i = 0; i < nc+1; i++)
280 os.write (reinterpret_cast<char *> (&itmp), 4);
283 for (
int i = 0; i < nz; i++)
287 os.write (reinterpret_cast<char *> (&itmp), 4);
300 int32_t nz, nc, nr, tmp;
303 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
311 error (
"load: only 2-D sparse matrices are supported");
315 if (! is.read (reinterpret_cast<char *> (&nr), 4))
317 if (! is.read (reinterpret_cast<char *> (&nc), 4))
319 if (! is.read (reinterpret_cast<char *> (&nz), 4))
330 static_cast<octave_idx_type> (nc),
331 static_cast<octave_idx_type> (nz));
333 for (
int i = 0; i < nc+1; i++)
336 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
343 for (
int i = 0; i < nz; i++)
346 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
353 if (! is.read (reinterpret_cast<char *> (&ctmp), 1))
357 static_cast<save_type> (ctmp), 2 * nz, swap, fmt);
370 #if defined (HAVE_HDF5)
385 hid_t group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT,
388 hid_t group_hid = H5Gcreate (loc_id, name, 0);
393 hid_t space_hid = -1, data_hid = -1;
399 space_hid = H5Screate_simple (0, hdims, 0);
402 H5Gclose (group_hid);
408 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
415 H5Sclose (space_hid);
416 H5Gclose (group_hid);
422 H5P_DEFAULT, &tmp) >= 0;
426 H5Sclose (space_hid);
427 H5Gclose (group_hid);
433 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
440 H5Sclose (space_hid);
441 H5Gclose (group_hid);
447 H5P_DEFAULT, &tmp) >= 0;
451 H5Sclose (space_hid);
452 H5Gclose (group_hid);
458 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
465 H5Sclose (space_hid);
466 H5Gclose (group_hid);
472 H5P_DEFAULT, &tmp) >= 0;
476 H5Sclose (space_hid);
477 H5Gclose (group_hid);
481 H5Sclose (space_hid);
483 hdims[0] = m.
cols () + 1;
486 space_hid = H5Screate_simple (2, hdims, 0);
490 H5Gclose (group_hid);
495 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
496 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
498 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
503 H5Sclose (space_hid);
504 H5Gclose (group_hid);
510 H5P_DEFAULT, itmp) >= 0;
514 H5Sclose (space_hid);
515 H5Gclose (group_hid);
519 H5Sclose (space_hid);
524 space_hid = H5Screate_simple (2, hdims, 0);
528 H5Gclose (group_hid);
533 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
534 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
536 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
541 H5Sclose (space_hid);
542 H5Gclose (group_hid);
547 retval = H5Dwrite (data_hid,
H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT,
552 H5Sclose (space_hid);
553 H5Gclose (group_hid);
557 hid_t save_type_hid = H5T_NATIVE_DOUBLE;
563 warning (
"save: some values too large to save as floats --");
564 warning (
"save: saving as doubles instead");
567 save_type_hid = H5T_NATIVE_FLOAT;
569 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS
573 double max_val, min_val;
584 H5Sclose (space_hid);
585 H5Gclose (group_hid);
589 data_hid = H5Dcreate (group_hid,
"data", type_hid, space_hid,
590 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
592 data_hid = H5Dcreate (group_hid,
"data", type_hid, space_hid, H5P_DEFAULT);
596 H5Sclose (space_hid);
598 H5Gclose (group_hid);
604 if (complex_type_hid >= 0)
608 retval = H5Dwrite (data_hid, complex_type_hid, H5S_ALL, H5S_ALL,
609 H5P_DEFAULT, ctmp) >= 0;
613 H5Sclose (space_hid);
615 H5Gclose (group_hid);
624 hid_t group_hid, data_hid, space_hid;
635 group_hid = H5Gopen (loc_id, name, H5P_DEFAULT);
637 group_hid = H5Gopen (loc_id, name);
639 if (group_hid < 0 )
return false;
642 data_hid = H5Dopen (group_hid,
"nr", H5P_DEFAULT);
644 data_hid = H5Dopen (group_hid,
"nr");
646 space_hid = H5Dget_space (data_hid);
647 rank = H5Sget_simple_extent_ndims (space_hid);
652 H5Gclose (group_hid);
657 H5S_ALL, H5P_DEFAULT, &nr) < 0)
660 H5Gclose (group_hid);
667 data_hid = H5Dopen (group_hid,
"nc", H5P_DEFAULT);
669 data_hid = H5Dopen (group_hid,
"nc");
671 space_hid = H5Dget_space (data_hid);
672 rank = H5Sget_simple_extent_ndims (space_hid);
677 H5Gclose (group_hid);
682 H5S_ALL, H5P_DEFAULT, &nc) < 0)
685 H5Gclose (group_hid);
692 data_hid = H5Dopen (group_hid,
"nz", H5P_DEFAULT);
694 data_hid = H5Dopen (group_hid,
"nz");
696 space_hid = H5Dget_space (data_hid);
697 rank = H5Sget_simple_extent_ndims (space_hid);
702 H5Gclose (group_hid);
707 H5S_ALL, H5P_DEFAULT, &nz) < 0)
710 H5Gclose (group_hid);
717 static_cast<octave_idx_type> (nc),
718 static_cast<octave_idx_type> (nz));
721 data_hid = H5Dopen (group_hid,
"cidx", H5P_DEFAULT);
723 data_hid = H5Dopen (group_hid,
"cidx");
725 space_hid = H5Dget_space (data_hid);
726 rank = H5Sget_simple_extent_ndims (space_hid);
730 H5Sclose (space_hid);
732 H5Gclose (group_hid);
739 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
741 if (static_cast<int> (hdims[0]) != nc + 1
742 || static_cast<int> (hdims[1]) != 1)
744 H5Sclose (space_hid);
746 H5Gclose (group_hid);
752 H5S_ALL, H5P_DEFAULT, itmp) < 0)
754 H5Sclose (space_hid);
756 H5Gclose (group_hid);
760 H5Sclose (space_hid);
764 data_hid = H5Dopen (group_hid,
"ridx", H5P_DEFAULT);
766 data_hid = H5Dopen (group_hid,
"ridx");
768 space_hid = H5Dget_space (data_hid);
769 rank = H5Sget_simple_extent_ndims (space_hid);
773 H5Sclose (space_hid);
775 H5Gclose (group_hid);
779 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
781 if (static_cast<int> (hdims[0]) != nz
782 || static_cast<int> (hdims[1]) != 1)
784 H5Sclose (space_hid);
786 H5Gclose (group_hid);
792 H5S_ALL, H5P_DEFAULT, itmp) < 0)
794 H5Sclose (space_hid);
796 H5Gclose (group_hid);
800 H5Sclose (space_hid);
804 data_hid = H5Dopen (group_hid,
"data", H5P_DEFAULT);
806 data_hid = H5Dopen (group_hid,
"data");
808 hid_t type_hid = H5Dget_type (data_hid);
814 H5Tclose (complex_type);
816 H5Gclose (group_hid);
820 space_hid = H5Dget_space (data_hid);
821 rank = H5Sget_simple_extent_ndims (space_hid);
825 H5Sclose (space_hid);
827 H5Gclose (group_hid);
831 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
833 if (static_cast<int> (hdims[0]) != nz
834 || static_cast<int> (hdims[1]) != 1)
836 H5Sclose (space_hid);
838 H5Gclose (group_hid);
844 if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL,
845 H5P_DEFAULT, ctmp) >= 0
852 H5Tclose (complex_type);
853 H5Sclose (space_hid);
855 H5Gclose (group_hid);
868 double *pr =
static_cast<double *
> (retval->
get_data ());
869 double *pi =
static_cast<double *
> (retval->
get_imag_data ());
873 for (
mwIndex i = 0; i < nz; i++)
898 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \
899 case umap_ ## UMAP: \
900 return octave_value (matrix.FCN ())
904 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \
905 case umap_ ## UMAP: \
906 return octave_value (matrix.map<TYPE> (FCN))