octave-maintainers
[Top][All Lists]
Advanced

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

Re: error saving empty matrix in HDF5 format


From: David Bateman
Subject: Re: error saving empty matrix in HDF5 format
Date: Mon, 1 Mar 2004 11:22:00 +0100
User-agent: Mutt/1.4.1i

According to John W. Eaton <address@hidden> (on 02/27/04):
> 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.

Looking at it now...

> 
> 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);


Well the reason for this was that I had very little knowledge of HDF5
stuff when I rewrote the load-save code. Therefore, I based what I did
heavily on the existing code. I also found the above a bit messy, but
since I didn't understand the intention of the original author, rather
than breaking code that read the HDF5 stuff on the other end, I kept
similar code.

However, I've already broken HDF5 compatiability in that I've now
implemented each saved variable as a group with a string containing the
name of the octave_value and a second value with the actual data. 

So, go ahead a do it as above.

> 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.

Humm, this is probably true for the ascii formats, and it might even
be true for the binary formats, since we could use for instance the
"<<" and ">>" operators for the actual work. However, I doubt it is
true for the HDF5 type due to the use of coumpound types for complex,
etc.

I'd propose putting this idea on the backburner and just commenting 
a "// XXX FIXME XX Implement as template class ??" above the relevant
code...

Cheers
David

-- 
David Bateman                                address@hidden
Motorola CRM                                 +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax) 
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



reply via email to

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