Ejemplo n.º 1
0
void Transformer::init() {
	//printf("num_threads = %d\n", omp_get_max_threads());
    printf("nthreads = %d\n", nfft_get_num_threads());
    /* init */
    fftw_init_threads();
    fftw_plan_with_nthreads(omp_get_max_threads());
    /* precomputation (for fast polynomial transform) */
    nfsft_precompute(N, 1000.0, 0U, 0U);

    /* Initialize transform plan using the guru interface. All input and output
     * arrays are allocated by nfsft_init_guru(). Computations are performed with
     * respect to L^2-normalized spherical harmonics Y_k^n. The array of spherical
     * Fourier coefficients is preserved during transformations. The NFFT uses a
     * cut-off parameter m = 6. See the NFFT 3 manual for details.
     */
    nfsft_init(&plan, N, M);
    //nfsft_init_guru(&plan, N, M, NFSFT_MALLOC_X | NFSFT_MALLOC_F |
    //    NFSFT_MALLOC_F_HAT | NFSFT_NORMALIZED | NFSFT_PRESERVE_F_HAT,
    //    PRE_PHI_HUT | PRE_PSI | FFTW_INIT | FFT_OUT_OF_PLACE, 6);
}
Ejemplo n.º 2
0
static PyObject *nfft(PyObject *self, PyObject *args, PyObject *kwargs)
{
  PyObject *in_obj, *coord_obj;

  
  
  static char *kwlist[] = {"real_space", "coordinates", NULL};
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO", kwlist, &in_obj, &coord_obj)) {
    return NULL;
  }
  
  PyObject *coord_array = PyArray_FROM_OTF(coord_obj, NPY_DOUBLE, NPY_IN_ARRAY);
  PyObject *in_array = PyArray_FROM_OTF(in_obj, NPY_COMPLEX128, NPY_IN_ARRAY);
  if (coord_array == NULL || in_array == NULL) {
    Py_XDECREF(coord_array);
    Py_XDECREF(in_array);
    return NULL;
  }

  int ndim = PyArray_NDIM(in_array);
  if (ndim <= 0) {
    PyErr_SetString(PyExc_ValueError, "Input array can't be 0 dimensional\n");
    return NULL;
  }

  if ((PyArray_NDIM(coord_array) != 2 || PyArray_DIM(coord_array, 1) != ndim) && (ndim != 1 || PyArray_NDIM(coord_array) != 1)) {
    PyErr_SetString(PyExc_ValueError, "Coordinates must be given as array of dimensions [NUMBER_OF_POINTS, NUMBER_OF_DIMENSIONS] of [NUMBER_OF_POINTS for 1D transforms.\n");
    Py_XDECREF(coord_array);
    Py_XDECREF(in_array);
    return NULL;
  }
  int number_of_points = (int) PyArray_DIM(coord_array, 0);

  
  nfft_plan my_plan;
  int total_number_of_pixels = 1;
  int dims[ndim];
  int dim;
  for (dim = 0; dim < ndim; ++dim) {
    dims[dim] = (int)PyArray_DIM(in_array, dim);
    total_number_of_pixels *= dims[dim];
  }

  #if defined(ENABLE_THREADS)
  printf("OMP_NUM_THREADS=%s\n",getenv("OMP_NUM_THREADS"));   
  printf("nthreads = %d\n", nfft_get_num_threads());
  fftw_init_threads();
  #endif

  nfft_init(&my_plan, ndim, dims, number_of_points);
  memcpy(my_plan.f_hat, PyArray_DATA(in_array), total_number_of_pixels*sizeof(fftw_complex));
  memcpy(my_plan.x, PyArray_DATA(coord_array), ndim*number_of_points*sizeof(double));
  
  if (my_plan.nfft_flags &PRE_PSI) {
    nfft_precompute_one_psi(&my_plan);
  }

  nfft_trafo(&my_plan);

  int out_dim[] = {number_of_points};
  PyObject *out_array = (PyObject *)PyArray_FromDims(1, out_dim, NPY_COMPLEX128);
  memcpy(PyArray_DATA(out_array), my_plan.f, number_of_points*sizeof(fftw_complex));

  // Clean up memory
  
  nfft_finalize(&my_plan);

  #if defined(ENABLE_THREADS)
  fftw_cleanup_threads();
  #endif

  Py_XDECREF(coord_array);
  Py_XDECREF(in_array);
  
  return out_array;
}