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

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

[Octave-bug-tracker] [bug #42112] Unable to load Java objects from MAT f


From: Rik
Subject: [Octave-bug-tracker] [bug #42112] Unable to load Java objects from MAT file
Date: Thu, 24 Apr 2014 15:56:36 +0000
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0

Follow-up Comment #2, bug #42112 (project octave):

This is probably a huge coding effort :(

First, I'm not sure it will be possible to save java objects in Matlab and
then re-load them in Octave.  It really depends on how Matlab did the
Serialization/Deserialization and whether there is any documentation or clues
to their approach.

But, before that can happen Octave itself needs to be able to load/save Java
objects which it can't.  See the following code:


octave:1> x = javaObject ('java.lang.Double', 1)
x =

<Java object: java.lang.Double>

octave:2> save -binary tst.save x
error: octave_base_value::save_binary(): wrong type argument 'octave_java'
warning: save: no such variable 'x'


I think the first place to start would be to get load/save working with
Octave's own formats.

I can give you a few pointers about how to do this.  The key is that a Java
object is an octave_value.  This is an overloaded class where the underlying
value might be a double, uint8, range (such as 1:3:10), Java object, etc.  If
you look in the directory libinterp/octave-value you will find all of the
different octave_value classes.  The overall octave_value class (ov.h) defines
various virtual methods like save_ascii or save_binary.  It is up to the
individual class to override these with a function that does whatever is
necessary for that particular object to save itself.

I'll take the example of a range because it is particularly simple.


x = 1:3:10
x =

    1    4    7   10

save -text tst.txt x


And the resulting file is:


# Created by Octave 4.1.0+, Thu Apr 24 08:51:01 2014 PDT <address@hidden>
# name: x
# type: range
# base, limit, increment
1 10 3



Now if you look in ov-range.h you will see there is a prototype for
save_ascii.  In ov-range.cc you can find the actual function:


octave_range::save_ascii (std::ostream& os)
{
  Range r = range_value ();
  double base = r.base ();
  double limit = r.limit ();
  double inc = r.inc ();
  octave_idx_type len = r.nelem ();

  if (inc != 0)
    os << "# base, limit, increment\n";
  else
    os << "# base, length, increment\n";

  octave_write_double (os, base);
  os << " ";
  if (inc != 0)
    octave_write_double (os, limit);
  else
    os << len;
  os << " ";
  octave_write_double (os, inc);
  os << "\n";

  return true;
}


The range class has a pretty simple way of saving itself.  For Java objects,
something more complex will have to be designed.  But the approach is the
same.  Add a prototype for save_ascii, save_binary, etc. in ov-java.h and then
an implementation in ov-java.cc.


    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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