26#if defined (HAVE_CONFIG_H)
62 std::string nm =
'<' +
type_name () +
'>';
63 octave::err_invalid_index (nm.c_str ());
75 "real sparse matrix",
"real scalar");
89 "real sparse matrix",
"complex scalar");
106 octave::err_nan_to_logical_conversion ();
152 octave::err_nan_to_logical_conversion ();
187 if (octave::math::isnan (
d))
188 octave::err_nan_to_character_conversion ();
190 int ival = octave::math::nint (
d);
192 if (ival < 0 || ival > std::numeric_limits<unsigned char>::max ())
200 ::warning (
"range error for conversion to character value");
205 chm(
matrix.
ridx (i) + j * nr) =
static_cast<char> (ival);
237 os.write (
reinterpret_cast<char *
> (&itmp), 4);
240 os.write (
reinterpret_cast<char *
> (&itmp), 4);
243 os.write (
reinterpret_cast<char *
> (&itmp), 4);
246 os.write (
reinterpret_cast<char *
> (&itmp), 4);
253 warning (
"save: some values too large to save as floats --");
254 warning (
"save: saving as doubles instead");
261 double max_val, min_val;
263 st = octave::get_save_type (max_val, min_val);
268 for (
int i = 0; i < nc+1; i++)
272 os.write (
reinterpret_cast<char *
> (&itmp), 4);
275 for (
int i = 0; i < nz; i++)
279 os.write (
reinterpret_cast<char *
> (&itmp), 4);
289 octave::mach_info::float_format fmt)
291 int32_t nz, nc, nr, tmp;
294 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
301 error (
"load: only 2-D sparse matrices are supported");
303 if (! is.read (
reinterpret_cast<char *
> (&nr), 4))
305 if (! is.read (
reinterpret_cast<char *
> (&nc), 4))
307 if (! is.read (
reinterpret_cast<char *
> (&nz), 4))
321 for (
int i = 0; i < nc+1; i++)
324 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
331 for (
int i = 0; i < nz; i++)
334 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
341 if (! is.read (
reinterpret_cast<char *
> (&ctmp), 1))
363#if defined (HAVE_HDF5)
373#if defined (HAVE_HDF5_18)
377 hid_t group_hid = H5Gcreate (loc_id, name, 0);
382 hid_t space_hid, data_hid;
383 space_hid = data_hid = -1;
388 space_hid = H5Screate_simple (0, hdims,
nullptr);
391 H5Gclose (group_hid);
394#if defined (HAVE_HDF5_18)
404 H5Sclose (space_hid);
405 H5Gclose (group_hid);
415 H5Sclose (space_hid);
416 H5Gclose (group_hid);
419#if defined (HAVE_HDF5_18)
429 H5Sclose (space_hid);
430 H5Gclose (group_hid);
440 H5Sclose (space_hid);
441 H5Gclose (group_hid);
445#if defined (HAVE_HDF5_18)
455 H5Sclose (space_hid);
456 H5Gclose (group_hid);
466 H5Sclose (space_hid);
467 H5Gclose (group_hid);
471 H5Sclose (space_hid);
473 hdims[0] = m.
cols () + 1;
476 space_hid = H5Screate_simple (2, hdims,
nullptr);
480 H5Gclose (group_hid);
484#if defined (HAVE_HDF5_18)
485 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
489 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
494 H5Sclose (space_hid);
495 H5Gclose (group_hid);
505 H5Sclose (space_hid);
506 H5Gclose (group_hid);
510 H5Sclose (space_hid);
515 space_hid = H5Screate_simple (2, hdims,
nullptr);
519 H5Gclose (group_hid);
522#if defined (HAVE_HDF5_18)
523 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
527 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
532 H5Sclose (space_hid);
533 H5Gclose (group_hid);
543 H5Sclose (space_hid);
544 H5Gclose (group_hid);
548 hid_t save_type_hid = H5T_NATIVE_DOUBLE;
554 warning (
"save: some values too large to save as floats --");
555 warning (
"save: saving as doubles instead");
558 save_type_hid = H5T_NATIVE_FLOAT;
560#if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
564 double max_val, min_val;
572#if defined (HAVE_HDF5_18)
573 data_hid = H5Dcreate (group_hid,
"data", save_type_hid, space_hid,
577 data_hid = H5Dcreate (group_hid,
"data", save_type_hid, space_hid,
582 H5Sclose (space_hid);
583 H5Gclose (group_hid);
587 double *dtmp = m.
xdata ();
591 H5Sclose (space_hid);
592 H5Gclose (group_hid);
595 octave_unused_parameter (loc_id);
596 octave_unused_parameter (name);
597 octave_unused_parameter (save_as_floats);
610#if defined (HAVE_HDF5)
613 hid_t group_hid, data_hid, space_hid;
623#if defined (HAVE_HDF5_18)
626 group_hid = H5Gopen (loc_id, name);
628 if (group_hid < 0)
return false;
630#if defined (HAVE_HDF5_18)
633 data_hid = H5Dopen (group_hid,
"nr");
635 space_hid = H5Dget_space (data_hid);
636 rank = H5Sget_simple_extent_ndims (space_hid);
641 H5Gclose (group_hid);
649 H5Gclose (group_hid);
655#if defined (HAVE_HDF5_18)
658 data_hid = H5Dopen (group_hid,
"nc");
660 space_hid = H5Dget_space (data_hid);
661 rank = H5Sget_simple_extent_ndims (space_hid);
666 H5Gclose (group_hid);
674 H5Gclose (group_hid);
680#if defined (HAVE_HDF5_18)
683 data_hid = H5Dopen (group_hid,
"nz");
685 space_hid = H5Dget_space (data_hid);
686 rank = H5Sget_simple_extent_ndims (space_hid);
691 H5Gclose (group_hid);
699 H5Gclose (group_hid);
709#if defined (HAVE_HDF5_18)
712 data_hid = H5Dopen (group_hid,
"cidx");
714 space_hid = H5Dget_space (data_hid);
715 rank = H5Sget_simple_extent_ndims (space_hid);
719 H5Sclose (space_hid);
721 H5Gclose (group_hid);
728 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
730 if (
static_cast<int> (hdims[0]) != nc + 1
731 ||
static_cast<int> (hdims[1]) != 1)
733 H5Sclose (space_hid);
735 H5Gclose (group_hid);
743 H5Sclose (space_hid);
745 H5Gclose (group_hid);
749 H5Sclose (space_hid);
752#if defined (HAVE_HDF5_18)
755 data_hid = H5Dopen (group_hid,
"ridx");
757 space_hid = H5Dget_space (data_hid);
758 rank = H5Sget_simple_extent_ndims (space_hid);
762 H5Sclose (space_hid);
764 H5Gclose (group_hid);
768 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
770 if (
static_cast<int> (hdims[0]) != nz ||
static_cast<int> (hdims[1]) != 1)
772 H5Sclose (space_hid);
774 H5Gclose (group_hid);
782 H5Sclose (space_hid);
784 H5Gclose (group_hid);
788 H5Sclose (space_hid);
791#if defined (HAVE_HDF5_18)
794 data_hid = H5Dopen (group_hid,
"data");
796 space_hid = H5Dget_space (data_hid);
797 rank = H5Sget_simple_extent_ndims (space_hid);
801 H5Sclose (space_hid);
803 H5Gclose (group_hid);
807 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
809 if (
static_cast<int> (hdims[0]) != nz ||
static_cast<int> (hdims[1]) != 1)
811 H5Sclose (space_hid);
813 H5Gclose (group_hid);
817 double *dtmp = m.
xdata ();
827 H5Sclose (space_hid);
829 H5Gclose (group_hid);
832 octave_unused_parameter (loc_id);
833 octave_unused_parameter (name);
844 mwSize nz =
nzmax ();
848 mxArray *retval =
new mxArray (interleaved, mxDOUBLE_CLASS, nr, nc, nz,
851 mxDouble *pd =
static_cast<mxDouble *
> (retval->
get_data ());
852 mwIndex *ir = retval->
get_ir ();
857 for (mwIndex i = 0; i < nz; i++)
864 mwIndex *jc = retval->
get_jc ();
868 for (mwIndex i = 0; i < nc + 1; i++)
887#define ARRAY_METHOD_MAPPER(UMAP, FCN) \
888 case umap_ ## UMAP: \
889 return octave_value (matrix.FCN ())
893#define ARRAY_MAPPER(UMAP, TYPE, FCN) \
894 case umap_ ## UMAP: \
895 return octave_value (matrix.map<TYPE> (FCN))
boolMatrix mx_el_ne(const boolMatrix &m1, const boolMatrix &m2)
void swap_bytes< 4 >(void *ptr)
bool any_element_not_one_or_zero() const
bool any_element_is_nan() const
bool any_element_not_one_or_zero() const
bool all_integers(double &max_val, double &min_val) const
bool any_element_is_nan() const
bool too_large_for_float() const
Matrix matrix_value() const
octave_idx_type cols() const
void resize(octave_idx_type r, octave_idx_type c)
octave_idx_type numel() const
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 numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
octave_idx_type ndims() const
Number of dimensions.
octave_idx_type nzmax() const
octave_value map(octave_base_value::unary_mapper_t umap) 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
NDArray array_value(bool=false) const
mxArray * as_mxArray(bool interleaved) const
std::string type_name() 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
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
octave_value as_double() 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 warn_implicit_conversion(const char *id, const char *from, const char *to)
Complex log2(const Complex &x)
Complex asin(const Complex &x)
Complex acos(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)
std::complex< T > ceil(const std::complex< T > &x)
Complex atan(const Complex &x)
std::complex< T > floor(const std::complex< T > &x)
std::complex< double > Complex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Complex erf(const Complex &x)
Complex expm1(const Complex &x)
Complex log1p(const Complex &x)
Complex erfc(const Complex &x)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
#define ARRAY_MAPPER(UMAP, TYPE, FCN)
#define ARRAY_METHOD_MAPPER(UMAP, FCN)
template int8_t abs(int8_t)
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d