octave-maintainers
[Top][All Lists]
Advanced

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

Re: saveing/loading symbol table of annymous functions


From: John W. Eaton
Subject: Re: saveing/loading symbol table of annymous functions
Date: Wed, 9 May 2007 13:25:59 -0400

On  9-May-2007, David Bateman wrote:

| I've been working on load/save for inline, function handles anda
| nonymous function handles in matlabs format. I have inline and function
| handles working fine, but have difficulties with the format of anonymous
| function handles. Basically this is a process of reverse engineering as
| matlab doesn't document the matfile format for anonymous function
| handles. The format is also excessively complex for what it is.

Aren't function handles in Matlab just class objects with the fields
"function", "type", and "file", and anonymous function handles just
add the additional field "workspace" to that (and set file to '')?  If
so, then aren't these saved the same as any other class object (which
I think is documented)?  OTOH, the workspace field seems a little
opaque and I guess that is where the real trouble is.

| The matlab v5 file format for an anonymous function handle is like
| 
| mxCLASS_FUNCTION
|   mxCLASS_STRUCT
|     matlabroot (mxCLASS_CHAR "/opt/matlab73")
|     separator (mxCLASS_CHAR "/")
|     sentinel (mxCLASS_CHAR "@")
|     function_handle
|       mxCLASS_STRUCT
|         function (mxCLASS_CHAR <string with anonymous function handle>)
|         type (mxCLASS_CHAR "anonymous")
|         file (mxCLASS_CHAR "")
|         workspace (mxClassID = 17 [0x11])
|           MCOS (mxCLASS_UINT32 5x1)
|           function_handle_workspace (mxCLASS_UINT8 Nx1)

What anonymous function definition did you use when you discovered
this structure?

| The function_handle_workspace field is in fact a matfile in itself
| stored as a UINT8 array which seems to contain a single structure.

This part is a complete MAT file with header info and all?  Ugh.

| At this point I have no idea what MCOS represents, and I haven't managed to
| get octave to correctly read the function_handle_workspace variable,
| which itself decomposes to
| 
| function_handle_workspace
| mxCLASS_STRUCT (1 field MCOS with no name!!!)
| MCOS (mxCLASS_WORKSPACE)
| MCOS (mxCLASS_CELL)
| [1,1] (mxCLASS_UINT8 Nx1)
| [2,1] (mxCLASS_DOUBLE 0x0)
| [3,1] (mxCLASS_CELL 2x1)
| [1,1] (mxCLASS_UINT32 5x1) ## Identical to
| ## function_handle.workspace.MCOS
| [2,1] (mxCLASS_STRUCT) ## This has the real workspace in it
| FileWrapper__ (mxCLASS_UINT8 Nx1)
| MCOS (mxCLASS_DOUBLE [])

Ugh^2.

| FileWrapper__ is also an embedded file like function_handle_workspace.

Is this also a complete MAT file?  If you save it separately and load
it, what variables does it contain?

| At this point I could probably get some anonymous function handle load
| save mat-file functionality running, but wouldn't mind some comments on
| what people think are the other parts of this structure for a function
| handle. I attach a loaded matlab anonymous function handle stored as a
| structure in an octave text file the details of how they were created is
| 
| f = @(x) 2 * x;
| save -v6 anon1.mat f
| a = 2;
| g = @(x) a + x;
| save -v6 anon2.mat g

Are you asking what information should we save in Octave files?  I
don't know what to recommend here.

In Matlab, I see

  a = 2;
  g = @(x) a + x;
  x = functions (g) => class object with fields as noted above
  c = x.workspace => cell array with one element
  c{1} => 1x1 structure array with fields corresponding to variables
          in the anonymous function that are not in the argument list

but maybe this is nothing new.

jwe


reply via email to

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