26 #if defined (HAVE_CONFIG_H)
58 "sparse complex matrix",
"double");
85 else if (nr == 0 || nc == 0)
111 if (! force_conversion)
113 "complex sparse matrix",
"real scalar");
121 "complex sparse matrix",
"real scalar");
131 if (! force_conversion)
133 "complex sparse matrix",
"real matrix");
149 "complex sparse matrix",
"real scalar");
173 "sparse complex matrix",
"string");
194 if (! force_conversion)
196 "complex sparse matrix",
197 "real sparse matrix");
210 ||
real (
matrix).any_element_not_one_or_zero ()))
240 os.write (
reinterpret_cast<char *
> (&itmp), 4);
243 os.write (
reinterpret_cast<char *
> (&itmp), 4);
246 os.write (
reinterpret_cast<char *
> (&itmp), 4);
249 os.write (
reinterpret_cast<char *
> (&itmp), 4);
256 warning (
"save: some values too large to save as floats --");
257 warning (
"save: saving as doubles instead");
264 double max_val, min_val;
271 for (
int i = 0; i < nc+1; i++)
275 os.write (
reinterpret_cast<char *
> (&itmp), 4);
278 for (
int i = 0; i < nz; i++)
282 os.write (
reinterpret_cast<char *
> (&itmp), 4);
295 int32_t nz, nc, nr, tmp;
298 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
305 error (
"load: only 2-D sparse matrices are supported");
307 if (! is.read (
reinterpret_cast<char *
> (&nr), 4))
309 if (! is.read (
reinterpret_cast<char *
> (&nc), 4))
311 if (! is.read (
reinterpret_cast<char *
> (&nz), 4))
325 for (
int i = 0; i < nc+1; i++)
328 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
335 for (
int i = 0; i < nz; i++)
338 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
345 if (! is.read (
reinterpret_cast<char *
> (&ctmp), 1))
349 static_cast<save_type> (ctmp), 2 * nz, swap, fmt);
354 if (!
m.indices_ok ())
369 #if defined (HAVE_HDF5)
379 #if defined (HAVE_HDF5_18)
383 hid_t group_hid = H5Gcreate (loc_id,
name, 0);
388 hid_t space_hid, data_hid;
389 space_hid = data_hid = -1;
394 space_hid = H5Screate_simple (0, hdims,
nullptr);
397 H5Gclose (group_hid);
401 #if defined (HAVE_HDF5_18)
410 H5Sclose (space_hid);
411 H5Gclose (group_hid);
421 H5Sclose (space_hid);
422 H5Gclose (group_hid);
426 #if defined (HAVE_HDF5_18)
435 H5Sclose (space_hid);
436 H5Gclose (group_hid);
446 H5Sclose (space_hid);
447 H5Gclose (group_hid);
451 #if defined (HAVE_HDF5_18)
460 H5Sclose (space_hid);
461 H5Gclose (group_hid);
471 H5Sclose (space_hid);
472 H5Gclose (group_hid);
476 H5Sclose (space_hid);
478 hdims[0] =
m.cols () + 1;
481 space_hid = H5Screate_simple (2, hdims,
nullptr);
485 H5Gclose (group_hid);
489 #if defined (HAVE_HDF5_18)
490 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
493 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
498 H5Sclose (space_hid);
499 H5Gclose (group_hid);
509 H5Sclose (space_hid);
510 H5Gclose (group_hid);
514 H5Sclose (space_hid);
519 space_hid = H5Screate_simple (2, hdims,
nullptr);
523 H5Gclose (group_hid);
527 #if defined (HAVE_HDF5_18)
528 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
531 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
536 H5Sclose (space_hid);
537 H5Gclose (group_hid);
547 H5Sclose (space_hid);
548 H5Gclose (group_hid);
552 hid_t save_type_hid = H5T_NATIVE_DOUBLE;
556 if (
m.too_large_for_float ())
558 warning (
"save: some values too large to save as floats --");
559 warning (
"save: saving as doubles instead");
562 save_type_hid = H5T_NATIVE_FLOAT;
564 #if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
568 double max_val, min_val;
570 if (
m.all_integers (max_val, min_val))
579 H5Sclose (space_hid);
580 H5Gclose (group_hid);
583 #if defined (HAVE_HDF5_18)
584 data_hid = H5Dcreate (group_hid,
"data", type_hid, space_hid,
587 data_hid = H5Dcreate (group_hid,
"data", type_hid, space_hid,
592 H5Sclose (space_hid);
594 H5Gclose (group_hid);
600 if (complex_type_hid >= 0)
609 H5Sclose (space_hid);
611 H5Gclose (group_hid);
614 octave_unused_parameter (loc_id);
615 octave_unused_parameter (
name);
616 octave_unused_parameter (save_as_floats);
630 #if defined (HAVE_HDF5)
633 hid_t group_hid, data_hid, space_hid;
643 #if defined (HAVE_HDF5_18)
646 group_hid = H5Gopen (loc_id,
name);
648 if (group_hid < 0)
return false;
650 #if defined (HAVE_HDF5_18)
653 data_hid = H5Dopen (group_hid,
"nr");
655 space_hid = H5Dget_space (data_hid);
656 rank = H5Sget_simple_extent_ndims (space_hid);
661 H5Gclose (group_hid);
669 H5Gclose (group_hid);
675 #if defined (HAVE_HDF5_18)
678 data_hid = H5Dopen (group_hid,
"nc");
680 space_hid = H5Dget_space (data_hid);
681 rank = H5Sget_simple_extent_ndims (space_hid);
686 H5Gclose (group_hid);
694 H5Gclose (group_hid);
700 #if defined (HAVE_HDF5_18)
703 data_hid = H5Dopen (group_hid,
"nz");
705 space_hid = H5Dget_space (data_hid);
706 rank = H5Sget_simple_extent_ndims (space_hid);
711 H5Gclose (group_hid);
719 H5Gclose (group_hid);
729 #if defined (HAVE_HDF5_18)
732 data_hid = H5Dopen (group_hid,
"cidx");
734 space_hid = H5Dget_space (data_hid);
735 rank = H5Sget_simple_extent_ndims (space_hid);
739 H5Sclose (space_hid);
741 H5Gclose (group_hid);
748 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
750 if (
static_cast<int> (hdims[0]) != nc + 1
751 ||
static_cast<int> (hdims[1]) != 1)
753 H5Sclose (space_hid);
755 H5Gclose (group_hid);
763 H5Sclose (space_hid);
765 H5Gclose (group_hid);
769 H5Sclose (space_hid);
772 #if defined (HAVE_HDF5_18)
775 data_hid = H5Dopen (group_hid,
"ridx");
777 space_hid = H5Dget_space (data_hid);
778 rank = H5Sget_simple_extent_ndims (space_hid);
782 H5Sclose (space_hid);
784 H5Gclose (group_hid);
788 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
790 if (
static_cast<int> (hdims[0]) != nz
791 ||
static_cast<int> (hdims[1]) != 1)
793 H5Sclose (space_hid);
795 H5Gclose (group_hid);
803 H5Sclose (space_hid);
805 H5Gclose (group_hid);
809 H5Sclose (space_hid);
812 #if defined (HAVE_HDF5_18)
815 data_hid = H5Dopen (group_hid,
"data");
817 hid_t type_hid = H5Dget_type (data_hid);
823 H5Tclose (complex_type);
825 H5Gclose (group_hid);
829 space_hid = H5Dget_space (data_hid);
830 rank = H5Sget_simple_extent_ndims (space_hid);
834 H5Sclose (space_hid);
836 H5Gclose (group_hid);
840 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
842 if (
static_cast<int> (hdims[0]) != nz
843 ||
static_cast<int> (hdims[1]) != 1)
845 H5Sclose (space_hid);
847 H5Gclose (group_hid);
861 H5Tclose (complex_type);
862 H5Sclose (space_hid);
864 H5Gclose (group_hid);
867 octave_unused_parameter (loc_id);
868 octave_unused_parameter (
name);
882 double *pr =
static_cast<double *
> (
retval->get_data ());
883 double *
pi =
static_cast<double *
> (
retval->get_imag_data ());
887 for (
mwIndex i = 0; i < nz; i++)
912 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \
913 case umap_ ## UMAP: \
914 return octave_value (matrix.FCN ())
918 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \
919 case umap_ ## UMAP: \
920 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 any_element_is_nan(void) const
bool all_elements_are_real(void) const
bool all_integers(double &max_val, double &min_val) const
bool too_large_for_float(void) const
ComplexMatrix matrix_value(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 ndims(void) const
Number of dimensions.
octave_idx_type nnz(void) const
SparseComplexMatrix matrix
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
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
octave_value as_double(void) const
SparseBoolMatrix sparse_bool_matrix_value(bool warn=false) const
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
ComplexNDArray complex_array_value(bool=false) const
Matrix matrix_value(bool=false) const
octave_base_value * try_narrowing_conversion(void)
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
SparseMatrix sparse_matrix_value(bool=false) const
charNDArray char_array_value(bool frc_str_conv=false) const
mxArray * as_mxArray(void) 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)
ColumnVector imag(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)
void warn_implicit_conversion(const char *id, const char *from, const char *to)
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)
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 log1p(const Complex &x)
Complex acos(const Complex &x)
Complex asin(const Complex &x)
Complex erfc(const Complex &x)
std::complex< T > ceil(const std::complex< T > &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_nan_to_logical_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