26 #if defined (HAVE_CONFIG_H)
57 "sparse bool matrix",
"logical");
84 "bool sparse matrix",
"real scalar");
97 "bool sparse matrix",
"complex scalar");
195 #if OCTAVE_SIZEOF_IDX_TYPE == OCTAVE_SIZEOF_INT
196 if (nr < 0 || nc < 0 || nz < 0)
200 if (nr < 0 || nr > max_val || nc < 0 || nc > max_val
201 || nz < 0 || nz > max_val)
208 os.write (
reinterpret_cast<char *
> (&itmp), 4);
211 os.write (
reinterpret_cast<char *
> (&itmp), 4);
214 os.write (
reinterpret_cast<char *
> (&itmp), 4);
217 os.write (
reinterpret_cast<char *
> (&itmp), 4);
221 for (
int i = 0; i < nc+1; i++)
225 os.write (
reinterpret_cast<char *
> (&itmp), 4);
228 for (
int i = 0; i < nz; i++)
232 os.write (
reinterpret_cast<char *
> (&itmp), 4);
237 for (
int i = 0; i < nz; i++)
249 int32_t nz, nc, nr, tmp;
250 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
257 error (
"load: only 2-D sparse matrices are supported");
259 if (! is.read (
reinterpret_cast<char *
> (&nr), 4))
261 if (! is.read (
reinterpret_cast<char *
> (&nc), 4))
263 if (! is.read (
reinterpret_cast<char *
> (&nz), 4))
277 for (
int i = 0; i < nc+1; i++)
280 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
287 for (
int i = 0; i < nz; i++)
290 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
302 if (! is.read (htmp, nz))
305 for (
int i = 0; i < nz; i++)
306 m.data(i) = (htmp[i] ? 1 : 0);
308 if (!
m.indices_ok ())
322 #if defined (HAVE_HDF5)
331 #if defined (HAVE_HDF5_18)
335 hid_t group_hid = H5Gcreate (loc_id, name, 0);
340 hid_t space_hid, data_hid;
341 space_hid = data_hid = -1;
346 space_hid = H5Screate_simple (0, hdims,
nullptr);
349 H5Gclose (group_hid);
352 #if defined (HAVE_HDF5_18)
362 H5Sclose (space_hid);
363 H5Gclose (group_hid);
373 H5Sclose (space_hid);
374 H5Gclose (group_hid);
378 #if defined (HAVE_HDF5_18)
388 H5Sclose (space_hid);
389 H5Gclose (group_hid);
399 H5Sclose (space_hid);
400 H5Gclose (group_hid);
404 #if defined (HAVE_HDF5_18)
414 H5Sclose (space_hid);
415 H5Gclose (group_hid);
425 H5Sclose (space_hid);
426 H5Gclose (group_hid);
430 H5Sclose (space_hid);
432 hdims[0] =
m.cols () + 1;
435 space_hid = H5Screate_simple (2, hdims,
nullptr);
439 H5Gclose (group_hid);
443 #if defined (HAVE_HDF5_18)
444 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
448 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
453 H5Sclose (space_hid);
454 H5Gclose (group_hid);
464 H5Sclose (space_hid);
465 H5Gclose (group_hid);
469 H5Sclose (space_hid);
474 space_hid = H5Screate_simple (2, hdims,
nullptr);
478 H5Gclose (group_hid);
482 #if defined (HAVE_HDF5_18)
483 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
487 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
492 H5Sclose (space_hid);
493 H5Gclose (group_hid);
503 H5Sclose (space_hid);
504 H5Gclose (group_hid);
508 #if defined (HAVE_HDF5_18)
509 data_hid = H5Dcreate (group_hid,
"data", H5T_NATIVE_HBOOL, space_hid,
513 data_hid = H5Dcreate (group_hid,
"data", H5T_NATIVE_HBOOL, space_hid,
518 H5Sclose (space_hid);
519 H5Gclose (group_hid);
524 for (
int i = 0; i <
m.nnz (); i++)
525 htmp[i] =
m.xdata(i);
530 H5Sclose (space_hid);
531 H5Gclose (group_hid);
534 octave_unused_parameter (loc_id);
535 octave_unused_parameter (name);
548 #if defined (HAVE_HDF5)
551 hid_t group_hid, data_hid, space_hid;
561 #if defined (HAVE_HDF5_18)
564 group_hid = H5Gopen (loc_id, name);
566 if (group_hid < 0)
return false;
568 #if defined (HAVE_HDF5_18)
571 data_hid = H5Dopen (group_hid,
"nr");
573 space_hid = H5Dget_space (data_hid);
574 rank = H5Sget_simple_extent_ndims (space_hid);
579 H5Gclose (group_hid);
588 H5Gclose (group_hid);
594 #if defined (HAVE_HDF5_18)
597 data_hid = H5Dopen (group_hid,
"nc");
599 space_hid = H5Dget_space (data_hid);
600 rank = H5Sget_simple_extent_ndims (space_hid);
605 H5Gclose (group_hid);
614 H5Gclose (group_hid);
620 #if defined (HAVE_HDF5_18)
623 data_hid = H5Dopen (group_hid,
"nz");
625 space_hid = H5Dget_space (data_hid);
626 rank = H5Sget_simple_extent_ndims (space_hid);
631 H5Gclose (group_hid);
640 H5Gclose (group_hid);
650 #if defined (HAVE_HDF5_18)
653 data_hid = H5Dopen (group_hid,
"cidx");
655 space_hid = H5Dget_space (data_hid);
656 rank = H5Sget_simple_extent_ndims (space_hid);
660 H5Sclose (space_hid);
662 H5Gclose (group_hid);
669 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
671 if (
static_cast<int> (hdims[0]) != nc + 1
672 ||
static_cast<int> (hdims[1]) != 1)
674 H5Sclose (space_hid);
676 H5Gclose (group_hid);
685 H5Sclose (space_hid);
687 H5Gclose (group_hid);
691 H5Sclose (space_hid);
694 #if defined (HAVE_HDF5_18)
697 data_hid = H5Dopen (group_hid,
"ridx");
699 space_hid = H5Dget_space (data_hid);
700 rank = H5Sget_simple_extent_ndims (space_hid);
704 H5Sclose (space_hid);
706 H5Gclose (group_hid);
710 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
712 if (
static_cast<int> (hdims[0]) != nz
713 ||
static_cast<int> (hdims[1]) != 1)
715 H5Sclose (space_hid);
717 H5Gclose (group_hid);
725 H5Sclose (space_hid);
727 H5Gclose (group_hid);
731 H5Sclose (space_hid);
734 #if defined (HAVE_HDF5_18)
737 data_hid = H5Dopen (group_hid,
"data");
739 space_hid = H5Dget_space (data_hid);
740 rank = H5Sget_simple_extent_ndims (space_hid);
744 H5Sclose (space_hid);
746 H5Gclose (group_hid);
750 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
752 if (
static_cast<int> (hdims[0]) != nz
753 ||
static_cast<int> (hdims[1]) != 1)
755 H5Sclose (space_hid);
757 H5Gclose (group_hid);
769 for (
int i = 0; i < nz; i++)
770 m.xdata(i) = htmp[i];
775 H5Sclose (space_hid);
777 H5Gclose (group_hid);
780 octave_unused_parameter (loc_id);
781 octave_unused_parameter (name);
805 for (
mwIndex i = 0; i < nz; i++)
816 for (
mwIndex i = 0; i < nc + 1; i++)
void swap_bytes< 4 >(void *ptr)
charNDArray max(char d, const charNDArray &m)
boolMatrix matrix_value() const
octave_idx_type cols() const
void resize(octave_idx_type r, octave_idx_type c)
Sparse< T, Alloc > maybe_compress(bool remove_zeros=false)
octave_idx_type rows() const
Vector representing the dimensions (size) of an Array.
octave_idx_type ndims() const
Number of dimensions.
octave_idx_type nzmax() const
octave_idx_type numel() const
octave_idx_type nnz() const
octave_idx_type rows() const
octave_idx_type columns() const
void warn_load(const char *type) const
friend class octave_value
void warn_save(const char *type) const
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
octave_value as_double() const
double double_value(bool=false) const
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
type_conv_info numeric_conversion_function() const
NDArray array_value(bool=false) const
Complex complex_value(bool=false) const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
charNDArray char_array_value(bool=false) const
ComplexMatrix complex_matrix_value(bool=false) const
boolMatrix bool_matrix_value(bool=false) const
ComplexNDArray complex_array_value(bool=false) const
octave_value convert_to_str_internal(bool pad, bool force, char type) const
SparseMatrix sparse_matrix_value(bool=false) const
SparseBoolMatrix sparse_bool_matrix_value(bool=false) const
bool save_binary(std::ostream &os, bool save_as_floats)
Matrix matrix_value(bool=false) const
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
mxArray * as_mxArray(bool interleaved) const
boolNDArray bool_array_value(bool=false) const
static int static_type_id()
octave_value convert_to_str(bool pad=false, bool force=false, char type='\'') const
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
void() error(const char *fmt,...)
void err_invalid_conversion(const std::string &from, const std::string &to)
void warn_implicit_conversion(const char *id, const char *from, const char *to)
int save_hdf5_empty(octave_hdf5_id loc_id, const char *name, const dim_vector &d)
int load_hdf5_empty(octave_hdf5_id loc_id, const char *name, dim_vector &d)
std::complex< double > Complex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)