Browse Source

FFT-MKL: reuse matching descriptor (cache=1)

pull/445/head
Christoph Ruegg 10 years ago
parent
commit
12f1c7bb3e
  1. 46
      src/Numerics/Providers/FourierTransform/Mkl/MklFourierTransformProvider.cs

46
src/Numerics/Providers/FourierTransform/Mkl/MklFourierTransformProvider.cs

@ -36,6 +36,10 @@ namespace MathNet.Numerics.Providers.FourierTransform.Mkl
{ {
public class MklFourierTransformProvider : IFourierTransformProvider public class MklFourierTransformProvider : IFourierTransformProvider
{ {
IntPtr _currentHandle = IntPtr.Zero;
int _currentLength = -1;
FourierTransformScaling _currentScaling = FourierTransformScaling.NoScaling;
/// <summary> /// <summary>
/// Try to find out whether the provider is available, at least in principle. /// Try to find out whether the provider is available, at least in principle.
/// Verification may still fail if available, but it will certainly fail if unavailable. /// Verification may still fail if available, but it will certainly fail if unavailable.
@ -128,18 +132,44 @@ namespace MathNet.Numerics.Providers.FourierTransform.Mkl
public void ForwardInplace(Complex[] complex, FourierTransformScaling scaling) public void ForwardInplace(Complex[] complex, FourierTransformScaling scaling)
{ {
IntPtr handle; if (_currentHandle == IntPtr.Zero)
SafeNativeMethods.z_fft_create(out handle, complex.Length, ForwardScaling(scaling, complex.Length), 1.0); {
SafeNativeMethods.z_fft_forward_inplace(handle, complex); SafeNativeMethods.z_fft_create(out _currentHandle, complex.Length, ForwardScaling(scaling, complex.Length), BackwardScaling(scaling, complex.Length));
SafeNativeMethods.x_fft_free(ref handle); }
else
{
if (complex.Length != _currentLength || scaling != _currentScaling)
{
SafeNativeMethods.x_fft_free(ref _currentHandle);
_currentHandle = IntPtr.Zero;
SafeNativeMethods.z_fft_create(out _currentHandle, complex.Length, ForwardScaling(scaling, complex.Length), BackwardScaling(scaling, complex.Length));
_currentLength = complex.Length;
_currentScaling = scaling;
}
}
SafeNativeMethods.z_fft_forward_inplace(_currentHandle, complex);
} }
public void BackwardInplace(Complex[] complex, FourierTransformScaling scaling) public void BackwardInplace(Complex[] complex, FourierTransformScaling scaling)
{ {
IntPtr handle; if (_currentHandle == IntPtr.Zero)
SafeNativeMethods.z_fft_create(out handle, complex.Length, 1.0, BackwardScaling(scaling, complex.Length)); {
SafeNativeMethods.z_fft_backward_inplace(handle, complex); SafeNativeMethods.z_fft_create(out _currentHandle, complex.Length, ForwardScaling(scaling, complex.Length), BackwardScaling(scaling, complex.Length));
SafeNativeMethods.x_fft_free(ref handle); }
else
{
if (complex.Length != _currentLength || scaling != _currentScaling)
{
SafeNativeMethods.x_fft_free(ref _currentHandle);
_currentHandle = IntPtr.Zero;
SafeNativeMethods.z_fft_create(out _currentHandle, complex.Length, ForwardScaling(scaling, complex.Length), BackwardScaling(scaling, complex.Length));
_currentLength = complex.Length;
_currentScaling = scaling;
}
}
SafeNativeMethods.z_fft_backward_inplace(_currentHandle, complex);
} }
public Complex[] Forward(Complex[] complexTimeSpace, FourierTransformScaling scaling) public Complex[] Forward(Complex[] complexTimeSpace, FourierTransformScaling scaling)

Loading…
Cancel
Save