Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU Radio OOT module AttributeError: 'module' object has no attribute 'MME_cpp'

I know this question has been asked before, but I don't find a useful solution. The full error is :

Executing: "/home/mint/Documents/test_sensor/cycl_test/top_block.py"

Using Volk machine: avx_64_mmx_orc
Traceback (most recent call last):
  File "/home/mint/Documents/test_sensor/cycl_test/top_block.py", line 87, in <module>
    tb = top_block()
  File "/home/mint/Documents/test_sensor/cycl_test/top_block.py", line 61, in __init__
    self.cycl_MME_cpp_0 = cycl.MME_cpp(1000, 16, 0.1)
AttributeError: 'module' object has no attribute 'MME_cpp'

I have found some possible reasons from previous questions:

  • mismatching of function parameter(including referencing function in .cc and .h)

  • swig problem

  • callbacks in .xml file

  • nm -C -u libgnuradio-.so

I've checked the first 3 reasons, but I'm not sure how to find out the undefined symblos using the last methods. There is part of the outcome:

U gsl_linalg_SV_decomp
U gsl_matrix_alloc
U gsl_matrix_set
U gsl_matrix_set_zero
U gsl_vector_alloc
U gsl_vector_get

Does this means all the gsl functions are undefined? If so how can I deal with it?

Except for the four reasons,is there any other hints about my questions?

I appreciate your help.

addendum:

1.MME_cpp_impl.cc

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gnuradio/io_signature.h>
#include "MME_cpp_impl.h"
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_linalg.h>

namespace gr {
  namespace cycl {

    MME_cpp::sptr
    MME_cpp::make(int Ns, int M, float Pfa)
    {
      return gnuradio::get_initial_sptr
        (new MME_cpp_impl(Ns, M, Pfa));
    }

    /*
 * The private constructor
 */
MME_cpp_impl::MME_cpp_impl(int Ns, int M, float Pfa)
  : gr::sync_block("MME_cpp",
          gr::io_signature::make(1, 1, sizeof(float)),
          gr::io_signature::make(1, 1, sizeof(float))),
    d_Ns(Ns), d_M(M), d_Pfa(Pfa)
{}

/*
 * Our virtual destructor.
 */
MME_cpp_impl::~MME_cpp_impl()
{
}

/*This function gives the CDF value for the pfa in input*/
float 
TracyWidom (float p){
    float pd, tw;
    tw = 0.45;
    pd = 1 - p;
    if (pd >= 0.01 && pd <= 0.05){
    tw = 18*(pd - (17/75)); printf("a - %f\n", tw);
    }else if (pd >= 0.05 && pd <= 0.1){
    tw = 8*(pd - (179/400)); printf("b - %f\n", tw);
    }else if (pd >= 0.1 && pd <= 0.3){
    tw = (87/20)*(pd - (643/870)); printf("c - %f\n", tw);
    }else if (pd >= 0.3 && pd <= 0.5){
    tw = (16/5)*(pd - (287/320)); printf("d - %f\n", tw);
    }else if (pd >= 0.5 && pd <= 0.7){
    tw = (17/5)*(pd - (297/340)); printf("e - %f\n", tw);
    }else if (pd >= 0.7 && pd <= 0.9){
    tw = (5.2)*(pd - (0.813)); printf("f - %f\n", tw);
    }else if (pd >= 0.9 && pd <= 0.95){
    tw = (53/5)*(pd - (909/1060)); printf("g - %f\n", tw);
    }else if (pd >= 0.95 && pd <= 1){
    tw = 26*(pd - (593/650)); printf("h - %f\n", tw);
    }else{
    printf ("wrong pfa value: it must be between 0 and 1\n");
    printf ("the pfa value standard is 0.1\n");
    tw = (53/5)*(0.9 - (909/1060));
    }
    return tw;
    } 

/*this function calculates the threshold for the test
the inputs are: 
ns = numbers of samples/L;
L = length of the correlation function;
pfa = probability of false alarm*/
float 
gamma (int ns, int L, float tw){
    float A, B, C, ratio1, ratio2, g;
    A = sqrt(ns)+sqrt(L*ns);
    B = sqrt(ns)-sqrt(L*ns);
    C = ns*ns*L;
    ratio1 = pow(A,2)/pow(B,2);
    ratio2 = 1+( pow(A,-0.667) / pow(C,0.167) )*tw;
    g = ratio1*ratio2;
    return g;
    } 

/*This function makes the detection test*/
float 
test (float r, float t){
    float decision;
    if(r > -1){
        if(r <= t){
          decision = 0;
        }   
        else{
          decision = 1;
        }
    }
    return decision;}
    //-------------end functions-----------         

int
MME_cpp_impl::work(int noutput_items,
          gr_vector_const_void_star &input_items,
          gr_vector_void_star &output_items)
{
    const float *in = (const float *) input_items[0];
    float *out = (float *) output_items[0];
    //float cov;

    //int ninputs = input_items.size ();

    //for(int i=0; i<noutput_items*Ns; ++i){
    //  cov = compute_convariance(in[i]);
    //int lenght = floor(d_samples / d_L) * d_L;
    float vett[d_Ns];
    int lenght = floor(d_Ns / d_M) ;
    int p, j, k=0;
    float thr, lmax, lmin, ratio=-1, TW, mem=0;
    // char c[1];
    gsl_matrix * hankel = gsl_matrix_alloc (lenght,d_M);
    gsl_matrix * V = gsl_matrix_alloc (d_M,d_M);
    gsl_vector * S = gsl_vector_alloc (d_M);
    gsl_vector * temp = gsl_vector_alloc (d_M);
    //FILE *story;

    gsl_matrix_set_zero (hankel);
    TW = TracyWidom (d_Pfa);
    thr = gamma(lenght, d_M, TW); //calculate the threshold

    for (int i = 0; i < noutput_items; i++){
        vett[k]=in[i];
        k++;
        if (k >= lenght*d_M){
          k = 0;
         // story = fopen("filestory.txt", "a");

          for( p=0; p<lenght; p++ ){
            for( j=0; j<d_M; j++ ){
                gsl_matrix_set (hankel, p, j, vett[p+j]);
            }
          }
        gsl_linalg_SV_decomp (hankel, V, S, temp);//using SDV to calculate eigenvalue
        lmax = gsl_vector_get(S, 0);//maximal eigenvalue
        lmin = gsl_vector_get(S, (d_M -1));//minimal eigenvalue
        ratio = lmax/lmin;
        mem = test(ratio, thr);
        //fprintf(story, "%f - ratio=%f - soglia=%f\n ", mem, ratio, thr);
        //fclose(story);
        }
        out[i] = mem; 
    }

    // Tell runtime system how many output items we produced.
    return noutput_items;
}

} /* namespace cycl / } / namespace gr */

2.MME_cpp_impl.h

#ifndef INCLUDED_CYCL_MME_CPP_IMPL_H
#define INCLUDED_CYCL_MME_CPP_IMPL_H

#include <cycl/MME_cpp.h>

namespace gr {
  namespace cycl {

    class MME_cpp_impl : public MME_cpp
    {
     private:
      int d_Ns, d_M;
      float d_Pfa;

     public:
      MME_cpp_impl(int Ns, int M, float Pfa);
      ~MME_cpp_impl();

      int Ns() const { return d_Ns; }
      void set_Ns(int Ns) { d_Ns = Ns; }
      int M() const { return d_M; }
      void set_M(int M) { d_M = M; }
      float Pfa() const { return d_Pfa; }
      void set_Pfa(float Pfa) { d_Pfa = Pfa; }

      // Where all the action really happens
      int work(int noutput_items,
           gr_vector_const_void_star &input_items,
           gr_vector_void_star &output_items);
      //float compute_covariance(float & d, int i, int j);
    friend float TracyWidom (float p);
    friend float gamma (int ns, int L, float tw);
    friend float test (float r, float t);
    };

    float TracyWidom (float p);
    float gamma (int ns, int L, float tw);
    float test (float r, float t);

  } // namespace cycl
} // namespace gr

#endif /* INCLUDED_CYCL_MME_CPP_IMPL_H */

3.MME_cpp.h

#ifndef INCLUDED_CYCL_MME_CPP_H
#define INCLUDED_CYCL_MME_CPP_H

#include <cycl/api.h>
#include <gnuradio/sync_block.h>

namespace gr {
  namespace cycl {

    /*!
     * \brief <+description of block+>
     * \ingroup cycl
     *
     */
    class CYCL_API MME_cpp : virtual public gr::sync_block
    {
     public:
      typedef boost::shared_ptr<MME_cpp> sptr;

      /*!
       * \brief Return a shared_ptr to a new instance of cycl::MME_cpp.
       *
       * To avoid accidental use of raw pointers, cycl::MME_cpp's
       * constructor is in a private implementation
       * class. cycl::MME_cpp::make is the public interface for
       * creating new instances.
       */
      static sptr make(int Ns, int M, float Pfa);

      virtual int Ns() const = 0;
      virtual void set_Ns(int Ns) = 0;
      virtual int M() const = 0;
      virtual void set_M(int M) = 0;
      virtual float Pfa() const = 0;
      virtual void set_Pfa(float Pfa) = 0;
    };

  } // namespace cycl
} // namespace gr

#endif /* INCLUDED_CYCL_MME_CPP_H */

4.cycl_MME_cpp.xml

<?xml version="1.0"?>
<block>
  <name>MME_cpp</name>
  <key>cycl_MME_cpp</key>
  <category>cycl</category>
  <import>import cycl</import>
  <make>cycl.MME_cpp($Ns, $M, $Pfa)</make>
  <callback>set_Ns($Ns)</callback>
  <callback>set_M($M)</callback>
  <callback>set_Pfa($Pfa)</callback>

  <param>
    <name>Number of samples</name>
    <key>Ns</key>
    <type>int</type>
  </param>
 <param>
    <name>Length of correlation function</name>
    <key>M</key>
    <type>int</type>
  </param>
 <param>
    <name>false probability</name>
    <key>Pfa</key>
    <type>float</type>
  </param>


  <sink>
    <name>in</name>
    <type>float</type>
  </sink>


  <source>
    <name>out</name>
    <type>float</type>
  </source>
</block>
like image 454
Betty Avatar asked Mar 03 '16 17:03

Betty


2 Answers

I had the same problem while developing a block. I noticed that the CMake script complained that the swig library is missing. Although this was not a fatal error, it does not work without it.

After installing swig I could use my module: sudo apt-get install swig

like image 94
Johannes Mittendorfer Avatar answered Nov 15 '22 03:11

Johannes Mittendorfer


This is likely due to the path that your .so is installed by default. I recently ran into this issue, and found that /usr/local/lib was not in my /etc/ld.so.conf by default (Arch Linux). After updating /etc/ld.so.conf, I ran:

sudo ldconfig

and the issue was resolved.

like image 38
Shaun Hey Avatar answered Nov 15 '22 05:11

Shaun Hey