26 #if defined (HAVE_CONFIG_H)
67 std::string nm =
'<' +
type_name () +
'>';
106 "real sparse matrix",
"real scalar");
120 "real sparse matrix",
"complex scalar");
136 if (
m.any_element_is_nan ())
138 if (warn &&
m.any_element_not_one_or_zero ())
228 ::warning (
"range error for conversion to character value");
233 chm(
matrix.
ridx (i) + j * nr) =
static_cast<char> (ival);
265 os.write (
reinterpret_cast<char *
> (&itmp), 4);
268 os.write (
reinterpret_cast<char *
> (&itmp), 4);
271 os.write (
reinterpret_cast<char *
> (&itmp), 4);
274 os.write (
reinterpret_cast<char *
> (&itmp), 4);
281 warning (
"save: some values too large to save as floats --");
282 warning (
"save: saving as doubles instead");
289 double max_val, min_val;
296 for (
int i = 0; i < nc+1; i++)
300 os.write (
reinterpret_cast<char *
> (&itmp), 4);
303 for (
int i = 0; i < nz; i++)
307 os.write (
reinterpret_cast<char *
> (&itmp), 4);
319 int32_t nz, nc, nr, tmp;
322 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
329 error (
"load: only 2-D sparse matrices are supported");
331 if (! is.read (
reinterpret_cast<char *
> (&nr), 4))
333 if (! is.read (
reinterpret_cast<char *
> (&nc), 4))
335 if (! is.read (
reinterpret_cast<char *
> (&nz), 4))
349 for (
int i = 0; i < nc+1; i++)
352 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
359 for (
int i = 0; i < nz; i++)
362 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
369 if (! is.read (
reinterpret_cast<char *
> (&ctmp), 1))
377 if (!
m.indices_ok ())
391 #if defined (HAVE_HDF5)
401 #if defined (HAVE_HDF5_18)
405 hid_t group_hid = H5Gcreate (loc_id,
name, 0);
410 hid_t space_hid, data_hid;
411 space_hid = data_hid = -1;
416 space_hid = H5Screate_simple (0, hdims,
nullptr);
419 H5Gclose (group_hid);
422 #if defined (HAVE_HDF5_18)
431 H5Sclose (space_hid);
432 H5Gclose (group_hid);
442 H5Sclose (space_hid);
443 H5Gclose (group_hid);
446 #if defined (HAVE_HDF5_18)
455 H5Sclose (space_hid);
456 H5Gclose (group_hid);
466 H5Sclose (space_hid);
467 H5Gclose (group_hid);
471 #if defined (HAVE_HDF5_18)
480 H5Sclose (space_hid);
481 H5Gclose (group_hid);
491 H5Sclose (space_hid);
492 H5Gclose (group_hid);
496 H5Sclose (space_hid);
498 hdims[0] =
m.cols () + 1;
501 space_hid = H5Screate_simple (2, hdims,
nullptr);
505 H5Gclose (group_hid);
509 #if defined (HAVE_HDF5_18)
510 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
513 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
518 H5Sclose (space_hid);
519 H5Gclose (group_hid);
529 H5Sclose (space_hid);
530 H5Gclose (group_hid);
534 H5Sclose (space_hid);
539 space_hid = H5Screate_simple (2, hdims,
nullptr);
543 H5Gclose (group_hid);
546 #if defined (HAVE_HDF5_18)
547 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
550 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
555 H5Sclose (space_hid);
556 H5Gclose (group_hid);
566 H5Sclose (space_hid);
567 H5Gclose (group_hid);
571 hid_t save_type_hid = H5T_NATIVE_DOUBLE;
575 if (
m.too_large_for_float ())
577 warning (
"save: some values too large to save as floats --");
578 warning (
"save: saving as doubles instead");
581 save_type_hid = H5T_NATIVE_FLOAT;
583 #if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
587 double max_val, min_val;
589 if (
m.all_integers (max_val, min_val))
595 #if defined (HAVE_HDF5_18)
596 data_hid = H5Dcreate (group_hid,
"data", save_type_hid, space_hid,
599 data_hid = H5Dcreate (group_hid,
"data", save_type_hid, space_hid,
604 H5Sclose (space_hid);
605 H5Gclose (group_hid);
609 double *dtmp =
m.xdata ();
613 H5Sclose (space_hid);
614 H5Gclose (group_hid);
617 octave_unused_parameter (loc_id);
618 octave_unused_parameter (
name);
619 octave_unused_parameter (save_as_floats);
632 #if defined (HAVE_HDF5)
635 hid_t group_hid, data_hid, space_hid;
645 #if defined (HAVE_HDF5_18)
648 group_hid = H5Gopen (loc_id,
name);
650 if (group_hid < 0)
return false;
652 #if defined (HAVE_HDF5_18)
655 data_hid = H5Dopen (group_hid,
"nr");
657 space_hid = H5Dget_space (data_hid);
658 rank = H5Sget_simple_extent_ndims (space_hid);
663 H5Gclose (group_hid);
671 H5Gclose (group_hid);
677 #if defined (HAVE_HDF5_18)
680 data_hid = H5Dopen (group_hid,
"nc");
682 space_hid = H5Dget_space (data_hid);
683 rank = H5Sget_simple_extent_ndims (space_hid);
688 H5Gclose (group_hid);
696 H5Gclose (group_hid);
702 #if defined (HAVE_HDF5_18)
705 data_hid = H5Dopen (group_hid,
"nz");
707 space_hid = H5Dget_space (data_hid);
708 rank = H5Sget_simple_extent_ndims (space_hid);
713 H5Gclose (group_hid);
721 H5Gclose (group_hid);
731 #if defined (HAVE_HDF5_18)
734 data_hid = H5Dopen (group_hid,
"cidx");
736 space_hid = H5Dget_space (data_hid);
737 rank = H5Sget_simple_extent_ndims (space_hid);
741 H5Sclose (space_hid);
743 H5Gclose (group_hid);
750 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
752 if (
static_cast<int> (hdims[0]) != nc + 1
753 ||
static_cast<int> (hdims[1]) != 1)
755 H5Sclose (space_hid);
757 H5Gclose (group_hid);
765 H5Sclose (space_hid);
767 H5Gclose (group_hid);
771 H5Sclose (space_hid);
774 #if defined (HAVE_HDF5_18)
777 data_hid = H5Dopen (group_hid,
"ridx");
779 space_hid = H5Dget_space (data_hid);
780 rank = H5Sget_simple_extent_ndims (space_hid);
784 H5Sclose (space_hid);
786 H5Gclose (group_hid);
790 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
792 if (
static_cast<int> (hdims[0]) != nz ||
static_cast<int> (hdims[1]) != 1)
794 H5Sclose (space_hid);
796 H5Gclose (group_hid);
804 H5Sclose (space_hid);
806 H5Gclose (group_hid);
810 H5Sclose (space_hid);
813 #if defined (HAVE_HDF5_18)
816 data_hid = H5Dopen (group_hid,
"data");
818 space_hid = H5Dget_space (data_hid);
819 rank = H5Sget_simple_extent_ndims (space_hid);
823 H5Sclose (space_hid);
825 H5Gclose (group_hid);
829 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
831 if (
static_cast<int> (hdims[0]) != nz ||
static_cast<int> (hdims[1]) != 1)
833 H5Sclose (space_hid);
835 H5Gclose (group_hid);
839 double *dtmp =
m.xdata ();
849 H5Sclose (space_hid);
851 H5Gclose (group_hid);
854 octave_unused_parameter (loc_id);
855 octave_unused_parameter (
name);
870 double *pr =
static_cast<double *
> (
retval->get_data ());
874 for (
mwIndex i = 0; i < nz; i++)
880 for (
mwIndex i = 0; i < nc + 1; i++)
899 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \
900 case umap_ ## UMAP: \
901 return octave_value (matrix.FCN ())
905 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \
906 case umap_ ## UMAP: \
907 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)
bool all_integers(double &max_val, double &min_val) const
Matrix matrix_value(void) const
bool any_element_is_nan(void) const
bool too_large_for_float(void) const
bool any_element_not_one_or_zero(void) const
octave_idx_type numel(void) const
octave_idx_type cols(void) const
octave_idx_type * cidx(void)
octave_idx_type nnz(void) const
Actual number of nonzero terms.
void resize(octave_idx_type r, octave_idx_type c)
octave_idx_type rows(void) const
size_t byte_size(void) const
Sparse< T > maybe_compress(bool remove_zeros=false)
octave_idx_type * ridx(void)
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.
octave_idx_type nnz(void) const
octave_idx_type nzmax(void) const
octave_idx_type numel(void) const
octave_value map(octave_base_value::unary_mapper_t umap) const
dim_vector dims(void) const
octave_idx_type columns(void) const
void warn_load(const char *type) const
octave_idx_type rows(void) const
friend class octave_value
void warn_save(const char *type) const
octave_base_value * try_narrowing_conversion(void)
NDArray array_value(bool=false) const
octave_value as_double(void) 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
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)
mxArray * as_mxArray(void) const
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)
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
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)
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)
Complex atan(const Complex &x)
Complex rc_acos(double x)
Complex log1p(const Complex &x)
Complex acos(const Complex &x)
Complex asin(const Complex &x)
Complex rc_log2(double x)
Complex erfc(const Complex &x)
Complex rc_sqrt(double x)
Complex rc_atanh(double x)
std::complex< T > ceil(const std::complex< T > &x)
Complex rc_acosh(double x)
Complex rc_log1p(double x)
Complex rc_log10(double x)
Complex rc_lgamma(double x)
Complex rc_asin(double x)
Complex log2(const Complex &x)
std::complex< T > floor(const std::complex< T > &x)
Complex erf(const Complex &x)
Complex expm1(const Complex &x)
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)
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)
octave_value::octave_value(const Array< char > &chm, char type) return retval