26#if defined (HAVE_CONFIG_H)
51 "sparse bool matrix",
"logical");
78 "bool sparse matrix",
"real scalar");
91 "bool sparse matrix",
"complex scalar");
189#if OCTAVE_SIZEOF_IDX_TYPE == OCTAVE_SIZEOF_INT
190 if (nr < 0 || nc < 0 || nz < 0)
194 if (nr < 0 || nr > max_val || nc < 0 || nc > max_val
195 || nz < 0 || nz > max_val)
202 os.write (
reinterpret_cast<char *
> (&itmp), 4);
205 os.write (
reinterpret_cast<char *
> (&itmp), 4);
208 os.write (
reinterpret_cast<char *
> (&itmp), 4);
211 os.write (
reinterpret_cast<char *
> (&itmp), 4);
215 for (
int i = 0; i < nc+1; i++)
219 os.write (
reinterpret_cast<char *
> (&itmp), 4);
222 for (
int i = 0; i < nz; i++)
226 os.write (
reinterpret_cast<char *
> (&itmp), 4);
231 for (
int i = 0; i < nz; i++)
241 octave::mach_info::float_format )
243 int32_t nz, nc, nr, tmp;
244 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
251 error (
"load: only 2-D sparse matrices are supported");
253 if (! is.read (
reinterpret_cast<char *
> (&nr), 4))
255 if (! is.read (
reinterpret_cast<char *
> (&nc), 4))
257 if (! is.read (
reinterpret_cast<char *
> (&nz), 4))
271 for (
int i = 0; i < nc+1; i++)
274 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
281 for (
int i = 0; i < nz; i++)
284 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
296 if (! is.read (htmp, nz))
299 for (
int i = 0; i < nz; i++)
300 m.
data(i) = (htmp[i] ? 1 : 0);
316#if defined (HAVE_HDF5)
325#if defined (HAVE_HDF5_18)
329 hid_t group_hid = H5Gcreate (loc_id, name, 0);
334 hid_t space_hid, data_hid;
335 space_hid = data_hid = -1;
340 space_hid = H5Screate_simple (0, hdims,
nullptr);
343 H5Gclose (group_hid);
346#if defined (HAVE_HDF5_18)
356 H5Sclose (space_hid);
357 H5Gclose (group_hid);
367 H5Sclose (space_hid);
368 H5Gclose (group_hid);
372#if defined (HAVE_HDF5_18)
382 H5Sclose (space_hid);
383 H5Gclose (group_hid);
393 H5Sclose (space_hid);
394 H5Gclose (group_hid);
398#if defined (HAVE_HDF5_18)
408 H5Sclose (space_hid);
409 H5Gclose (group_hid);
419 H5Sclose (space_hid);
420 H5Gclose (group_hid);
424 H5Sclose (space_hid);
426 hdims[0] = m.
cols () + 1;
429 space_hid = H5Screate_simple (2, hdims,
nullptr);
433 H5Gclose (group_hid);
437#if defined (HAVE_HDF5_18)
438 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
442 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
447 H5Sclose (space_hid);
448 H5Gclose (group_hid);
458 H5Sclose (space_hid);
459 H5Gclose (group_hid);
463 H5Sclose (space_hid);
468 space_hid = H5Screate_simple (2, hdims,
nullptr);
472 H5Gclose (group_hid);
476#if defined (HAVE_HDF5_18)
477 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
481 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
486 H5Sclose (space_hid);
487 H5Gclose (group_hid);
497 H5Sclose (space_hid);
498 H5Gclose (group_hid);
502#if defined (HAVE_HDF5_18)
503 data_hid = H5Dcreate (group_hid,
"data", H5T_NATIVE_HBOOL, space_hid,
507 data_hid = H5Dcreate (group_hid,
"data", H5T_NATIVE_HBOOL, space_hid,
512 H5Sclose (space_hid);
513 H5Gclose (group_hid);
518 for (
int i = 0; i < m.
nnz (); i++)
519 htmp[i] = m.
xdata(i);
524 H5Sclose (space_hid);
525 H5Gclose (group_hid);
528 octave_unused_parameter (loc_id);
529 octave_unused_parameter (name);
542#if defined (HAVE_HDF5)
545 hid_t group_hid, data_hid, space_hid;
555#if defined (HAVE_HDF5_18)
558 group_hid = H5Gopen (loc_id, name);
560 if (group_hid < 0)
return false;
562#if defined (HAVE_HDF5_18)
565 data_hid = H5Dopen (group_hid,
"nr");
567 space_hid = H5Dget_space (data_hid);
568 rank = H5Sget_simple_extent_ndims (space_hid);
573 H5Gclose (group_hid);
582 H5Gclose (group_hid);
588#if defined (HAVE_HDF5_18)
591 data_hid = H5Dopen (group_hid,
"nc");
593 space_hid = H5Dget_space (data_hid);
594 rank = H5Sget_simple_extent_ndims (space_hid);
599 H5Gclose (group_hid);
608 H5Gclose (group_hid);
614#if defined (HAVE_HDF5_18)
617 data_hid = H5Dopen (group_hid,
"nz");
619 space_hid = H5Dget_space (data_hid);
620 rank = H5Sget_simple_extent_ndims (space_hid);
625 H5Gclose (group_hid);
634 H5Gclose (group_hid);
644#if defined (HAVE_HDF5_18)
647 data_hid = H5Dopen (group_hid,
"cidx");
649 space_hid = H5Dget_space (data_hid);
650 rank = H5Sget_simple_extent_ndims (space_hid);
654 H5Sclose (space_hid);
656 H5Gclose (group_hid);
663 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
665 if (
static_cast<int> (hdims[0]) != nc + 1
666 ||
static_cast<int> (hdims[1]) != 1)
668 H5Sclose (space_hid);
670 H5Gclose (group_hid);
679 H5Sclose (space_hid);
681 H5Gclose (group_hid);
685 H5Sclose (space_hid);
688#if defined (HAVE_HDF5_18)
691 data_hid = H5Dopen (group_hid,
"ridx");
693 space_hid = H5Dget_space (data_hid);
694 rank = H5Sget_simple_extent_ndims (space_hid);
698 H5Sclose (space_hid);
700 H5Gclose (group_hid);
704 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
706 if (
static_cast<int> (hdims[0]) != nz
707 ||
static_cast<int> (hdims[1]) != 1)
709 H5Sclose (space_hid);
711 H5Gclose (group_hid);
719 H5Sclose (space_hid);
721 H5Gclose (group_hid);
725 H5Sclose (space_hid);
728#if defined (HAVE_HDF5_18)
731 data_hid = H5Dopen (group_hid,
"data");
733 space_hid = H5Dget_space (data_hid);
734 rank = H5Sget_simple_extent_ndims (space_hid);
738 H5Sclose (space_hid);
740 H5Gclose (group_hid);
744 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
746 if (
static_cast<int> (hdims[0]) != nz
747 ||
static_cast<int> (hdims[1]) != 1)
749 H5Sclose (space_hid);
751 H5Gclose (group_hid);
763 for (
int i = 0; i < nz; i++)
764 m.
xdata(i) = htmp[i];
769 H5Sclose (space_hid);
771 H5Gclose (group_hid);
774 octave_unused_parameter (loc_id);
775 octave_unused_parameter (name);
786 mwSize nz =
nzmax ();
790 mxArray *retval =
new mxArray (interleaved, mxLOGICAL_CLASS, nr, nc, nz,
793 mxLogical *pd =
static_cast<mxLogical *
> (retval->
get_data ());
794 mwIndex *ir = retval->
get_ir ();
799 for (mwIndex i = 0; i < nz; i++)
806 mwIndex *jc = retval->
get_jc ();
810 for (mwIndex i = 0; i < nc + 1; i++)
void swap_bytes< 4 >(void *ptr)
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 nnz() const
Actual number of nonzero terms.
octave_idx_type rows() const
octave_idx_type * xcidx()
octave_idx_type * xridx()
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)