26 #if defined (HAVE_CONFIG_H)
57 "sparse bool matrix",
"logical");
84 "bool sparse matrix",
"real scalar");
97 "bool sparse matrix",
"complex scalar");
197 os.write (
reinterpret_cast<char *
> (&itmp), 4);
200 os.write (
reinterpret_cast<char *
> (&itmp), 4);
203 os.write (
reinterpret_cast<char *
> (&itmp), 4);
206 os.write (
reinterpret_cast<char *
> (&itmp), 4);
210 for (
int i = 0; i < nc+1; i++)
214 os.write (
reinterpret_cast<char *
> (&itmp), 4);
217 for (
int i = 0; i < nz; i++)
221 os.write (
reinterpret_cast<char *
> (&itmp), 4);
226 for (
int i = 0; i < nz; i++)
238 int32_t nz, nc, nr, tmp;
239 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
246 error (
"load: only 2-D sparse matrices are supported");
248 if (! is.read (
reinterpret_cast<char *
> (&nr), 4))
250 if (! is.read (
reinterpret_cast<char *
> (&nc), 4))
252 if (! is.read (
reinterpret_cast<char *
> (&nz), 4))
266 for (
int i = 0; i < nc+1; i++)
269 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
276 for (
int i = 0; i < nz; i++)
279 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
291 if (! is.read (htmp, nz))
294 for (
int i = 0; i < nz; i++)
295 m.data(i) = (htmp[i] ? 1 : 0);
297 if (!
m.indices_ok ())
311 #if defined (HAVE_HDF5)
320 #if defined (HAVE_HDF5_18)
324 hid_t group_hid = H5Gcreate (loc_id, name, 0);
329 hid_t space_hid, data_hid;
330 space_hid = data_hid = -1;
335 space_hid = H5Screate_simple (0, hdims,
nullptr);
338 H5Gclose (group_hid);
341 #if defined (HAVE_HDF5_18)
351 H5Sclose (space_hid);
352 H5Gclose (group_hid);
362 H5Sclose (space_hid);
363 H5Gclose (group_hid);
367 #if defined (HAVE_HDF5_18)
377 H5Sclose (space_hid);
378 H5Gclose (group_hid);
388 H5Sclose (space_hid);
389 H5Gclose (group_hid);
393 #if defined (HAVE_HDF5_18)
403 H5Sclose (space_hid);
404 H5Gclose (group_hid);
414 H5Sclose (space_hid);
415 H5Gclose (group_hid);
419 H5Sclose (space_hid);
421 hdims[0] =
m.cols () + 1;
424 space_hid = H5Screate_simple (2, hdims,
nullptr);
428 H5Gclose (group_hid);
432 #if defined (HAVE_HDF5_18)
433 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
437 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
442 H5Sclose (space_hid);
443 H5Gclose (group_hid);
453 H5Sclose (space_hid);
454 H5Gclose (group_hid);
458 H5Sclose (space_hid);
463 space_hid = H5Screate_simple (2, hdims,
nullptr);
467 H5Gclose (group_hid);
471 #if defined (HAVE_HDF5_18)
472 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
476 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
481 H5Sclose (space_hid);
482 H5Gclose (group_hid);
492 H5Sclose (space_hid);
493 H5Gclose (group_hid);
497 #if defined (HAVE_HDF5_18)
498 data_hid = H5Dcreate (group_hid,
"data", H5T_NATIVE_HBOOL, space_hid,
502 data_hid = H5Dcreate (group_hid,
"data", H5T_NATIVE_HBOOL, space_hid,
507 H5Sclose (space_hid);
508 H5Gclose (group_hid);
513 for (
int i = 0; i <
m.nnz (); i++)
514 htmp[i] =
m.xdata(i);
519 H5Sclose (space_hid);
520 H5Gclose (group_hid);
523 octave_unused_parameter (loc_id);
524 octave_unused_parameter (name);
537 #if defined (HAVE_HDF5)
540 hid_t group_hid, data_hid, space_hid;
550 #if defined (HAVE_HDF5_18)
553 group_hid = H5Gopen (loc_id, name);
555 if (group_hid < 0)
return false;
557 #if defined (HAVE_HDF5_18)
560 data_hid = H5Dopen (group_hid,
"nr");
562 space_hid = H5Dget_space (data_hid);
563 rank = H5Sget_simple_extent_ndims (space_hid);
568 H5Gclose (group_hid);
577 H5Gclose (group_hid);
583 #if defined (HAVE_HDF5_18)
586 data_hid = H5Dopen (group_hid,
"nc");
588 space_hid = H5Dget_space (data_hid);
589 rank = H5Sget_simple_extent_ndims (space_hid);
594 H5Gclose (group_hid);
603 H5Gclose (group_hid);
609 #if defined (HAVE_HDF5_18)
612 data_hid = H5Dopen (group_hid,
"nz");
614 space_hid = H5Dget_space (data_hid);
615 rank = H5Sget_simple_extent_ndims (space_hid);
620 H5Gclose (group_hid);
629 H5Gclose (group_hid);
639 #if defined (HAVE_HDF5_18)
642 data_hid = H5Dopen (group_hid,
"cidx");
644 space_hid = H5Dget_space (data_hid);
645 rank = H5Sget_simple_extent_ndims (space_hid);
649 H5Sclose (space_hid);
651 H5Gclose (group_hid);
658 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
660 if (
static_cast<int> (hdims[0]) != nc + 1
661 ||
static_cast<int> (hdims[1]) != 1)
663 H5Sclose (space_hid);
665 H5Gclose (group_hid);
674 H5Sclose (space_hid);
676 H5Gclose (group_hid);
680 H5Sclose (space_hid);
683 #if defined (HAVE_HDF5_18)
686 data_hid = H5Dopen (group_hid,
"ridx");
688 space_hid = H5Dget_space (data_hid);
689 rank = H5Sget_simple_extent_ndims (space_hid);
693 H5Sclose (space_hid);
695 H5Gclose (group_hid);
699 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
701 if (
static_cast<int> (hdims[0]) != nz
702 ||
static_cast<int> (hdims[1]) != 1)
704 H5Sclose (space_hid);
706 H5Gclose (group_hid);
714 H5Sclose (space_hid);
716 H5Gclose (group_hid);
720 H5Sclose (space_hid);
723 #if defined (HAVE_HDF5_18)
726 data_hid = H5Dopen (group_hid,
"data");
728 space_hid = H5Dget_space (data_hid);
729 rank = H5Sget_simple_extent_ndims (space_hid);
733 H5Sclose (space_hid);
735 H5Gclose (group_hid);
739 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
741 if (
static_cast<int> (hdims[0]) != nz
742 ||
static_cast<int> (hdims[1]) != 1)
744 H5Sclose (space_hid);
746 H5Gclose (group_hid);
758 for (
int i = 0; i < nz; i++)
759 m.xdata(i) = htmp[i];
764 H5Sclose (space_hid);
766 H5Gclose (group_hid);
769 octave_unused_parameter (loc_id);
770 octave_unused_parameter (name);
781 mwSize nz =
nzmax ();
785 mxArray *retval =
new mxArray (interleaved, mxLOGICAL_CLASS, nr, nc, nz,
788 mxLogical *pd =
static_cast<mxLogical *
> (retval->
get_data ());
789 mwIndex *ir = retval->
get_ir ();
794 for (mwIndex i = 0; i < nz; i++)
801 mwIndex *jc = retval->
get_jc ();
805 for (mwIndex i = 0; i < nc + 1; i++)
void swap_bytes< 4 >(void *ptr)
OCTAVE_API boolMatrix matrix_value(void) const
octave_idx_type rows(void) const
octave_idx_type * cidx(void)
octave_idx_type * ridx(void)
OCTAVE_API void resize(octave_idx_type r, octave_idx_type c)
Sparse< T, Alloc > maybe_compress(bool remove_zeros=false)
octave_idx_type cols(void) const
Vector representing the dimensions (size) of an Array.
octave_idx_type ndims(void) const
Number of dimensions.
void * get_data(void) const
mwIndex * get_jc(void) const
mwIndex * get_ir(void) const
octave_idx_type nnz(void) const
octave_idx_type nzmax(void) const
octave_idx_type numel(void) const
dim_vector dims(void) const
octave_idx_type columns(void) const
OCTINTERP_API void warn_load(const char *type) const
octave_idx_type rows(void) const
friend class octave_value
OCTINTERP_API void warn_save(const char *type) const
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
double double_value(bool=false) const
SparseComplexMatrix sparse_complex_matrix_value(bool=false) 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 as_double(void) 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)
type_conv_info numeric_conversion_function(void) const
mxArray * as_mxArray(bool interleaved) const
boolNDArray bool_array_value(bool=false) const
static int static_type_id(void)
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)
class OCTAVE_API boolNDArray
class OCTAVE_API ComplexMatrix
class OCTAVE_API SparseMatrix
class OCTAVE_API ComplexNDArray
class OCTAVE_API SparseComplexMatrix
std::complex< double > Complex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
static octave_base_value * default_numeric_conversion_function(const octave_base_value &a)