help-octave
[Top][All Lists]
Advanced

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

Re: How to call existing .oct files from C++?


From: David Bateman
Subject: Re: How to call existing .oct files from C++?
Date: Mon, 31 Mar 2008 11:28:52 +0200
User-agent: Thunderbird 2.0.0.12 (X11/20080306)

Charles David Hill wrote:
>
> Thankyou to Soren and everyone who replied to my post,
>
> Yes, I've read the appendix and it's definitely good for me to get
> started, and that is what I want to do - however if possible I don't
> want to have the extra overhead of calling feval() and invoking the
> interpreter. Is there any way that I can link directly from C++ to
> existing .oct files? At the moment I have used the octave source code
> to compile it to a .o file, and linked to that in but that seems like
> a kludge on my part.
>
> My code wants to look something like this (with type checking and
> error checking to come):
>
> ======
>
> DEFUN_DLD (tensor, args,  nargout, "Tensor product")
> {
>         // Create a tensor product of many possible values
>
>         // Return value
>         octave_value_list retvalue;
>
>         // Get the number of arguments
>         int numMatrices = args.length();
>        
>         // Get the first argument
>         ComplexMatrix a (args(0).complex_matrix_value());
>         numMatrices--;
>         ComplexMatrix b, c;
>
>         // Loop over the inputs
>         while (numMatrices > 0) {
>                 b = (ComplexMatrix)
> args(numMatrices).complex_matrix_value();
>
>                 if (!error_state) {
>                         ComplexMatrix c;
>                         kron (a, b, c);
>                        
>                         a = c;
>                         numMatrices--;
>                 }
>         }
>
>         retvalue(0) = a;
>         return retvalue;
> }
>
> ======
>
> My system is Ubuntu 7.10, using gcc 4.1.3, octave 2.9.12 (using the
> same version of mkoctfile to C++ compile files for use with octave).
> Everything so far is going pretty well - I'm just wondering if linking
> against .oct files is possible.
>
> Thanks again for all your help,
>
> Charles.
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
>   

In the case of kron, the actual function that does the work is a
template function. So if you have the lines

extern void
kron (const Array2<double>&, const Array2<double>&, Array2<double>&);

extern void
kron (const Array2<Complex>&, const Array2<Complex>&, Array2<Complex>&);

you should then be able to call that template function directly from
your code, with one major proviso.. As kron itself is a DLD function. It
is not loaded into Octave's until kron is called. You therefore have to
use kron once (even "help kron" will be sufficient) before calling your
code, othewise you'll get a segfault.

You're advised to use feval if you want to call the oct-file interface
however..

D.



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

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]