octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

error saving empty matrix in HDF5 format


From: John W. Eaton
Subject: error saving empty matrix in HDF5 format
Date: Fri, 27 Feb 2004 14:24:49 -0600

I just noticed the following error with the current CVS sources:

  octave:1> clear
  octave:2> x = [];
  octave:3> save -hdf5 x.hdf5
  HDF5-DIAG: Error detected in HDF5 library version: 1.6.1 thread 16384.  Back 
trace follows.
    #000: ../../../src/H5S.c line 1708 in H5Screate_simple(): zero sized 
dimension for non-unlimited dimension
      major(01): Function arguments
      minor(05): Bad value
  error: save: error while writing `x' to hdf5 file

I tried to fix this, but it seems that HDF5 does not like empty arrays.

Any ideas on what the right was is to save empty arrays and preserve
their dimensions when using HDF5?

Also, the following cod seems a bit clumsy to me

  bool
  octave_matrix::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats)
  {
    dim_vector d = dims ();
    hsize_t hdims[d.length () > 2 ? d.length () : 3];
    hid_t space_hid = -1, data_hid = -1;
    int rank = ( (d (0) == 1) && (d.length () == 2) ? 1 : d.length ());
    bool retval = true;
    NDArray m = array_value ();

    // Octave uses column-major, while HDF5 uses row-major ordering
    for (int i = 0, j = d.length() - 1; i < d.length (); i++, j--)
      hdims[i] = d (j);

    space_hid = H5Screate_simple (rank, hdims, (hsize_t*) 0);

Why not just

    dim_vector d = dims ();
    int rank = d.length ();
    hsize_t hdims[rank];
    hid_t space_hid = -1, data_hid = -1;
    bool retval = true;
    NDArray m = array_value ();

    // Octave uses column-major, while HDF5 uses row-major ordering
    for (int i = 0; < rank; i++)
      hdims[i] = d (rank-i-1);

    space_hid = H5Screate_simple (rank, hdims, (hsize_t*) 0);

Finally, I suspect that there is very little difference in the code
for various matrix types.  It would be nice to implement this in the
base class (though that might not be possible) or as a template
function to avoid repeated code.

jwe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]