pybind / pybind/pybind11

[BUG]: Binding an FFTW algorithm gives different results

Open
#4,085 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

Problem description

Hello everyone,

As I am not sure if the bug I am seeing comes from pybind, the underlying library FFTW3 or the compiling/linking, I also adress this issue in the fftw3 project

Here is the minimal example that I think illustrates my problem in a practical way.

In the Git repository, we have a function foo() that uses an hard-coded vector of size 300 and computes its DFT using the FFTW3 library. I followed what is in the tutorial but with real-to-complex DFT instead.
This function is duplicated in two sources files : main.c that is built into a Main program, and bindings.cpp that is built into a Python module. Both outputs are built using cmake in a conda environment.

To compare the results, the foo() function prints the FFT plan and the ouput complex array.

When launching the foo function from both module and program, I get differences in the output vector (left is the C program call, right is the Python module call) :
image

Because the input vector for the FFT is hard-coded, I don't think there is a data corruption from pybind. Any idea why we see this behavior ?

Note : the hard-coded vector has been generated with random numbers with numpy, then scaled to 100.
Note 2: taking a small vector (10 elements) shows no differences.

pybind version: 2.9.2
fftw3 version: 3.3.4

Reproducible example code
[minimal example](https://github.com/robin-cls/fftw3_pybind)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal example, comparing main.c and bindings.cpp and how CMake builds each target in the conda environment. Reproduce the differing FFT outputs for the 300-element input, then compare the FFTW tutorial usage and dependency versions; done means identifying the source of the discrepancy and documenting or correcting it.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, python
Domain
build-system, hpc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.