56 "sparse complex matrix",
"double");
83 else if (nr == 0 || nc == 0)
111 if (! force_conversion)
113 "complex sparse matrix",
"real scalar");
120 "complex sparse matrix",
"real scalar");
135 if (! force_conversion)
137 "complex sparse matrix",
"real matrix");
156 "complex sparse matrix",
"real scalar");
185 "sparse complex matrix",
"string");
206 if (! force_conversion)
208 "complex sparse matrix",
209 "real sparse matrix");
222 ||
real (
matrix).any_element_not_one_or_zero ()))
246 os.write (reinterpret_cast<char *> (&itmp), 4);
249 os.write (reinterpret_cast<char *> (&itmp), 4);
252 os.write (reinterpret_cast<char *> (&itmp), 4);
255 os.write (reinterpret_cast<char *> (&itmp), 4);
262 warning (
"save: some values too large to save as floats --");
263 warning (
"save: saving as doubles instead");
270 double max_val, min_val;
277 for (
int i = 0; i < nc+1; i++)
281 os.write (reinterpret_cast<char *> (&itmp), 4);
284 for (
int i = 0; i < nz; i++)
288 os.write (reinterpret_cast<char *> (&itmp), 4);
301 int32_t nz, nc, nr, tmp;
304 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
312 error (
"load: only 2-D sparse matrices are supported");
316 if (! is.read (reinterpret_cast<char *> (&nr), 4))
318 if (! is.read (reinterpret_cast<char *> (&nc), 4))
320 if (! is.read (reinterpret_cast<char *> (&nz), 4))
331 static_cast<octave_idx_type> (nc),
332 static_cast<octave_idx_type> (nz));
334 for (
int i = 0; i < nc+1; i++)
337 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
344 for (
int i = 0; i < nz; i++)
347 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
354 if (! is.read (reinterpret_cast<char *> (&ctmp), 1))
358 static_cast<save_type> (ctmp), 2 * nz, swap, fmt);
377 #if defined (HAVE_HDF5)
388 hid_t group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT,
391 hid_t group_hid = H5Gcreate (loc_id, name, 0);
396 hid_t space_hid, data_hid;
397 space_hid = data_hid = -1;
402 space_hid = H5Screate_simple (0, hdims, 0);
405 H5Gclose (group_hid);
411 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
418 H5Sclose (space_hid);
419 H5Gclose (group_hid);
425 H5P_DEFAULT, &tmp) >= 0;
429 H5Sclose (space_hid);
430 H5Gclose (group_hid);
436 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
443 H5Sclose (space_hid);
444 H5Gclose (group_hid);
450 H5P_DEFAULT, &tmp) >= 0;
454 H5Sclose (space_hid);
455 H5Gclose (group_hid);
461 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
468 H5Sclose (space_hid);
469 H5Gclose (group_hid);
475 H5P_DEFAULT, &tmp) >= 0;
479 H5Sclose (space_hid);
480 H5Gclose (group_hid);
484 H5Sclose (space_hid);
486 hdims[0] = m.
cols () + 1;
489 space_hid = H5Screate_simple (2, hdims, 0);
493 H5Gclose (group_hid);
498 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
499 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
501 data_hid = H5Dcreate (group_hid,
"cidx",
H5T_NATIVE_IDX, space_hid,
506 H5Sclose (space_hid);
507 H5Gclose (group_hid);
513 H5P_DEFAULT, itmp) >= 0;
517 H5Sclose (space_hid);
518 H5Gclose (group_hid);
522 H5Sclose (space_hid);
527 space_hid = H5Screate_simple (2, hdims, 0);
531 H5Gclose (group_hid);
536 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
537 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
539 data_hid = H5Dcreate (group_hid,
"ridx",
H5T_NATIVE_IDX, space_hid,
544 H5Sclose (space_hid);
545 H5Gclose (group_hid);
550 retval = H5Dwrite (data_hid,
H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT,
555 H5Sclose (space_hid);
556 H5Gclose (group_hid);
560 hid_t save_type_hid = H5T_NATIVE_DOUBLE;
566 warning (
"save: some values too large to save as floats --");
567 warning (
"save: saving as doubles instead");
570 save_type_hid = H5T_NATIVE_FLOAT;
572 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS
576 double max_val, min_val;
587 H5Sclose (space_hid);
588 H5Gclose (group_hid);
592 data_hid = H5Dcreate (group_hid,
"data", type_hid, space_hid,
593 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
595 data_hid = H5Dcreate (group_hid,
"data", type_hid, space_hid, H5P_DEFAULT);
599 H5Sclose (space_hid);
601 H5Gclose (group_hid);
607 if (complex_type_hid >= 0)
611 retval = H5Dwrite (data_hid, complex_type_hid, H5S_ALL, H5S_ALL,
612 H5P_DEFAULT, ctmp) >= 0;
616 H5Sclose (space_hid);
618 H5Gclose (group_hid);
632 #if defined (HAVE_HDF5)
635 hid_t group_hid, data_hid, space_hid;
646 group_hid = H5Gopen (loc_id, name, H5P_DEFAULT);
648 group_hid = H5Gopen (loc_id, name);
650 if (group_hid < 0)
return false;
653 data_hid = H5Dopen (group_hid,
"nr", H5P_DEFAULT);
655 data_hid = H5Dopen (group_hid,
"nr");
657 space_hid = H5Dget_space (data_hid);
658 rank = H5Sget_simple_extent_ndims (space_hid);
663 H5Gclose (group_hid);
668 H5S_ALL, H5P_DEFAULT, &nr) < 0)
671 H5Gclose (group_hid);
678 data_hid = H5Dopen (group_hid,
"nc", H5P_DEFAULT);
680 data_hid = H5Dopen (group_hid,
"nc");
682 space_hid = H5Dget_space (data_hid);
683 rank = H5Sget_simple_extent_ndims (space_hid);
688 H5Gclose (group_hid);
693 H5S_ALL, H5P_DEFAULT, &nc) < 0)
696 H5Gclose (group_hid);
703 data_hid = H5Dopen (group_hid,
"nz", H5P_DEFAULT);
705 data_hid = H5Dopen (group_hid,
"nz");
707 space_hid = H5Dget_space (data_hid);
708 rank = H5Sget_simple_extent_ndims (space_hid);
713 H5Gclose (group_hid);
718 H5S_ALL, H5P_DEFAULT, &nz) < 0)
721 H5Gclose (group_hid);
728 static_cast<octave_idx_type> (nc),
729 static_cast<octave_idx_type> (nz));
732 data_hid = H5Dopen (group_hid,
"cidx", H5P_DEFAULT);
734 data_hid = H5Dopen (group_hid,
"cidx");
736 space_hid = H5Dget_space (data_hid);
737 rank = H5Sget_simple_extent_ndims (space_hid);
741 H5Sclose (space_hid);
743 H5Gclose (group_hid);
750 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
752 if (static_cast<int> (hdims[0]) != nc + 1
753 || static_cast<int> (hdims[1]) != 1)
755 H5Sclose (space_hid);
757 H5Gclose (group_hid);
763 H5S_ALL, H5P_DEFAULT, itmp) < 0)
765 H5Sclose (space_hid);
767 H5Gclose (group_hid);
771 H5Sclose (space_hid);
775 data_hid = H5Dopen (group_hid,
"ridx", H5P_DEFAULT);
777 data_hid = H5Dopen (group_hid,
"ridx");
779 space_hid = H5Dget_space (data_hid);
780 rank = H5Sget_simple_extent_ndims (space_hid);
784 H5Sclose (space_hid);
786 H5Gclose (group_hid);
790 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
792 if (static_cast<int> (hdims[0]) != nz
793 || static_cast<int> (hdims[1]) != 1)
795 H5Sclose (space_hid);
797 H5Gclose (group_hid);
803 H5S_ALL, H5P_DEFAULT, itmp) < 0)
805 H5Sclose (space_hid);
807 H5Gclose (group_hid);
811 H5Sclose (space_hid);
815 data_hid = H5Dopen (group_hid,
"data", H5P_DEFAULT);
817 data_hid = H5Dopen (group_hid,
"data");
819 hid_t type_hid = H5Dget_type (data_hid);
825 H5Tclose (complex_type);
827 H5Gclose (group_hid);
831 space_hid = H5Dget_space (data_hid);
832 rank = H5Sget_simple_extent_ndims (space_hid);
836 H5Sclose (space_hid);
838 H5Gclose (group_hid);
842 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
844 if (static_cast<int> (hdims[0]) != nz
845 || static_cast<int> (hdims[1]) != 1)
847 H5Sclose (space_hid);
849 H5Gclose (group_hid);
855 if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL,
856 H5P_DEFAULT, ctmp) >= 0
863 H5Tclose (complex_type);
864 H5Sclose (space_hid);
866 H5Gclose (group_hid);
881 double *pr =
static_cast<double *
> (retval->
get_data ());
882 double *pi =
static_cast<double *
> (retval->
get_imag_data ());
886 for (
mwIndex i = 0; i < nz; i++)
911 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \
912 case umap_ ## UMAP: \
913 return octave_value (matrix.FCN ())
917 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \
918 case umap_ ## UMAP: \
919 return octave_value (matrix.map<TYPE> (FCN))
void gripe_implicit_conversion(const char *id, const char *from, const char *to)
octave_idx_type * xridx(void)
SparseMatrix sparse_matrix_value(bool=false) const
octave_idx_type cols(void) const
bool hdf5_types_compatible(hid_t t1, hid_t t2)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
octave_idx_type rows(void) const
SparseComplexMatrix matrix
ComplexMatrix matrix_value(void) const
octave_base_value * try_narrowing_conversion(void)
octave_idx_type columns(void) const
std::complex< double > erfi(std::complex< double > z, double relerr=0)
Complex complex_value(bool=false) const
void gripe_load(const char *type) const
save_type get_save_type(double, double)
SparseBoolMatrix sparse_bool_matrix_value(bool warn=false) const
octave_idx_type * xcidx(void)
void error(const char *fmt,...)
void * get_data(void) const
void write_doubles(std::ostream &os, const double *data, save_type type, octave_idx_type len)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
void gripe_save(const char *type) const
bool load_binary(std::istream &is, bool swap, oct_mach_info::float_format fmt)
octave_idx_type * cidx(void)
double lo_ieee_nan_value(void)
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
bool indices_ok(void) const
std::complex< double > erf(std::complex< double > z, double relerr=0)
octave_idx_type nzmax(void) const
F77_RET_T const double const double double * d
int load_hdf5_empty(hid_t loc_id, const char *name, dim_vector &d)
octave_idx_type nnz(void) const
hid_t hdf5_make_complex_type(hid_t num_type)
mwIndex * get_ir(void) const
#define ARRAY_MAPPER(UMAP, TYPE, FCN)
ComplexColumnVector conj(const ComplexColumnVector &a)
ComplexMatrix complex_matrix_value(bool=false) const
void swap_bytes< 4 >(void *ptr)
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
octave_idx_type numel(void) const
Sparse< T > maybe_compress(bool remove_zeros=false)
void gripe_nan_to_logical_conversion(void)
void resize(octave_idx_type r, octave_idx_type c)
std::complex< T > ceil(const std::complex< T > &x)
double double_value(bool=false) const
octave_value map(octave_base_value::unary_mapper_t umap) const
size_t byte_size(void) const
bool too_large_for_float(void) const
std::complex< double > erfcx(std::complex< double > z, double relerr=0)
boolMatrix mx_el_ne(const boolMatrix &m1, const boolMatrix &m2)
void read_doubles(std::istream &is, double *data, save_type type, octave_idx_type len, bool swap, oct_mach_info::float_format fmt)
charNDArray char_array_value(bool frc_str_conv=false) const
mxArray * as_mxArray(void) const
void warning(const char *fmt,...)
bool all_elements_are_real(void) const
octave_idx_type * ridx(void)
void gripe_logical_conversion(void)
bool any_element_is_nan(void) const
void * get_imag_data(void) const
void gripe_invalid_conversion(const std::string &from, const std::string &to)
#define ARRAY_METHOD_MAPPER(UMAP, FCN)
int save_hdf5_empty(hid_t loc_id, const char *name, const dim_vector d)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
mwIndex * get_jc(void) const
Complex asin(const Complex &x)
ColumnVector imag(const ComplexColumnVector &a)
std::complex< T > floor(const std::complex< T > &x)
octave_value map(unary_mapper_t umap) const
std::complex< double > Complex
Complex acos(const Complex &x)
ColumnVector real(const ComplexColumnVector &a)
Matrix matrix_value(bool=false) const
bool save_binary(std::ostream &os, bool &save_as_floats)
bool all_integers(double &max_val, double &min_val) const
Complex atan(const Complex &x)
dim_vector dims(void) const
octave_idx_type nnz(void) const
octave_idx_type rows(void) const
ComplexNDArray complex_array_value(bool=false) const
bool octave_is_NA(double x)
std::complex< double > erfc(std::complex< double > z, double relerr=0)