octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #38326] save -binary or load fails with big ma


From: Rik
Subject: [Octave-bug-tracker] [bug #38326] save -binary or load fails with big matrices
Date: Wed, 20 Feb 2013 22:15:53 +0000
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0

Follow-up Comment #4, bug #38326 (project octave):

I think there is an opportunity for a stop-gap measure which would improve
things before actually moving fully to a new format.

Currently the dimensions are stored as int32_t objects, but this isn't so much
the problem.  The original poster was using dimensions of 20,000 X 4,000 which
are both well shy of 2^31.  The problem is the write_doubles routine which
accepts a length which is the number of elements.  The prototype for the
function in liboctave/util/data-conv.cc is


write_doubles (std::ostream& os, const double *data, save_type type,
               octave_idx_type len)


And later on there is a call to os.write which does math with the
octave_idx_type.


case LS_DOUBLE: // No conversion necessary.
  {
    char tmp_type = static_cast<char> (type);
    os.write (&tmp_type, 1);
    os.write (reinterpret_cast <const char *> (data), 8 * len);
  }


The real fun is that the multiplication by 8 means another 3 bits off the
maximum number of elements allowed.  There is no need to use the extremely
large dimensions of the original poster to demonstrate the problem.  The
following example much more quickly reveals the problem:


x = ones (2^28, 1);
save -binary x.bin x


The resulting file is only 45 bytes on disk which is clearly wrong.

As a stop-gap I would use this code in data-conv.cc.


std::streamsize n_bytes = 8 * static_cast<std::streamsize> (len);
os.write (reinterpret_cast <const char *> (data), n_bytes);


On 32-bit systems you will still be limited to less than 2^31 bytes or 2^28
elements if they are IEEE doubles.  But 64-bit systems will have a 64-bit
streamsize and they can therefore handle up to 2^31 elements or 2^34 bytes.  I
verified that this works for me.

I'm attaching a patch that works for me.  We might want to touch up
ov-base-int.cc as well.



(file #27487)
    _______________________________________________________

Additional Item Attachment:

File name: patch.LFS                      Size:3 KB


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?38326>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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