[SciPy-User] Single precision FFT insufficiently accurate.

Ralf Gommers ralf.gommers@googlemail....
Mon Jun 28 07:37:02 CDT 2010


On Mon, Jun 28, 2010 at 7:45 PM, Pauli Virtanen <pav@iki.fi> wrote:

> Mon, 28 Jun 2010 13:21:25 +0200, Sebastian Haase wrote:
> [clip]
> > What size of error are talking about anyway ..?
>
> We are talking about 0.1% ... 5% relative error,
>
>        import numpy as np
>        from scipy.fftpack import fft, ifft
>
>        x = np.random.rand(2011).astype(np.float32)
>        np.linalg.norm(x - ifft(fft(x))) / np.linalg.norm(x)
>        # -> 0.001  norm-2 relative error
>
>        x = np.random.rand(2012).astype(np.float32)
>        np.linalg.norm(x - ifft(fft(x))) / np.linalg.norm(x)
>        # -> 6e-5  norm-2 relative error
>
>        x = np.random.rand(8923).astype(np.float32)
>        np.linalg.norm(x - ifft(fft(x))) / np.linalg.norm(x)
>        # -> 0.03  norm-2 relative error
>
>        x = np.random.rand(8925).astype(np.float32)
>        np.linalg.norm(x - ifft(fft(x))) / np.linalg.norm(x)
>        # -> 2.4902545e-07 norm-2 relative error
>
> So for "difficult" cases the error is up to several orders of magnitude
> larger than for the "easy" cases.
>
> > Personally I would
> > leave it in, and make a note in the doc-string about expected precision
> > error for non multiple-2 dimensions for single precision float.
> > Maybe one could (for now) even append an option for
> > "workaroundFloat32PrecisionLoss"
>
> Several percent errors are not something I'd like to leave for the users
> to sort out by themselves, even if mentioned in the documentation.
>
> I would perhaps rather drop the feature in 0.8 and wait for a proper fix
> in 0.9 (hopefully later this year), than add keyword arguments that we
> have to deprecate later on.
>
> Anne's argument sounded convincing, so I think the way it is now in the
0.8.x branch is fine. Probably good to add a warning in the docstrings like:

    .. note:: In scipy 0.8.0 `fft` in single precision is available, but
*only*
        for input array sizes which can be factorized into (combinations of)
2,
        3 and 5. For other sizes the computation will be done in double
        precision.

Ralf


> --
> Pauli Virtanen
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20100628/3775b656/attachment.html 


More information about the SciPy-User mailing list