[Top][All Lists]

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

Re: passing global variables when embedding octave

From: Jaroslav Hajek
Subject: Re: passing global variables when embedding octave
Date: Mon, 2 Mar 2009 10:36:52 +0100

On Mon, Mar 2, 2009 at 9:01 AM, Soeren Sonnenburg <address@hidden> wrote:
> Dear all,
> I've written a script to call python functions from within octave that
> passes variables to python and results back to octave (avoiding disk
> io). To this end I embedded python within octave context. (*)
> Now I would like to do the same for python, i.e. run a octave function
> from within python and pass all the variables to octave. So I need to
> embed the octave interpreter. The octave_embed example (from
> octave_embed.tar.gz ) shows how to run a script but not how to implant
> global variables/access variables in either direction.
> Could someone give an insight on how I can push a global variable to
> octave and also get the variable back?
> would be enough to show how
> octave_value x = octave_scalar(42);
> is made visible in octave context and incremented +1 and result
> transferred back...
> Thanks a lot!
> Soeren

symbol_table::global_varref (const std::string&) will create a
variable (or reference an existing one) in the global scope.
symbol_table::varref will work with local scope. Symbol table needs to
be initialized.
For more fine tuning, use symbol_table::insert which will return a

> (*) This will be in the shogun toolbox (,
> currently things like
> A=[[1,2,3];[4,5,6]];
> B=[[1,1,1];[0,0,0]];
> pythoncode=sprintf('import numpy\nresults=(A+B, 2*B, [ "bla1", "bla2" ])\n');
> [A2,B2,bla]=elwms('run_python', 'A',A, 'B',B, 'pythoncode', pythoncode)
> work.

Just out of curiosity; if Shogun is implemented in C++ (as the site
says), why do you want to interface Octave to Python for it?

Is the license compatible with GPL 3?


RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic

reply via email to

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