C++ code using acos for complex number in IT++

I am currently trying out IT++ and so far it was great. It is as easy as Octave but written for C++ programming. One thing that I had trouble was that in my code I need to compute
complex acos(complex a)
However, it gives me error

for the function acos. It turns out acos for complex number was not in the C++ 98 specification, it will only be on the C++ 0x specification. So I turn to Boost library.

To modify IT++, this is what I do:
1. go to “itpp-4.0.6/itpp/base/math” folder, and modify the file “trig_hyp.h”

2. Add this line:
#include <boost/math/complex/acos.hpp>

Of course you need to have Boost library.

3. Find the line for “acos” in trig_hyp.h file, and add these lines:
//! Inverse cosine function vector
inline cvec acos(const cvec &x) { return apply_function<std::complex >(boost::math::acos, x); }
//! Inverse cosine function matrix
inline cmat acos(const cmat &x) { return apply_function<std::complex >(boost::math::acos, x); }
//! Inverse cosine function scalar
inline std::complex acos(const std::complex &x) { return boost::math::acos( x); }

4. Go back to the root directory for IT++ and do a ./configure again
./configure --prefix=$(HOME)/local F77=gfortran CPPFLAGS=-I
where we have included the root folder of our Boost libraries.

5. Type “make”, “make check”, and “make install”

6. Now, in your code, you also need to include your Boost folder in your Makefile.

That’s all, now we have acos in IT++


6 Responses

  1. I tried to install IT++ in one of my workstation, somehow it couldn’t find the fftw3 library. So I need to specify it in my ./configure parameters. Before that, I need to install fftw3 library with -fPIC flag.

    then configure IT++ with
    ./configure –prefix=$HOME/local CPPFLAGS=-I/your/include/folder LDFLAGS=-L/your/library/folder

  2. This is quite a up-to-date information. I’ll share it on Delicious.

  3. Hello every one

    I just start trying ITPP, it looks like quite nice.

    But I have one big problem initializing a cvec object and I have two questions:

    1) first, is there any special forums for itpp’s users? I didn’t any solution in find http://sourceforge.net/forum/forum.php
    2) if not, can you help for the folowing problem:

    Written with GnuScientificLibrary, it should look like this
    // creating complex
    gsl_comple z;
    gsl_complex* signal = malloc(sizeof(gsl_complex) * nb_of_samples);
    if( signal == NULL) {exit(EXICT_FAILURE);}
    // reading a file, for each sample,
    real=fread… imag=fread…
    // Building the complex number
    z = gsl_complex_rec(real, imag);
    *(signal + index_of_sample) = z;

  4. And to get a complex back

    real = REAL(*(signal + index_of_sample));
    imag = IMAG(*(signal + index_of_sample));

    I would like to do the same with itpp

    I guess it would be something like

    std::complex my_complex(real, imag); to create a complex,
    but I am not sur.
    then it should be something like
    (cvec signal).set(index, my_complex);

    Actually I have no idea of how to get real and imag part back from complex.

    Thank you very much for your help !

    • to set a complex simply use in your header and type
      std::complex my_complex(3,2);

      and to obtain the real and imaginary part back you can type:

      • thank you a lot,

        I keep on studiing itpp and cpp, Now I may have some problems with members and pointers:

        I would like to save memory, so, in C langage, I would use pointers, malloc and free.

        with CPP, I would like to use cvec* in a member, but I cannot use any
        cvec* my_cvec_pointer = new cvec(nomber_of_samples);

        I still look for a solution,

        Have a nice day!

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: