Calling ARPACK functions from C++ using liboctave

Previously I post on how to call GSL function, now it’s time for ARPACK. In octave, when you run interactively, you just need to run “eigs” for various matrix function. So Octave has provided some bindings to call ARPACK functions. So following the same steps as calling GSL function:

download arpack-1.0.6.tar.gz.

unzip the file and type “./configure” and “make”, but don’t type “make install”. Under folder “src” you can find two files “” and “”. If you look inside “”, this file will include “” in the beginning.

Comment or delete the DLD_FUNC lines and replace with an ordinary function name
octave_value_list eigs(octave_value_list args,unsigned int nargout)

I also created a header file
#include "eigs.h"
where it only contains the prototype of the functions and some #define directives
#ifndef EIGS
#define EIGS
octave_value_list eigs(octave_value_list args,unsigned int nargout);

we need to define “HAVE_ARPACK”, otherwise, the function will not run. Nothing to be done for, except removing the warning due to NaN.

To compile your C++ code, you will need to use “-larpack” during linking. Otherwise it will give error.

In your main program, you can call “eigs” function as follows:
octave_value_list fargs;
octave_value_list retval=eigs(fargs,2);
Matrix V(retval(0).matrix_value());
Matrix D(retval(1).matrix_value());

where M is the matrix of one input argument. Type “help eigs” in your octave prompt if you are not familiar with the syntax (of course you need to do pkg install arpack-1.0.6.tar.gz inside Octave, if you have not done so)

Now, about the warning. After I successfuly called the function. I kept on getting this warning:
warning: eigs: 'A - sigma*B' is singular, indicating sigma is exactly
warning: an eigenvalue. Convergence is not guaranteed

After some debugging, it turns out the octave_NaN variable was not set properly. A simple way to overcome this is to initialize octave_NaN again. You can call this line
inside functions. This should solve the problem.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: