help-octave
[Top][All Lists]
Advanced

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

Re: Techniques in using liboctave and liboctinterp from C++ program


From: John Swensen
Subject: Re: Techniques in using liboctave and liboctinterp from C++ program
Date: Fri, 27 Jun 2008 09:01:18 -0400


On Jun 26, 2008, at 1:56 PM, dbateman wrote:




John Swensen wrote:

I have started using the datatypes and operations of Octave from C++
for my research and have a few questions.

1) Can builtin functions and DLD-FUNCTIONS (e.g. find, eig, conv2,
etc) be used directly from C++?


You can always use feval to call an m-file or oct-file. You can't really call an oct-file directly from C++. What you can have for example is if the oct-file calls another C++ function, you might declare that function extern
and call it as well, though the oct-file would have to be loaded first



2) In the documentation, is there a list of overloaded operators for
octave_value objects of different types? For example, I was trying to
do the following:
Matrix A(768,1024);
Matrix B(1,1);
Matric C = A*B;
This, however, didn't work.  Instead, I had to declare B as a scalar
double as follows:
Matrix A(768,1024);
double b;
Matrix C = A*B;
This isn't necessarily a problem, but it would be nice if there was a
list of possible overloads somewhere.


That's not so easy for two reasons. Firstly someone has to do the work of documenting them. However, the second reason is harder. Having documented
these functions they then define an API to the internals of Octave,
something that has never really been stable. Therefore some thought needs to
go into this process of what functionality to document in an API.



3) I often do image thresholding after I have processed it a bit.  In
the Octave interpreter I can simply type 'im2 = im1>0.5'.  I tried
doing the following, but it didn't work:
Matrix A(768,1024);
double B = 0.5;
Matrix C = A>B;
If I could find out where that bit of the interpreter was implemented,
I could figure it out, but I searched through the sources a bit and
couldn't find anything.


I don't have a copy of Octave with me, but check the file
src/OPERATORS/op-m-m.cc for the gt function and see what it does.

D.
--
View this message in context: 
http://www.nabble.com/Techniques-in-using-liboctave-and-liboctinterp-from-C%2B%2B-program-tp18137086p18139690.html
Sent from the Octave - General mailing list archive at Nabble.com.

_______________________________________________
Help-octave mailing list
address@hidden
https://www.cae.wisc.edu/mailman/listinfo/help-octave
So I have kindof muddled my way through the operator business. Once I got my head wrapped around all the #define's, it makes a lot of sense. However, the comparator operators are still not working. I can get it to compile fine, but every time I try to do a compare, I get a "fatal: T& Array<T>::checkelem (10, -1, -1): range error" error message.

Here is a very simple example that causes the problem:
// compile with 'mkoctfile --link-stand-alone test.cpp -o test'
#include "octave/config.h"
#include "octave.h"
#include <octave/ov.h>

// Standard C++ includes
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

int main (int argc, char* argv[])
{
  octave_value tmp1(0.5);
  octave_value tmp2(1.0);
  octave_value tmp3(0.5);

  tmp1 == tmp2;

  return 0;
}

I'm assuming this is some sort of indexing error, since the checkelem() function in Array.h appears to be checking indices. What I don't understand is why it thinks these two scalar octave_values are somehow 3-dimensional. Why isn't it using the checkelem() that appears to be tailored for single dimensional octave_values?

John Swensen


reply via email to

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