26#if defined (HAVE_CONFIG_H)
106 "real matrix",
"real scalar");
118 "real matrix",
"real scalar");
144 "real matrix",
"complex scalar");
160 "real matrix",
"complex scalar");
203 octave::err_nan_to_logical_conversion ();
316 error (
"diag: expecting vector argument");
320 return mat.
diag (m, n);
340 if (octave::math::isnan (
d))
341 octave::err_nan_to_character_conversion ();
343 int ival = octave::math::nint (
d);
345 if (ival < 0 || ival > std::numeric_limits<unsigned char>::max ())
353 ::warning (
"range error for conversion to character value");
358 chm(i) =
static_cast<char> (ival);
375 os <<
"# ndims: " << dv.
ndims () <<
"\n";
377 for (
int i=0; i < dv.
ndims (); i++)
386 os <<
"# rows: " <<
rows () <<
"\n"
387 <<
"# columns: " <<
columns () <<
"\n";
400 keywords[0] =
"ndims";
401 keywords[1] =
"rows";
407 error (
"load: failed to extract number of rows and columns");
412 char *prev_locale = std::setlocale (LC_ALL,
nullptr);
413 std::string old_locale (prev_locale ? prev_locale :
"");
414 std::setlocale (LC_ALL,
"C");
415 octave::unwind_action act
416 ([&old_locale] () { std::setlocale (LC_ALL, old_locale.c_str ()); });
420 int mdims =
static_cast<int> (val);
423 error (
"load: failed to extract number of dimensions");
428 for (
int i = 0; i < mdims; i++)
432 error (
"load: failed to read dimensions");
439 error (
"load: failed to load matrix constant");
443 else if (kw ==
"rows")
449 error (
"load: failed to extract number of rows and columns");
451 if (nr > 0 && nc > 0)
456 error (
"load: failed to load matrix constant");
460 else if (nr == 0 || nc == 0)
463 error (
"unexpected dimensions in octave_float_matrix::load_ascii - please report this bug");
466 error (
"unexpected dimensions keyword (= '%s') octave_float_matrix::load_ascii - please report this bug", kw.c_str ());
479 int32_t tmp = - dv.
ndims ();
480 os.write (
reinterpret_cast<char *
> (&tmp), 4);
481 for (
int i = 0; i < dv.
ndims (); i++)
484 os.write (
reinterpret_cast<char *
> (&tmp), 4);
489 if (dv.
numel () > 8192)
491 float max_val, min_val;
493 st = octave::get_save_type (max_val, min_val);
496 const float *mtmp = m.
data ();
504 octave::mach_info::float_format fmt)
508 if (! is.read (
reinterpret_cast<char *
> (&mdims), 4))
519 for (
int i = 0; i < mdims; i++)
521 if (! is.read (
reinterpret_cast<char *
> (&di), 4))
540 if (! is.read (
reinterpret_cast<char *
> (&tmp), 1))
557 if (! is.read (
reinterpret_cast<char *
> (&nc), 4))
561 if (! is.read (
reinterpret_cast<char *
> (&tmp), 1))
581#if defined (HAVE_HDF5)
588 int rank = dv.
ndims ();
589 hid_t space_hid, data_hid;
590 space_hid = data_hid = -1;
596 for (
int i = 0; i < rank; i++)
597 hdims[i] = dv(rank-i-1);
599 space_hid = H5Screate_simple (rank, hdims,
nullptr);
601 if (space_hid < 0)
return false;
603 hid_t save_type_hid = H5T_NATIVE_FLOAT;
605#if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
609 float max_val, min_val;
616#if defined (HAVE_HDF5_18)
617 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
621 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
626 H5Sclose (space_hid);
630 const float *mtmp = m.
data ();
635 H5Sclose (space_hid);
638 octave_unused_parameter (loc_id);
639 octave_unused_parameter (name);
652#if defined (HAVE_HDF5)
661#if defined (HAVE_HDF5_18)
664 hid_t data_hid = H5Dopen (loc_id, name);
666 hid_t space_id = H5Dget_space (data_hid);
668 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
680 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
692 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--)
709 octave_unused_parameter (loc_id);
710 octave_unused_parameter (name);
720 bool pr_as_read_syntax)
const
731 mxSingle *pd =
static_cast<mxSingle *
> (retval->
get_data ());
733 mwSize nel =
numel ();
737 for (mwIndex i = 0; i < nel; i++)
757 if (tmp.imag () == 0.0)
758 rr.xelem (i) = tmp.real ();
764 rc.xelem (j) = rr.xelem (j);
772 rc.xelem (j) = fcn (a(j));
795#define ARRAY_METHOD_MAPPER(UMAP, FCN) \
796 case umap_ ## UMAP: \
797 return octave_value (m_matrix.FCN ())
804#define ARRAY_MAPPER(UMAP, TYPE, FCN) \
805 case umap_ ## UMAP: \
806 return octave_value (m_matrix.map<TYPE> (FCN))
808#define RC_ARRAY_MAPPER(UMAP, TYPE, FCN) \
809 case umap_ ## UMAP: \
810 return do_rc_map (m_matrix, FCN)
871 return str_conv.
map (umap);
void swap_bytes< 4 >(void *ptr)
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
T & elem(octave_idx_type n)
Size of the specified dimension.
int ndims() const
Size of the specified dimension.
octave_idx_type rows() const
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
octave_idx_type columns() const
const T * data() const
Size of the specified dimension.
T * rwdata()
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
FloatMatrix diag(octave_idx_type k=0) const
bool any_element_not_one_or_zero() const
bool all_integers(float &max_val, float &min_val) const
bool any_element_is_nan() const
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.
void resize(int n, int fill_value=0)
octave_idx_type ndims() const
Number of dimensions.
octave_value diag(octave_idx_type k=0) const
octave_idx_type numel() const
octave_idx_type rows() const
octave_idx_type columns() const
int current_print_indent_level() const
virtual octave_value map(unary_mapper_t) const
virtual octave_value convert_to_str(bool pad=false, bool force=false, char type='\'') const
void warn_load(const char *type) const
friend class octave_value
void warn_save(const char *type) const
FloatNDArray float_array_value(bool=false) const
ComplexNDArray complex_array_value(bool=false) const
charNDArray char_array_value(bool=false) const
octave_base_value * try_narrowing_conversion()
bool save_binary(std::ostream &os, bool save_as_floats)
octave_value as_double() const
octave_value map(unary_mapper_t umap) const
octave_value as_uint16() const
ComplexMatrix complex_matrix_value(bool=false) const
octave_value as_int16() const
FloatComplex float_complex_value(bool=false) const
FloatMatrix float_matrix_value(bool=false) const
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
octave_value as_int64() const
octave_value as_single() const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
bool save_ascii(std::ostream &os)
double double_value(bool=false) const
FloatComplexNDArray float_complex_array_value(bool=false) const
Complex complex_value(bool=false) const
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
octave_value as_uint64() const
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Matrix matrix_value(bool=false) const
octave_value convert_to_str_internal(bool pad, bool force, char type) const
octave_value diag(octave_idx_type k=0) const
octave_value as_uint32() const
boolNDArray bool_array_value(bool warn=false) const
float float_value(bool=false) const
SparseMatrix sparse_matrix_value(bool=false) const
bool load_ascii(std::istream &is)
NDArray array_value(bool=false) const
octave_value as_int8() const
octave_value as_int32() const
octave_value as_uint8() const
FloatComplexMatrix float_complex_matrix_value(bool=false) const
mxArray * as_mxArray(bool interleaved) const
octave_value map(octave_base_value::unary_mapper_t umap) const
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
void write_floats(std::ostream &os, const float *data, save_type type, octave_idx_type len)
void read_floats(std::istream &is, float *data, save_type type, octave_idx_type len, bool swap, octave::mach_info::float_format fmt)
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)
intNDArray< octave_int16 > int16NDArray
intNDArray< octave_int32 > int32NDArray
intNDArray< octave_int64 > int64NDArray
intNDArray< octave_int8 > int8NDArray
float lo_ieee_float_nan_value()
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::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
std::complex< double > Complex
std::complex< float > FloatComplex
#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)
#define RC_ARRAY_MAPPER(UMAP, TYPE, FCN)
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)
template int8_t abs(int8_t)
intNDArray< octave_uint16 > uint16NDArray
intNDArray< octave_uint32 > uint32NDArray
intNDArray< octave_uint64 > uint64NDArray
intNDArray< octave_uint8 > uint8NDArray