26 #if defined (HAVE_CONFIG_H)
58 "sparse complex matrix",
"double");
70 if (! force_conversion)
72 "complex sparse matrix",
"real scalar");
80 "complex sparse matrix",
"real scalar");
90 if (! force_conversion)
92 "complex sparse matrix",
"real matrix");
108 "complex sparse matrix",
"real scalar");
132 "sparse complex matrix",
"string");
153 if (! force_conversion)
155 "complex sparse matrix",
156 "real sparse matrix");
169 ||
real (
matrix).any_element_not_one_or_zero ()))
199 os.write (
reinterpret_cast<char *
> (&itmp), 4);
202 os.write (
reinterpret_cast<char *
> (&itmp), 4);
205 os.write (
reinterpret_cast<char *
> (&itmp), 4);
208 os.write (
reinterpret_cast<char *
> (&itmp), 4);
215 warning (
"save: some values too large to save as floats --");
216 warning (
"save: saving as doubles instead");
223 double max_val, min_val;
230 for (
int i = 0; i < nc+1; i++)
234 os.write (
reinterpret_cast<char *
> (&itmp), 4);
237 for (
int i = 0; i < nz; i++)
241 os.write (
reinterpret_cast<char *
> (&itmp), 4);
254 int32_t nz, nc, nr, tmp;
257 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
264 error (
"load: only 2-D sparse matrices are supported");
266 if (! is.read (
reinterpret_cast<char *
> (&nr), 4))
268 if (! is.read (
reinterpret_cast<char *
> (&nc), 4))
270 if (! is.read (
reinterpret_cast<char *
> (&nz), 4))
284 for (
int i = 0; i < nc+1; i++)
287 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
294 for (
int i = 0; i < nz; i++)
297 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
304 if (! is.read (
reinterpret_cast<char *
> (&ctmp), 1))
308 static_cast<save_type> (ctmp), 2 * nz, swap, fmt);
313 if (!
m.indices_ok ())
328 #if defined (HAVE_HDF5)
338 #if defined (HAVE_HDF5_18)
342 hid_t group_hid = H5Gcreate (loc_id, name, 0);
347 hid_t space_hid, data_hid;
348 space_hid = data_hid = -1;
353 space_hid = H5Screate_simple (0, hdims,
nullptr);
356 H5Gclose (group_hid);
360 #if defined (HAVE_HDF5_18)
370 H5Sclose (space_hid);
371 H5Gclose (group_hid);
381 H5Sclose (space_hid);
382 H5Gclose (group_hid);
386 #if defined (HAVE_HDF5_18)
396 H5Sclose (space_hid);
397 H5Gclose (group_hid);
407 H5Sclose (space_hid);
408 H5Gclose (group_hid);
412 #if defined (HAVE_HDF5_18)
422 H5Sclose (space_hid);
423 H5Gclose (group_hid);
433 H5Sclose (space_hid);
434 H5Gclose (group_hid);
438 H5Sclose (space_hid);
440 hdims[0] =
m.cols () + 1;
443 space_hid = H5Screate_simple (2, hdims,
nullptr);
447 H5Gclose (group_hid);
451 #if defined (HAVE_HDF5_18)
452 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
456 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
461 H5Sclose (space_hid);
462 H5Gclose (group_hid);
472 H5Sclose (space_hid);
473 H5Gclose (group_hid);
477 H5Sclose (space_hid);
482 space_hid = H5Screate_simple (2, hdims,
nullptr);
486 H5Gclose (group_hid);
490 #if defined (HAVE_HDF5_18)
491 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
495 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
500 H5Sclose (space_hid);
501 H5Gclose (group_hid);
511 H5Sclose (space_hid);
512 H5Gclose (group_hid);
516 hid_t save_type_hid = H5T_NATIVE_DOUBLE;
520 if (
m.too_large_for_float ())
522 warning (
"save: some values too large to save as floats --");
523 warning (
"save: saving as doubles instead");
526 save_type_hid = H5T_NATIVE_FLOAT;
528 #if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
532 double max_val, min_val;
534 if (
m.all_integers (max_val, min_val))
543 H5Sclose (space_hid);
544 H5Gclose (group_hid);
547 #if defined (HAVE_HDF5_18)
548 data_hid = H5Dcreate (group_hid,
"data", type_hid, space_hid,
552 data_hid = H5Dcreate (group_hid,
"data", type_hid, space_hid,
557 H5Sclose (space_hid);
559 H5Gclose (group_hid);
565 if (complex_type_hid >= 0)
574 H5Sclose (space_hid);
576 H5Gclose (group_hid);
579 octave_unused_parameter (loc_id);
580 octave_unused_parameter (name);
581 octave_unused_parameter (save_as_floats);
595 #if defined (HAVE_HDF5)
598 hid_t group_hid, data_hid, space_hid;
608 #if defined (HAVE_HDF5_18)
611 group_hid = H5Gopen (loc_id, name);
613 if (group_hid < 0)
return false;
615 #if defined (HAVE_HDF5_18)
618 data_hid = H5Dopen (group_hid,
"nr");
620 space_hid = H5Dget_space (data_hid);
621 rank = H5Sget_simple_extent_ndims (space_hid);
626 H5Gclose (group_hid);
634 H5Gclose (group_hid);
640 #if defined (HAVE_HDF5_18)
643 data_hid = H5Dopen (group_hid,
"nc");
645 space_hid = H5Dget_space (data_hid);
646 rank = H5Sget_simple_extent_ndims (space_hid);
651 H5Gclose (group_hid);
659 H5Gclose (group_hid);
665 #if defined (HAVE_HDF5_18)
668 data_hid = H5Dopen (group_hid,
"nz");
670 space_hid = H5Dget_space (data_hid);
671 rank = H5Sget_simple_extent_ndims (space_hid);
676 H5Gclose (group_hid);
684 H5Gclose (group_hid);
694 #if defined (HAVE_HDF5_18)
697 data_hid = H5Dopen (group_hid,
"cidx");
699 space_hid = H5Dget_space (data_hid);
700 rank = H5Sget_simple_extent_ndims (space_hid);
704 H5Sclose (space_hid);
706 H5Gclose (group_hid);
713 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
715 if (
static_cast<int> (hdims[0]) != nc + 1
716 ||
static_cast<int> (hdims[1]) != 1)
718 H5Sclose (space_hid);
720 H5Gclose (group_hid);
728 H5Sclose (space_hid);
730 H5Gclose (group_hid);
734 H5Sclose (space_hid);
737 #if defined (HAVE_HDF5_18)
740 data_hid = H5Dopen (group_hid,
"ridx");
742 space_hid = H5Dget_space (data_hid);
743 rank = H5Sget_simple_extent_ndims (space_hid);
747 H5Sclose (space_hid);
749 H5Gclose (group_hid);
753 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
755 if (
static_cast<int> (hdims[0]) != nz
756 ||
static_cast<int> (hdims[1]) != 1)
758 H5Sclose (space_hid);
760 H5Gclose (group_hid);
768 H5Sclose (space_hid);
770 H5Gclose (group_hid);
774 H5Sclose (space_hid);
777 #if defined (HAVE_HDF5_18)
780 data_hid = H5Dopen (group_hid,
"data");
782 hid_t type_hid = H5Dget_type (data_hid);
788 H5Tclose (complex_type);
790 H5Gclose (group_hid);
794 space_hid = H5Dget_space (data_hid);
795 rank = H5Sget_simple_extent_ndims (space_hid);
799 H5Sclose (space_hid);
801 H5Gclose (group_hid);
805 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
807 if (
static_cast<int> (hdims[0]) != nz
808 ||
static_cast<int> (hdims[1]) != 1)
810 H5Sclose (space_hid);
812 H5Gclose (group_hid);
826 H5Tclose (complex_type);
827 H5Sclose (space_hid);
829 H5Gclose (group_hid);
832 octave_unused_parameter (loc_id);
833 octave_unused_parameter (name);
861 for (
mwIndex i = 0; i < nz; i++)
863 pd[i].
real = pdata[i].real ();
864 pd[i].
imag = pdata[i].imag ();
874 for (
mwIndex i = 0; i < nz; i++)
876 pr[i] = pdata[i].real ();
877 pi[i] = pdata[i].imag ();
887 for (
mwIndex i = 0; i < nc + 1; i++)
904 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \
905 case umap_ ## UMAP: \
906 return octave_value (matrix.FCN ())
910 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \
911 case umap_ ## UMAP: \
912 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
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)
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 warn_implicit_conversion(const char *id, const char *from, const char *to)
void err_nan_to_logical_conversion()
Complex log2(const Complex &x)
Complex asin(const Complex &x)
Complex acos(const Complex &x)
Complex atan(const Complex &x)
std::complex< T > floor(const std::complex< T > &x)
std::complex< T > ceil(const std::complex< T > &x)
Complex expm1(const Complex &x)
Complex log1p(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)
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)
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)