Exemplo n.º 1
0
Vector * Vector_create(int length)
{
    Vector * vector = (Vector *)malloc(sizeof(Vector));
    if (!vector) {
        return NULL;
    }
    FFTW_COMPLEX * data = (FFTW_COMPLEX*)FFTW_MALLOC(sizeof(FFTW_COMPLEX) * length);
    if (!data) {
        Vector_destroy(vector);
        return NULL;
    }
    vector->data = data;
    vector->length = length;
    return vector;
}
Exemplo n.º 2
0
static void dummy_g_realloc(int mesh) {
  size_t new_size;
  if((dummy_g != NULL) && (mesh <= dummy_g_size))
    return;

  new_size = ((mesh - dummy_g_size) < DUMMY_G_STEP) ? (dummy_g_size + DUMMY_G_STEP) : mesh;
  new_size = (new_size < DUMMY_G_MIN_SIZE) ? DUMMY_G_MIN_SIZE : new_size;
  new_size = (new_size > DUMMY_G_MAX_SIZE) ? mesh : new_size;

  dummy_g_size = new_size;

  new_size = new_size*new_size*new_size*sizeof(FLOAT_TYPE);

  if(dummy_g != NULL)
    FFTW_FREE(dummy_g);

  dummy_g = (FLOAT_TYPE *)FFTW_MALLOC(new_size);

  assert(dummy_g != NULL);
  
  for(int i = 0; i < mesh*mesh*mesh; i++)
    dummy_g[i] = 1.0;
}
Exemplo n.º 3
0
int gen(int type, int sz)
{
        float_prec *a, *b;
        FFTW_PLAN p;
        int i, tp;

        a = FFTW_MALLOC(sizeof(*a) * sz);
        if (a == NULL) {
                fprintf(stderr, "failure\n");
                exit(EXIT_FAILURE);
        }
        b = FFTW_MALLOC(sizeof(*b) * sz);
        if (b == NULL) {
                fprintf(stderr, "failure\n");
                exit(EXIT_FAILURE);
        }

        switch(type) {
                case DCT_I:
                        tp = FFTW_REDFT00;
                        break;
                case DCT_II:
                        tp = FFTW_REDFT10;
                        break;
                case DCT_III:
                        tp = FFTW_REDFT01;
                        break;
                case DCT_IV:
                        tp = FFTW_REDFT11;
                        break;
                case DST_I:
                        tp = FFTW_RODFT00;
                        break;
                case DST_II:
                        tp = FFTW_RODFT10;
                        break;
                case DST_III:
                        tp = FFTW_RODFT01;
                        break;
                case DST_IV:
                        tp = FFTW_RODFT11;
                        break;
                default:
                        fprintf(stderr, "unknown type\n");
                        exit(EXIT_FAILURE);
        }

        switch(type) {
            case DCT_I:
            case DCT_II:
            case DCT_III:
            case DCT_IV:
                for(i=0; i < sz; ++i) {
                    a[i] = i;
                }
                break;
            case DST_I:
            case DST_II:
            case DST_III:
            case DST_IV:
/*                TODO: what should we do for dst's?*/
                for(i=0; i < sz; ++i) {
                    a[i] = i;
                }
                break;
            default:
                fprintf(stderr, "unknown type\n");
                exit(EXIT_FAILURE);
        }

        p = FFTW_PLAN_CREATE(sz, a, b, tp, FFTW_ESTIMATE);
        FFTW_EXECUTE(p);
        FFTW_DESTROY_PLAN(p);

        for(i=0; i < sz; ++i) {
                printf(PF"\n", b[i]);
        }
        FFTW_FREE(b);
        FFTW_FREE(a);

        return 0;
}