lesgourg / class_public

Public repository of the Cosmic Linear Anisotropy Solving System (master for the most recent version of the standard code; GW_CLASS to include Cosmic Gravitational Wave Background anisotropies; classnet branch for acceleration with neutral networks; ExoCLASS branch for exotic energy injection; class_matter branch for FFTlog)
235 stars 291 forks source link

Implementing a new function in wrapper Classy #196

Open alessiospuriomancini opened 6 years ago

alessiospuriomancini commented 6 years ago

I added a function in spectra.c and it works very well producing exactly the output that I would like it to compute, if I call it through Class. Here the declarations in spectra.c and spectra.h:

in spectra.c:

double function_at_k_and_z(struct background * pba,
                          struct spectra * psp,
                          struct perturbs *ppt,
                          double k,
                          double z,
                          double * pk_ic) 
{      ...... function
...... return  something}

in spectra.h:

double function_at_k_and_z (struct background * pba,
                          struct spectra * psp,
              struct perturbs *ppt,
                          double k,
                          double z,
                          double * pk_ic);

Now I would like to call this function in python through the wrapper Classy. Then I write

in classy.pyx:


def my_function(self, double k, double z):
        cdef double dummy
        result = function_at_k_and_z(&self.ba, &self.sp, &self.pt, k, z, &dummy)
        return result

and in cclassy.pxd I add the same definition that I gave in spectra.h.

However, this seems to ruin everything! I cannot compile the wrapper at all: all the functions, including the other ones already defined, produce errors when I insert this definiton in spectra.h!!

Can anyone help me implement my function in the wrapper Classy?

ThomasTram commented 6 years ago

Hi

Could you send the first and last part of the error message you get when you try to compile classy, and also a git diff? It is probably something simple like a missing semicolon, a tab character or a wrong indentation.

Cheers, Thomas

alessiospuriomancini commented 6 years ago

Hi,

Just now I tried removing the spacing and putting everything on one line in classy.pxd :

double function_at_k_and_z (background * pba, spectra * psp, perturbs *ppt, double k, double z, double * pk_ic)

This compiles now. I am unfortunately experiencing a segmentation error now, which I traced back to an integer variable defined in my added function in Class, but I guess this depends on me now, so I will not bother you with that :)

Thank you for your help anyway. I guess you can then confirm that (apart from the segmentation fault which I am getting now) the procedure I described sounds correct in order to implement a new function in the wrapper?

Cheers