Mercurial > hg > octave-nkf
changeset 4948:7124436476cb
[project @ 2004-08-31 17:57:21 by jwe]
author | jwe |
---|---|
date | Tue, 31 Aug 2004 17:57:21 +0000 |
parents | b2bf2a130eba |
children | f6b63ff1119b |
files | src/ChangeLog src/data.cc src/ls-hdf5.cc |
diffstat | 3 files changed, 127 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2004-08-31 David Bateman <dbateman@free.fr> + + * ls-hdf5.cc (hdf5_read_next_data): When importing hdf5 files, + allow structures and lists (for backward compatibility). Also + allow importation of integer types into octave int and uint types. + 2004-08-31 John W. Eaton <jwe@octave.org> * data.cc (fill_matrix, identity_matrix): Convert class name to
--- a/src/data.cc +++ b/src/data.cc @@ -1318,8 +1318,8 @@ "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} ones (@var{x})\n\ @deftypefnx {Built-in Function} {} ones (@var{n}, @var{m})\n\ -@deftypefnx {Built-in Function} {} ones (@var{n}, @var{m}, @var{k},...)\n\ -@deftypefnx {Built-in Function} {} ones (..., @var{class})\n\ +@deftypefnx {Built-in Function} {} ones (@var{n}, @var{m}, @var{k}, @dots{})\n\ +@deftypefnx {Built-in Function} {} ones (@dots{}, @var{class})\n\ Return a matrix or N-dimensional array whose elements are all 1.\n\ The arguments are handled the same as the arguments for @code{eye}.\n\ \n\ @@ -1345,8 +1345,8 @@ "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} zeros (@var{x})\n\ @deftypefnx {Built-in Function} {} zeros (@var{n}, @var{m})\n\ -@deftypefnx {Built-in Function} {} zeros (@var{n}, @var{m}, @var{k},...)\n\ -@deftypefnx {Built-in Function} {} zeros (..., @var{class})\n\ +@deftypefnx {Built-in Function} {} zeros (@var{n}, @var{m}, @var{k}, @dots{})\n\ +@deftypefnx {Built-in Function} {} zeros (@dots{}, @var{class})\n\ Return a matrix or N-dimensional array whose elements are all 0.\n\ The arguments are handled the same as the arguments for @code{eye}.\n\ \n\ @@ -1394,12 +1394,10 @@ } static octave_value -identity_matrix (int nr, int nc, const std::string& nm) +identity_matrix (int nr, int nc, oct_data_conv::data_type dt) { octave_value retval; - oct_data_conv::data_type dt = oct_data_conv::string_to_data_type (nm); - // XXX FIXME XXX -- perhaps this should be made extensible by using // the class name to lookup a function to call to create the new // value. @@ -1460,7 +1458,7 @@ "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} eye (@var{x})\n\ @deftypefnx {Built-in Function} {} eye (@var{n}, @var{m})\n\ -@deftypefnx {Built-in Function} {} eye (..., @var{class})\n\ +@deftypefnx {Built-in Function} {} eye (@dots{}, @var{class})\n\ Return an identity matrix. If invoked with a single scalar argument,\n\ @code{eye} returns a square matrix with the dimension specified. If you\n\ supply two scalar arguments, @code{eye} takes them to be the number of\n\ @@ -1502,22 +1500,27 @@ { octave_value retval; - std::string nm = "double"; + int nargin = args.length (); - int nargin = args.length (); + oct_data_conv::data_type dt = oct_data_conv::dt_double; // Check for type information. if (nargin > 0 && args(nargin-1).is_string ()) { - nm = args(nargin-1).string_value (); + std::string nm = args(nargin-1).string_value (); nargin--; + + dt = oct_data_conv::string_to_data_type (nm); + + if (error_state) + return retval; } switch (nargin) { case 0: - retval = identity_matrix (1, 1, nm); + retval = identity_matrix (1, 1, dt); break; case 1: @@ -1526,7 +1529,7 @@ get_dimensions (args(0), "eye", nr, nc); if (! error_state) - retval = identity_matrix (nr, nc, nm); + retval = identity_matrix (nr, nc, dt); } break; @@ -1536,7 +1539,7 @@ get_dimensions (args(0), args(1), "eye", nr, nc); if (! error_state) - retval = identity_matrix (nr, nc, nm); + retval = identity_matrix (nr, nc, dt); } break;
--- a/src/ls-hdf5.cc +++ b/src/ls-hdf5.cc @@ -290,7 +290,7 @@ if (hdf5_check_attr (subgroup_id, "OCTAVE_LIST")) d->tc = octave_value_typeinfo::lookup_type ("list"); else - d->tc = octave_value_typeinfo::lookup_type ("cell"); + d->tc = octave_value_typeinfo::lookup_type ("struct"); // check for OCTAVE_GLOBAL attribute: d->global = hdf5_check_attr (subgroup_id, "OCTAVE_GLOBAL"); @@ -317,12 +317,7 @@ type_class_id = H5Tget_class (type_id); -#if HAVE_HDF5_INT2FLOAT_CONVERSIONS - if (type_class_id == H5T_INTEGER || type_class_id == H5T_FLOAT) -#else - // hdf5 doesn't (yet) support automatic float/integer conversions if (type_class_id == H5T_FLOAT) -#endif { space_id = H5Dget_space (data_id); @@ -335,6 +330,109 @@ H5Sclose (space_id); } + else if (type_class_id == H5T_INTEGER) + { + // What integer type do we really have.. + std::string int_typ; +#ifdef HAVE_H5T_GET_NATIVE_TYPE + // XXX FIXME XX test this code and activated with an autoconf test!! + switch (H5Tget_native_type (type_id, H5T_DIR_ASCEND)) + { + case H5T_NATIVE_CHAR: + int_typ = "int8 "; + break; + + case H5T_NATIVE_SHORT: + int_typ = "int16 "; + break; + + case H5T_NATIVE_INT: + case H5T_NATIVE_LONG: + int_typ = "int32 "; + break; + + case H5T_NATIVE_LLONG: + int_typ = "int64 "; + break; + + case H5T_NATIVE_UCHAR: + int_typ = "uint8 "; + break; + + case H5T_NATIVE_USHORT: + int_typ = "uint16 "; + break; + + case H5T_NATIVE_UINT: + case H5T_NATIVE_ULONG: + int_typ = "uint32 "; + break; + + case H5T_NATIVE_ULLONG: + int_typ = "uint64 "; + break; + } +#else + hid_t int_sign = H5Tget_sign (type_id); + + if (int_sign == H5T_SGN_ERROR) + warning ("load: can't read `%s' (unknown datatype)", name); + else + { + if (int_sign == H5T_SGN_NONE) + int_typ.append ("u"); + int_typ.append ("int"); + + int slen = H5Tget_size (type_id); + if (slen < 0) + warning ("load: can't read `%s' (unknown datatype)", name); + else + { + switch (slen) + { + case 1: + int_typ.append ("8 "); + break; + + case 2: + int_typ.append ("16 "); + break; + + case 4: + int_typ.append ("32 "); + break; + + case 8: + int_typ.append ("64 "); + break; + + default: + warning ("load: can't read `%s' (unknown datatype)", + name); + int_typ = ""; + break; + } + } + } +#endif + if (int_typ == "") + warning ("load: can't read `%s' (unknown datatype)", name); + else + { + // Matrix or scalar? + space_id = H5Dget_space (data_id); + + hsize_t rank = H5Sget_simple_extent_ndims (space_id); + + if (rank == 0) + int_typ.append ("scalar"); + else + int_typ.append ("matrix"); + + d->tc = octave_value_typeinfo::lookup_type (int_typ); + H5Sclose (space_id); + } + } else if (type_class_id == H5T_STRING) d->tc = octave_value_typeinfo::lookup_type ("string"); else if (type_class_id == H5T_COMPOUND)