26#if defined (HAVE_CONFIG_H)
52 "sparse complex matrix",
"double");
64 if (! force_conversion)
66 "complex sparse matrix",
"real scalar");
74 "complex sparse matrix",
"real scalar");
76 return std::real (
matrix(0, 0));
84 if (! force_conversion)
86 "complex sparse matrix",
"real matrix");
102 "complex sparse matrix",
"real scalar");
126 "sparse complex matrix",
"string");
136 =
static_cast<char> (std::real (
matrix.
data (i)));
147 if (! force_conversion)
149 "complex sparse matrix",
150 "real sparse matrix");
161 octave::err_nan_to_logical_conversion ();
163 ||
real (
matrix).any_element_not_one_or_zero ()))
193 os.write (
reinterpret_cast<char *
> (&itmp), 4);
196 os.write (
reinterpret_cast<char *
> (&itmp), 4);
199 os.write (
reinterpret_cast<char *
> (&itmp), 4);
202 os.write (
reinterpret_cast<char *
> (&itmp), 4);
209 warning (
"save: some values too large to save as floats --");
210 warning (
"save: saving as doubles instead");
217 double max_val, min_val;
219 st = octave::get_save_type (max_val, min_val);
224 for (
int i = 0; i < nc+1; i++)
228 os.write (
reinterpret_cast<char *
> (&itmp), 4);
231 for (
int i = 0; i < nz; i++)
235 os.write (
reinterpret_cast<char *
> (&itmp), 4);
246 octave::mach_info::float_format fmt)
248 int32_t nz, nc, nr, tmp;
251 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
258 error (
"load: only 2-D sparse matrices are supported");
260 if (! is.read (
reinterpret_cast<char *
> (&nr), 4))
262 if (! is.read (
reinterpret_cast<char *
> (&nc), 4))
264 if (! is.read (
reinterpret_cast<char *
> (&nz), 4))
278 for (
int i = 0; i < nc+1; i++)
281 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
288 for (
int i = 0; i < nz; i++)
291 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
298 if (! is.read (
reinterpret_cast<char *
> (&ctmp), 1))
302 static_cast<save_type> (ctmp), 2 * nz, swap, fmt);
322#if defined (HAVE_HDF5)
332#if defined (HAVE_HDF5_18)
336 hid_t group_hid = H5Gcreate (loc_id, name, 0);
341 hid_t space_hid, data_hid;
342 space_hid = data_hid = -1;
347 space_hid = H5Screate_simple (0, hdims,
nullptr);
350 H5Gclose (group_hid);
354#if defined (HAVE_HDF5_18)
364 H5Sclose (space_hid);
365 H5Gclose (group_hid);
375 H5Sclose (space_hid);
376 H5Gclose (group_hid);
380#if defined (HAVE_HDF5_18)
390 H5Sclose (space_hid);
391 H5Gclose (group_hid);
401 H5Sclose (space_hid);
402 H5Gclose (group_hid);
406#if defined (HAVE_HDF5_18)
416 H5Sclose (space_hid);
417 H5Gclose (group_hid);
427 H5Sclose (space_hid);
428 H5Gclose (group_hid);
432 H5Sclose (space_hid);
434 hdims[0] = m.
cols () + 1;
437 space_hid = H5Screate_simple (2, hdims,
nullptr);
441 H5Gclose (group_hid);
445#if defined (HAVE_HDF5_18)
446 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
450 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
455 H5Sclose (space_hid);
456 H5Gclose (group_hid);
466 H5Sclose (space_hid);
467 H5Gclose (group_hid);
471 H5Sclose (space_hid);
476 space_hid = H5Screate_simple (2, hdims,
nullptr);
480 H5Gclose (group_hid);
484#if defined (HAVE_HDF5_18)
485 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
489 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
494 H5Sclose (space_hid);
495 H5Gclose (group_hid);
505 H5Sclose (space_hid);
506 H5Gclose (group_hid);
510 hid_t save_type_hid = H5T_NATIVE_DOUBLE;
516 warning (
"save: some values too large to save as floats --");
517 warning (
"save: saving as doubles instead");
520 save_type_hid = H5T_NATIVE_FLOAT;
522#if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
526 double max_val, min_val;
537 H5Sclose (space_hid);
538 H5Gclose (group_hid);
541#if defined (HAVE_HDF5_18)
542 data_hid = H5Dcreate (group_hid,
"data", type_hid, space_hid,
546 data_hid = H5Dcreate (group_hid,
"data", type_hid, space_hid,
551 H5Sclose (space_hid);
553 H5Gclose (group_hid);
559 if (complex_type_hid >= 0)
568 H5Sclose (space_hid);
570 H5Gclose (group_hid);
573 octave_unused_parameter (loc_id);
574 octave_unused_parameter (name);
575 octave_unused_parameter (save_as_floats);
589#if defined (HAVE_HDF5)
592 hid_t group_hid, data_hid, space_hid;
602#if defined (HAVE_HDF5_18)
605 group_hid = H5Gopen (loc_id, name);
607 if (group_hid < 0)
return false;
609#if defined (HAVE_HDF5_18)
612 data_hid = H5Dopen (group_hid,
"nr");
614 space_hid = H5Dget_space (data_hid);
615 rank = H5Sget_simple_extent_ndims (space_hid);
620 H5Gclose (group_hid);
628 H5Gclose (group_hid);
634#if defined (HAVE_HDF5_18)
637 data_hid = H5Dopen (group_hid,
"nc");
639 space_hid = H5Dget_space (data_hid);
640 rank = H5Sget_simple_extent_ndims (space_hid);
645 H5Gclose (group_hid);
653 H5Gclose (group_hid);
659#if defined (HAVE_HDF5_18)
662 data_hid = H5Dopen (group_hid,
"nz");
664 space_hid = H5Dget_space (data_hid);
665 rank = H5Sget_simple_extent_ndims (space_hid);
670 H5Gclose (group_hid);
678 H5Gclose (group_hid);
688#if defined (HAVE_HDF5_18)
691 data_hid = H5Dopen (group_hid,
"cidx");
693 space_hid = H5Dget_space (data_hid);
694 rank = H5Sget_simple_extent_ndims (space_hid);
698 H5Sclose (space_hid);
700 H5Gclose (group_hid);
707 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
709 if (
static_cast<int> (hdims[0]) != nc + 1
710 ||
static_cast<int> (hdims[1]) != 1)
712 H5Sclose (space_hid);
714 H5Gclose (group_hid);
722 H5Sclose (space_hid);
724 H5Gclose (group_hid);
728 H5Sclose (space_hid);
731#if defined (HAVE_HDF5_18)
734 data_hid = H5Dopen (group_hid,
"ridx");
736 space_hid = H5Dget_space (data_hid);
737 rank = H5Sget_simple_extent_ndims (space_hid);
741 H5Sclose (space_hid);
743 H5Gclose (group_hid);
747 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
749 if (
static_cast<int> (hdims[0]) != nz
750 ||
static_cast<int> (hdims[1]) != 1)
752 H5Sclose (space_hid);
754 H5Gclose (group_hid);
762 H5Sclose (space_hid);
764 H5Gclose (group_hid);
768 H5Sclose (space_hid);
771#if defined (HAVE_HDF5_18)
774 data_hid = H5Dopen (group_hid,
"data");
776 hid_t type_hid = H5Dget_type (data_hid);
782 H5Tclose (complex_type);
784 H5Gclose (group_hid);
788 space_hid = H5Dget_space (data_hid);
789 rank = H5Sget_simple_extent_ndims (space_hid);
793 H5Sclose (space_hid);
795 H5Gclose (group_hid);
799 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
801 if (
static_cast<int> (hdims[0]) != nz
802 ||
static_cast<int> (hdims[1]) != 1)
804 H5Sclose (space_hid);
806 H5Gclose (group_hid);
820 H5Tclose (complex_type);
821 H5Sclose (space_hid);
823 H5Gclose (group_hid);
826 octave_unused_parameter (loc_id);
827 octave_unused_parameter (name);
838 mwSize nz =
nzmax ();
842 mxArray *retval =
new mxArray (interleaved, mxDOUBLE_CLASS, nr, nc, nz,
845 mwIndex *ir = retval->
get_ir ();
853 =
static_cast<mxComplexDouble *
> (retval->
get_data ());
855 for (mwIndex i = 0; i < nz; i++)
857 pd[i].real = pdata[i].real ();
858 pd[i].imag = pdata[i].imag ();
865 mxDouble *pr =
static_cast<mxDouble *
> (retval->
get_data ());
866 mxDouble *pi =
static_cast<mxDouble *
> (retval->
get_imag_data ());
868 for (mwIndex i = 0; i < nz; i++)
870 pr[i] = pdata[i].real ();
871 pi[i] = pdata[i].imag ();
877 mwIndex *jc = retval->
get_jc ();
881 for (mwIndex i = 0; i < nc + 1; i++)
898#define ARRAY_METHOD_MAPPER(UMAP, FCN) \
899 case umap_ ## UMAP: \
900 return octave_value (matrix.FCN ())
904#define ARRAY_MAPPER(UMAP, TYPE, FCN) \
905 case umap_ ## UMAP: \
906 return octave_value (matrix.map<TYPE> (FCN))
ComplexColumnVector conj(const ComplexColumnVector &a)
boolMatrix mx_el_ne(const boolMatrix &m1, const boolMatrix &m2)
void swap_bytes< 4 >(void *ptr)
bool too_large_for_float() const
ComplexMatrix matrix_value() const
bool all_elements_are_real() const
bool any_element_is_nan() const
bool all_integers(double &max_val, double &min_val) const
octave_idx_type cols() const
void resize(octave_idx_type r, octave_idx_type c)
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 ndims() const
Number of dimensions.
void * get_imag_data() const
SparseComplexMatrix matrix
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
void warn_save(const char *type) const
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
octave_value map(unary_mapper_t umap) const
Complex complex_value(bool=false) const
SparseBoolMatrix sparse_bool_matrix_value(bool warn=false) const
octave_base_value * try_narrowing_conversion()
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
ComplexNDArray complex_array_value(bool=false) const
octave_value as_double() const
Matrix matrix_value(bool=false) const
double double_value(bool=false) const
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
ComplexMatrix complex_matrix_value(bool=false) const
mxArray * as_mxArray(bool interleaved) const
SparseMatrix sparse_matrix_value(bool=false) const
charNDArray char_array_value(bool frc_str_conv=false) const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
bool save_binary(std::ostream &os, bool save_as_floats)
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
ColumnVector real(const ComplexColumnVector &a)
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)
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)
octave_hdf5_id hdf5_make_complex_type(octave_hdf5_id num_type)
bool hdf5_types_compatible(octave_hdf5_id t1, octave_hdf5_id t2)
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)