26 #if defined (HAVE_CONFIG_H)
67 std::string nm =
'<' +
type_name () +
'>';
80 "real sparse matrix",
"real scalar");
94 "real sparse matrix",
"complex scalar");
110 if (
m.any_element_is_nan ())
112 if (warn &&
m.any_element_not_one_or_zero ())
202 ::warning (
"range error for conversion to character value");
207 chm(
matrix.
ridx (i) + j * nr) =
static_cast<char> (ival);
239 os.write (
reinterpret_cast<char *
> (&itmp), 4);
242 os.write (
reinterpret_cast<char *
> (&itmp), 4);
245 os.write (
reinterpret_cast<char *
> (&itmp), 4);
248 os.write (
reinterpret_cast<char *
> (&itmp), 4);
255 warning (
"save: some values too large to save as floats --");
256 warning (
"save: saving as doubles instead");
263 double max_val, min_val;
270 for (
int i = 0; i < nc+1; i++)
274 os.write (
reinterpret_cast<char *
> (&itmp), 4);
277 for (
int i = 0; i < nz; i++)
281 os.write (
reinterpret_cast<char *
> (&itmp), 4);
293 int32_t nz, nc, nr, tmp;
296 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
303 error (
"load: only 2-D sparse matrices are supported");
305 if (! is.read (
reinterpret_cast<char *
> (&nr), 4))
307 if (! is.read (
reinterpret_cast<char *
> (&nc), 4))
309 if (! is.read (
reinterpret_cast<char *
> (&nz), 4))
323 for (
int i = 0; i < nc+1; i++)
326 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
333 for (
int i = 0; i < nz; i++)
336 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
343 if (! is.read (
reinterpret_cast<char *
> (&ctmp), 1))
351 if (!
m.indices_ok ())
365 #if defined (HAVE_HDF5)
375 #if defined (HAVE_HDF5_18)
379 hid_t group_hid = H5Gcreate (loc_id, name, 0);
384 hid_t space_hid, data_hid;
385 space_hid = data_hid = -1;
390 space_hid = H5Screate_simple (0, hdims,
nullptr);
393 H5Gclose (group_hid);
396 #if defined (HAVE_HDF5_18)
406 H5Sclose (space_hid);
407 H5Gclose (group_hid);
417 H5Sclose (space_hid);
418 H5Gclose (group_hid);
421 #if defined (HAVE_HDF5_18)
431 H5Sclose (space_hid);
432 H5Gclose (group_hid);
442 H5Sclose (space_hid);
443 H5Gclose (group_hid);
447 #if defined (HAVE_HDF5_18)
457 H5Sclose (space_hid);
458 H5Gclose (group_hid);
468 H5Sclose (space_hid);
469 H5Gclose (group_hid);
473 H5Sclose (space_hid);
475 hdims[0] =
m.cols () + 1;
478 space_hid = H5Screate_simple (2, hdims,
nullptr);
482 H5Gclose (group_hid);
486 #if defined (HAVE_HDF5_18)
487 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
491 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
496 H5Sclose (space_hid);
497 H5Gclose (group_hid);
507 H5Sclose (space_hid);
508 H5Gclose (group_hid);
512 H5Sclose (space_hid);
517 space_hid = H5Screate_simple (2, hdims,
nullptr);
521 H5Gclose (group_hid);
524 #if defined (HAVE_HDF5_18)
525 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
529 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
534 H5Sclose (space_hid);
535 H5Gclose (group_hid);
545 H5Sclose (space_hid);
546 H5Gclose (group_hid);
550 hid_t save_type_hid = H5T_NATIVE_DOUBLE;
554 if (
m.too_large_for_float ())
556 warning (
"save: some values too large to save as floats --");
557 warning (
"save: saving as doubles instead");
560 save_type_hid = H5T_NATIVE_FLOAT;
562 #if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
566 double max_val, min_val;
568 if (
m.all_integers (max_val, min_val))
574 #if defined (HAVE_HDF5_18)
575 data_hid = H5Dcreate (group_hid,
"data", save_type_hid, space_hid,
579 data_hid = H5Dcreate (group_hid,
"data", save_type_hid, space_hid,
584 H5Sclose (space_hid);
585 H5Gclose (group_hid);
589 double *dtmp =
m.xdata ();
593 H5Sclose (space_hid);
594 H5Gclose (group_hid);
597 octave_unused_parameter (loc_id);
598 octave_unused_parameter (name);
599 octave_unused_parameter (save_as_floats);
612 #if defined (HAVE_HDF5)
615 hid_t group_hid, data_hid, space_hid;
625 #if defined (HAVE_HDF5_18)
628 group_hid = H5Gopen (loc_id, name);
630 if (group_hid < 0)
return false;
632 #if defined (HAVE_HDF5_18)
635 data_hid = H5Dopen (group_hid,
"nr");
637 space_hid = H5Dget_space (data_hid);
638 rank = H5Sget_simple_extent_ndims (space_hid);
643 H5Gclose (group_hid);
651 H5Gclose (group_hid);
657 #if defined (HAVE_HDF5_18)
660 data_hid = H5Dopen (group_hid,
"nc");
662 space_hid = H5Dget_space (data_hid);
663 rank = H5Sget_simple_extent_ndims (space_hid);
668 H5Gclose (group_hid);
676 H5Gclose (group_hid);
682 #if defined (HAVE_HDF5_18)
685 data_hid = H5Dopen (group_hid,
"nz");
687 space_hid = H5Dget_space (data_hid);
688 rank = H5Sget_simple_extent_ndims (space_hid);
693 H5Gclose (group_hid);
701 H5Gclose (group_hid);
711 #if defined (HAVE_HDF5_18)
714 data_hid = H5Dopen (group_hid,
"cidx");
716 space_hid = H5Dget_space (data_hid);
717 rank = H5Sget_simple_extent_ndims (space_hid);
721 H5Sclose (space_hid);
723 H5Gclose (group_hid);
730 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
732 if (
static_cast<int> (hdims[0]) != nc + 1
733 ||
static_cast<int> (hdims[1]) != 1)
735 H5Sclose (space_hid);
737 H5Gclose (group_hid);
745 H5Sclose (space_hid);
747 H5Gclose (group_hid);
751 H5Sclose (space_hid);
754 #if defined (HAVE_HDF5_18)
757 data_hid = H5Dopen (group_hid,
"ridx");
759 space_hid = H5Dget_space (data_hid);
760 rank = H5Sget_simple_extent_ndims (space_hid);
764 H5Sclose (space_hid);
766 H5Gclose (group_hid);
770 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
772 if (
static_cast<int> (hdims[0]) != nz ||
static_cast<int> (hdims[1]) != 1)
774 H5Sclose (space_hid);
776 H5Gclose (group_hid);
784 H5Sclose (space_hid);
786 H5Gclose (group_hid);
790 H5Sclose (space_hid);
793 #if defined (HAVE_HDF5_18)
796 data_hid = H5Dopen (group_hid,
"data");
798 space_hid = H5Dget_space (data_hid);
799 rank = H5Sget_simple_extent_ndims (space_hid);
803 H5Sclose (space_hid);
805 H5Gclose (group_hid);
809 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
811 if (
static_cast<int> (hdims[0]) != nz ||
static_cast<int> (hdims[1]) != 1)
813 H5Sclose (space_hid);
815 H5Gclose (group_hid);
819 double *dtmp =
m.xdata ();
829 H5Sclose (space_hid);
831 H5Gclose (group_hid);
834 octave_unused_parameter (loc_id);
835 octave_unused_parameter (name);
846 mwSize nz =
nzmax ();
850 mxArray *retval =
new mxArray (interleaved, mxDOUBLE_CLASS, nr, nc, nz,
853 mxDouble *pd =
static_cast<mxDouble *
> (retval->
get_data ());
854 mwIndex *ir = retval->
get_ir ();
859 for (mwIndex i = 0; i < nz; i++)
866 mwIndex *jc = retval->
get_jc ();
870 for (mwIndex i = 0; i < nc + 1; i++)
889 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \
890 case umap_ ## UMAP: \
891 return octave_value (matrix.FCN ())
895 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \
896 case umap_ ## UMAP: \
897 return octave_value (matrix.map<TYPE> (FCN))
boolMatrix mx_el_ne(const boolMatrix &m1, const boolMatrix &m2)
void swap_bytes< 4 >(void *ptr)
charNDArray max(char d, const charNDArray &m)
OCTAVE_API bool all_integers(double &max_val, double &min_val) const
OCTAVE_API Matrix matrix_value(void) const
OCTAVE_API bool any_element_is_nan(void) const
OCTAVE_API bool too_large_for_float(void) const
OCTAVE_API bool any_element_not_one_or_zero(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)
octave_idx_type nnz(void) const
Actual number of nonzero terms.
Sparse< T, Alloc > maybe_compress(bool remove_zeros=false)
octave_idx_type cols(void) const
octave_idx_type numel(void) const
Vector representing the dimensions (size) of an Array.
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
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
OCTINTERP_API octave_value map(octave_base_value::unary_mapper_t umap) 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
NDArray array_value(bool=false) const
octave_value as_double(void) const
mxArray * as_mxArray(bool interleaved) const
ComplexNDArray complex_array_value(bool=false) const
ComplexMatrix complex_matrix_value(bool=false) const
bool save_binary(std::ostream &os, bool save_as_floats)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
Complex complex_value(bool=false) const
std::string type_name(void) const
octave::idx_vector index_vector(bool require_integers=false) const
SparseMatrix sparse_matrix_value(bool=false) const
octave_value map(unary_mapper_t umap) const
octave_value convert_to_str_internal(bool pad, bool force, char type) const
double double_value(bool=false) const
charNDArray char_array_value(bool=false) const
SparseBoolMatrix sparse_bool_matrix_value(bool warn=false) const
Matrix matrix_value(bool=false) const
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
boolNDArray bool_array_value(bool warn=false) const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
void read_doubles(std::istream &is, double *data, save_type type, octave_idx_type len, bool swap, octave::mach_info::float_format fmt)
void write_doubles(std::ostream &os, const double *data, save_type type, octave_idx_type len)
void warning(const char *fmt,...)
void error(const char *fmt,...)
void err_invalid_conversion(const std::string &from, const std::string &to)
void warn_logical_conversion(void)
void warn_implicit_conversion(const char *id, const char *from, const char *to)
octave::idx_vector idx_vector
void err_invalid_index(const std::string &idx, octave_idx_type nd, octave_idx_type dim, const std::string &)
void err_nan_to_logical_conversion(void)
void err_nan_to_character_conversion(void)
Complex log2(const Complex &x)
Complex rc_acosh(double x)
Complex rc_atanh(double x)
Complex asin(const Complex &x)
Complex rc_asin(double x)
Complex rc_acos(double x)
Complex rc_sqrt(double x)
Complex rc_log10(double x)
Complex acos(const Complex &x)
Complex rc_log2(double x)
Complex atan(const Complex &x)
std::complex< T > floor(const std::complex< T > &x)
std::complex< T > ceil(const std::complex< T > &x)
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
Complex rc_log1p(double x)
Complex rc_lgamma(double x)
Complex expm1(const Complex &x)
Complex log1p(const Complex &x)
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)
octave_hdf5_id save_type_to_hdf5(save_type st)
save_type get_save_type(double, double)
class OCTAVE_API boolNDArray
class OCTAVE_API ComplexMatrix
class OCTAVE_API SparseMatrix
class OCTAVE_API ComplexNDArray
std::complex< double > erfc(std::complex< double > z, double relerr=0)
std::complex< double > erfcx(std::complex< double > z, double relerr=0)
std::complex< double > erfi(std::complex< double > z, double relerr=0)
std::complex< double > erf(std::complex< double > z, double relerr=0)
std::complex< double > Complex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
#define ARRAY_MAPPER(UMAP, TYPE, FCN)
#define ARRAY_METHOD_MAPPER(UMAP, FCN)