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 ();
149 octave::err_nan_to_logical_conversion ();
184 if (octave::math::isnan (
d))
185 octave::err_nan_to_character_conversion ();
187 int ival = octave::math::nint (
d);
189 if (ival < 0 || ival > std::numeric_limits<unsigned char>::max ())
197 ::warning (
"range error for conversion to character value");
202 chm(
matrix.
ridx (i) + j * nr) =
static_cast<char> (ival);
234 os.write (
reinterpret_cast<char *
> (&itmp), 4);
237 os.write (
reinterpret_cast<char *
> (&itmp), 4);
240 os.write (
reinterpret_cast<char *
> (&itmp), 4);
243 os.write (
reinterpret_cast<char *
> (&itmp), 4);
250 warning (
"save: some values too large to save as floats --");
251 warning (
"save: saving as doubles instead");
258 double max_val, min_val;
260 st = octave::get_save_type (max_val, min_val);
265 for (
int i = 0; i < nc+1; i++)
269 os.write (
reinterpret_cast<char *
> (&itmp), 4);
272 for (
int i = 0; i < nz; i++)
276 os.write (
reinterpret_cast<char *
> (&itmp), 4);
286 octave::mach_info::float_format fmt)
288 int32_t nz, nc, nr, tmp;
291 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
298 error (
"load: only 2-D sparse matrices are supported");
300 if (! is.read (
reinterpret_cast<char *
> (&nr), 4))
302 if (! is.read (
reinterpret_cast<char *
> (&nc), 4))
304 if (! is.read (
reinterpret_cast<char *
> (&nz), 4))
318 for (
int i = 0; i < nc+1; i++)
321 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
328 for (
int i = 0; i < nz; i++)
331 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
338 if (! is.read (
reinterpret_cast<char *
> (&ctmp), 1))
360#if defined (HAVE_HDF5)
370#if defined (HAVE_HDF5_18)
374 hid_t group_hid = H5Gcreate (loc_id, name, 0);
379 hid_t space_hid, data_hid;
380 space_hid = data_hid = -1;
385 space_hid = H5Screate_simple (0, hdims,
nullptr);
388 H5Gclose (group_hid);
391#if defined (HAVE_HDF5_18)
401 H5Sclose (space_hid);
402 H5Gclose (group_hid);
412 H5Sclose (space_hid);
413 H5Gclose (group_hid);
416#if defined (HAVE_HDF5_18)
426 H5Sclose (space_hid);
427 H5Gclose (group_hid);
437 H5Sclose (space_hid);
438 H5Gclose (group_hid);
442#if defined (HAVE_HDF5_18)
452 H5Sclose (space_hid);
453 H5Gclose (group_hid);
463 H5Sclose (space_hid);
464 H5Gclose (group_hid);
468 H5Sclose (space_hid);
470 hdims[0] = m.
cols () + 1;
473 space_hid = H5Screate_simple (2, hdims,
nullptr);
477 H5Gclose (group_hid);
481#if defined (HAVE_HDF5_18)
482 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
486 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
491 H5Sclose (space_hid);
492 H5Gclose (group_hid);
502 H5Sclose (space_hid);
503 H5Gclose (group_hid);
507 H5Sclose (space_hid);
512 space_hid = H5Screate_simple (2, hdims,
nullptr);
516 H5Gclose (group_hid);
519#if defined (HAVE_HDF5_18)
520 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
524 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
529 H5Sclose (space_hid);
530 H5Gclose (group_hid);
540 H5Sclose (space_hid);
541 H5Gclose (group_hid);
545 hid_t save_type_hid = H5T_NATIVE_DOUBLE;
551 warning (
"save: some values too large to save as floats --");
552 warning (
"save: saving as doubles instead");
555 save_type_hid = H5T_NATIVE_FLOAT;
557#if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
561 double max_val, min_val;
569#if defined (HAVE_HDF5_18)
570 data_hid = H5Dcreate (group_hid,
"data", save_type_hid, space_hid,
574 data_hid = H5Dcreate (group_hid,
"data", save_type_hid, space_hid,
579 H5Sclose (space_hid);
580 H5Gclose (group_hid);
584 double *dtmp = m.
xdata ();
588 H5Sclose (space_hid);
589 H5Gclose (group_hid);
592 octave_unused_parameter (loc_id);
593 octave_unused_parameter (name);
594 octave_unused_parameter (save_as_floats);
607#if defined (HAVE_HDF5)
610 hid_t group_hid, data_hid, space_hid;
620#if defined (HAVE_HDF5_18)
623 group_hid = H5Gopen (loc_id, name);
625 if (group_hid < 0)
return false;
627#if defined (HAVE_HDF5_18)
630 data_hid = H5Dopen (group_hid,
"nr");
632 space_hid = H5Dget_space (data_hid);
633 rank = H5Sget_simple_extent_ndims (space_hid);
638 H5Gclose (group_hid);
646 H5Gclose (group_hid);
652#if defined (HAVE_HDF5_18)
655 data_hid = H5Dopen (group_hid,
"nc");
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,
"nz");
682 space_hid = H5Dget_space (data_hid);
683 rank = H5Sget_simple_extent_ndims (space_hid);
688 H5Gclose (group_hid);
696 H5Gclose (group_hid);
706#if defined (HAVE_HDF5_18)
709 data_hid = H5Dopen (group_hid,
"cidx");
711 space_hid = H5Dget_space (data_hid);
712 rank = H5Sget_simple_extent_ndims (space_hid);
716 H5Sclose (space_hid);
718 H5Gclose (group_hid);
725 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
727 if (
static_cast<int> (hdims[0]) != nc + 1
728 ||
static_cast<int> (hdims[1]) != 1)
730 H5Sclose (space_hid);
732 H5Gclose (group_hid);
740 H5Sclose (space_hid);
742 H5Gclose (group_hid);
746 H5Sclose (space_hid);
749#if defined (HAVE_HDF5_18)
752 data_hid = H5Dopen (group_hid,
"ridx");
754 space_hid = H5Dget_space (data_hid);
755 rank = H5Sget_simple_extent_ndims (space_hid);
759 H5Sclose (space_hid);
761 H5Gclose (group_hid);
765 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
767 if (
static_cast<int> (hdims[0]) != nz ||
static_cast<int> (hdims[1]) != 1)
769 H5Sclose (space_hid);
771 H5Gclose (group_hid);
779 H5Sclose (space_hid);
781 H5Gclose (group_hid);
785 H5Sclose (space_hid);
788#if defined (HAVE_HDF5_18)
791 data_hid = H5Dopen (group_hid,
"data");
793 space_hid = H5Dget_space (data_hid);
794 rank = H5Sget_simple_extent_ndims (space_hid);
798 H5Sclose (space_hid);
800 H5Gclose (group_hid);
804 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
806 if (
static_cast<int> (hdims[0]) != nz ||
static_cast<int> (hdims[1]) != 1)
808 H5Sclose (space_hid);
810 H5Gclose (group_hid);
814 double *dtmp = m.
xdata ();
824 H5Sclose (space_hid);
826 H5Gclose (group_hid);
829 octave_unused_parameter (loc_id);
830 octave_unused_parameter (name);
841 mwSize nz =
nzmax ();
845 mxArray *retval =
new mxArray (interleaved, mxDOUBLE_CLASS, nr, nc, nz,
848 mxDouble *pd =
static_cast<mxDouble *
> (retval->
get_data ());
849 mwIndex *ir = retval->
get_ir ();
854 for (mwIndex i = 0; i < nz; i++)
861 mwIndex *jc = retval->
get_jc ();
865 for (mwIndex i = 0; i < nc + 1; i++)
884#define ARRAY_METHOD_MAPPER(UMAP, FCN) \
885 case umap_ ## UMAP: \
886 return octave_value (matrix.FCN ())
890#define ARRAY_MAPPER(UMAP, TYPE, FCN) \
891 case umap_ ## UMAP: \
892 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)
std::complex< T > ceil(const std::complex< T > &x)
Complex atan(const Complex &x)
std::complex< T > floor(const std::complex< T > &x)
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
Complex erf(const Complex &x)
Complex expm1(const Complex &x)
Complex log1p(const Complex &x)
Complex erfc(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< 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)
template int8_t abs(int8_t)