arrayfire / arrayfire-python

Python bindings for ArrayFire: A general purpose GPU library.

Home Page:https://arrayfire.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Discrepancy in fft2 output?

AndyGreenwell opened this issue · comments

In performing a few numerical experiments with fft2 between various environments, I have noticed what seem to be discrepancies in output values that might not be attributable just to floating point round-off error.

I would appreciate someone's take on whether I have set up this test properly for evaluating behavior of ArrayFire's fft2 function.

Setup

Configuration

  • Compare numerical output from Matlab 2017b, Anaconda 5.0.1/Python 3.6.3/Scipy 0.19.1, Julia 0.6.2, and ArrayFire 3.5.1
  • All GPU functionality executed against CUDA 8.0.61.2
  • Windows 10 operating system

Test performed

  • In all environments, construct a Float32 matrix of zeros of size (2048, 4096)
  • Fill the four 50x50 corners of the matrix with the value 1.0
  • Take the real to complex fft2 on the resulting array

Results observed

  • CPU outputs from Matlab, Scipy and Julia all match to within reasonable floating point differences
  • GPU output in Matlab matches the CPU output from all three above environments to within reasonable floating point differences
  • GPU output in arrayfire-python seems to match in one column of output, but has significant differences in the remaining columns.
    ** As a specific numerical difference, notice the value in the first row, second column of each output.
    ** For the CPU executions and Matlab GPU, the entry has a value with a real part of 9990.2 and an imaginary part of 7.6623.
    ** For the ArrayFire execution, the entry has a value with a real part of 9960.82031250 and an imaginary part 15.27970791, or if the result is transposed below a real part of 9960.82617188 and an imaginary part of 7.63974667j.

Question

  • Have I structured this test properly for execution in the arrayfire-python environment?

Request

  • Provide a utility function for gathering an ArrayFire array into a numpy array if numpy is present on the system.

Commands and Output

Matlab 2017b

>> a = zeros(2048,4096,'single');
>> ad = gpuArray(a);
>> a(1:50,1:50) = 1;
>> a(1:50,end-49:end) = 1;
>> a(end-49:end,1:50) = 1;
>> a(end-49:end,end-49:end) = 1;
>> ad = gpuArray(a);
>> bd = fft2(ad);
>> b = fft2(a);
>> b(1:10,1:10)

ans =

  10×10 single matrix

  Columns 1 through 6

  1.0000000e+04 + 0.0000000e+00i  9.9901953e+03 + 7.6623907e+00i  9.9608184e+03 + 1.5279749e+01i  9.9119746e+03 + 2.2807228e+01i  9.8438311e+03 + 3.0200647e+01i  9.7566348e+03 + 3.7416420e+01i
  9.9608193e+03 + 1.5279821e+01i  9.9510430e+03 + 2.2897202e+01i  9.9217695e+03 + 3.0439827e+01i  9.8731055e+03 + 3.7863113e+01i  9.8052178e+03 + 4.5123505e+01i  9.7183516e+03 + 5.2177799e+01i
  9.8438320e+03 + 3.0200367e+01i  9.8341582e+03 + 3.7713478e+01i  9.8052168e+03 + 4.5123173e+01i  9.7571133e+03 + 5.2385574e+01i  9.6900127e+03 + 5.9457695e+01i  9.6041543e+03 + 6.6297554e+01i
  9.6506875e+03 + 4.4412247e+01i  9.6411904e+03 + 5.1763443e+01i  9.6128066e+03 + 5.8984249e+01i  9.5656348e+03 + 6.6031860e+01i  9.4998398e+03 + 7.2864410e+01i  9.4156563e+03 + 7.9440842e+01i
  9.3840957e+03 + 5.7580696e+01i  9.3748516e+03 + 6.4714691e+01i  9.3472412e+03 + 7.1693748e+01i  9.3013613e+03 + 7.8476349e+01i  9.2373730e+03 + 8.5022018e+01i  9.1555049e+03 + 9.1291229e+01i
  9.0478047e+03 + 6.9397179e+01i  9.0388809e+03 + 7.6261902e+01i  9.0122490e+03 + 8.2950027e+01i  8.9680020e+03 + 8.9421822e+01i  8.9062969e+03 + 9.5638336e+01i  8.8273525e+03 + 1.0156185e+02i
  8.6465059e+03 + 7.9583786e+01i  8.6379688e+03 + 8.6131058e+01i  8.6125068e+03 + 9.2483597e+01i  8.5702129e+03 + 9.8603455e+01i  8.5112344e+03 + 1.0445392e+02i  8.4357813e+03 + 1.0999908e+02i
  8.1857832e+03 + 8.7900818e+01i  8.1776904e+03 + 9.4086906e+01i  8.1535771e+03 + 1.0006406e+02i  8.1135269e+03 + 1.0579652e+02i  8.0576821e+03 + 1.1124962e+02i  7.9862402e+03 + 1.1638995e+02i
  7.6720059e+03 + 9.4154678e+01i  7.6644121e+03 + 9.9940964e+01i  7.6418032e+03 + 1.0550838e+02i  7.6042583e+03 + 1.1082356e+02i  7.5519102e+03 + 1.1585425e+02i  7.4849438e+03 + 1.2056924e+02i
  7.1122246e+03 + 9.8196442e+01i  7.1051763e+03 + 1.0354982e+02i  7.0842085e+03 + 1.0867901e+02i  7.0493945e+03 + 1.1355305e+02i  7.0008579e+03 + 1.1814230e+02i  6.9387700e+03 + 1.2241808e+02i

  Columns 7 through 10

  9.6506855e+03 + 4.4412262e+01i  9.5263613e+03 + 5.1146973e+01i  9.3840957e+03 + 5.7580811e+01i  9.2243906e+03 + 6.3676044e+01i
  9.6128057e+03 + 5.8984318e+01i  9.4889590e+03 + 6.5502625e+01i  9.3472422e+03 + 7.1693794e+01i  9.1881523e+03 + 7.7521202e+01i
  9.4998398e+03 + 7.2864082e+01i  9.3774365e+03 + 7.9118256e+01i  9.2373730e+03 + 8.5021957e+01i  9.0801426e+03 + 9.0539658e+01i
  9.3133770e+03 + 8.5721733e+01i  9.1933662e+03 + 9.1669067e+01i  9.0560420e+03 + 9.7246353e+01i  8.9018877e+03 + 1.0241939e+02i
  9.0560410e+03 + 9.7246155e+01i  8.9393359e+03 + 1.0285026e+02i  8.8057949e+03 + 1.0806866e+02i  8.6558906e+03 + 1.1286887e+02i
  8.7314434e+03 + 1.0715637e+02i  8.6189102e+03 + 1.1238715e+02i  8.4901475e+03 + 1.1722084e+02i  8.3456074e+03 + 1.2162746e+02i
  8.3441182e+03 + 1.1520484e+02i  8.2365664e+03 + 1.2003874e+02i  8.1135059e+03 + 1.2446959e+02i  7.9753682e+03 + 1.2846884e+02i
  7.8994521e+03 + 1.2118526e+02i  7.7976235e+03 + 1.2560530e+02i  7.6811123e+03 + 1.2962128e+02i  7.5503271e+03 + 1.3320709e+02i
  7.4035938e+03 + 1.2493880e+02i  7.3081489e+03 + 1.2893518e+02i  7.1989424e+03 + 1.3253171e+02i  7.0763594e+03 + 1.3570422e+02i
  6.8633486e+03 + 1.2635329e+02i  6.7748604e+03 + 1.2992242e+02i  6.6736143e+03 + 1.3310135e+02i  6.5599688e+03 + 1.3586807e+02i

>> bd(1:10,1:10)

ans =

  10×10 single gpuArray matrix

  Columns 1 through 6

  1.0000000e+04 + 0.0000000e+00i  9.9901953e+03 + 7.6623096e+00i  9.9608193e+03 + 1.5279715e+01i  9.9119746e+03 + 2.2807190e+01i  9.8438320e+03 + 3.0200514e+01i  9.7566348e+03 + 3.7416363e+01i
  9.9608203e+03 + 1.5279708e+01i  9.9510430e+03 + 2.2896988e+01i  9.9217695e+03 + 3.0439701e+01i  9.8731055e+03 + 3.7863056e+01i  9.8052188e+03 + 4.5123158e+01i  9.7183506e+03 + 5.2177612e+01i
  9.8438330e+03 + 3.0200592e+01i  9.8341592e+03 + 3.7713570e+01i  9.8052188e+03 + 4.5123596e+01i  9.7571133e+03 + 5.2385696e+01i  9.6900127e+03 + 5.9457623e+01i  9.6041543e+03 + 6.6297523e+01i
  9.6506855e+03 + 4.4412113e+01i  9.6411914e+03 + 5.1763298e+01i  9.6128066e+03 + 5.8984150e+01i  9.5656348e+03 + 6.6031898e+01i  9.4998398e+03 + 7.2864044e+01i  9.4156563e+03 + 7.9440460e+01i
  9.3840967e+03 + 5.7580814e+01i  9.3748525e+03 + 6.4714752e+01i  9.3472422e+03 + 7.1693832e+01i  9.3013613e+03 + 7.8476456e+01i  9.2373740e+03 + 8.5022049e+01i  9.1555039e+03 + 9.1291382e+01i
  9.0478037e+03 + 6.9397087e+01i  9.0388809e+03 + 7.6261871e+01i  9.0122480e+03 + 8.2950119e+01i  8.9680020e+03 + 8.9421753e+01i  8.9062969e+03 + 9.5638115e+01i  8.8273516e+03 + 1.0156184e+02i
  8.6465059e+03 + 7.9583710e+01i  8.6379688e+03 + 8.6131195e+01i  8.6125078e+03 + 9.2483505e+01i  8.5702139e+03 + 9.8603386e+01i  8.5112344e+03 + 1.0445370e+02i  8.4357822e+03 + 1.0999883e+02i
  8.1857837e+03 + 8.7901047e+01i  8.1776909e+03 + 9.4087189e+01i  8.1535776e+03 + 1.0006441e+02i  8.1135278e+03 + 1.0579699e+02i  8.0576826e+03 + 1.1124986e+02i  7.9862412e+03 + 1.1638994e+02i
  7.6720059e+03 + 9.4154358e+01i  7.6644121e+03 + 9.9940605e+01i  7.6418032e+03 + 1.0550810e+02i  7.6042588e+03 + 1.1082333e+02i  7.5519102e+03 + 1.1585382e+02i  7.4849434e+03 + 1.2056885e+02i
  7.1122246e+03 + 9.8196213e+01i  7.1051772e+03 + 1.0354974e+02i  7.0842095e+03 + 1.0867896e+02i  7.0493955e+03 + 1.1355289e+02i  7.0008584e+03 + 1.1814211e+02i  6.9387705e+03 + 1.2241788e+02i

  Columns 7 through 10

  9.6506855e+03 + 4.4412270e+01i  9.5263613e+03 + 5.1146660e+01i  9.3840977e+03 + 5.7580605e+01i  9.2243916e+03 + 6.3676071e+01i
  9.6128066e+03 + 5.8984367e+01i  9.4889580e+03 + 6.5502228e+01i  9.3472422e+03 + 7.1693573e+01i  9.1881523e+03 + 7.7521240e+01i
  9.4998398e+03 + 7.2864265e+01i  9.3774355e+03 + 7.9118210e+01i  9.2373740e+03 + 8.5021736e+01i  9.0801445e+03 + 9.0539764e+01i
  9.3133770e+03 + 8.5721619e+01i  9.1933652e+03 + 9.1668533e+01i  9.0560420e+03 + 9.7246140e+01i  8.9018867e+03 + 1.0241924e+02i
  9.0560420e+03 + 9.7246361e+01i  8.9393340e+03 + 1.0285011e+02i  8.8057969e+03 + 1.0806861e+02i  8.6558916e+03 + 1.1286905e+02i
  8.7314434e+03 + 1.0715643e+02i  8.6189092e+03 + 1.1238669e+02i  8.4901475e+03 + 1.1722072e+02i  8.3456064e+03 + 1.2162760e+02i
  8.3441172e+03 + 1.1520473e+02i  8.2365664e+03 + 1.2003819e+02i  8.1135068e+03 + 1.2446938e+02i  7.9753682e+03 + 1.2846857e+02i
  7.8994521e+03 + 1.2118549e+02i  7.7976230e+03 + 1.2560516e+02i  7.6811128e+03 + 1.2962163e+02i  7.5503271e+03 + 1.3320723e+02i
  7.4035938e+03 + 1.2493860e+02i  7.3081484e+03 + 1.2893465e+02i  7.1989434e+03 + 1.3253122e+02i  7.0763594e+03 + 1.3570404e+02i
  6.8633481e+03 + 1.2635315e+02i  6.7748594e+03 + 1.2992197e+02i  6.6736152e+03 + 1.3310097e+02i  6.5599688e+03 + 1.3586806e+02i

Julia 0.6.2

   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.2 (2017-12-13 18:08 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-w64-mingw32

julia> a = zeros(Float32,2048,4096);

julia> a[1:50,1:50] = 1;

julia> a[end-49:end,end-49:end] = 1;

julia> a[end-49:end,1:50] = 1;

julia> a[1:50,end-49:end] = 1;

julia> b = fft(a);

julia> b
2048×4096 Array{Complex{Float32},2}:
 10000.0+0.0im       9990.2+7.66239im  9960.82+15.2797im      …  9960.82-15.2797im       9990.2-7.6622im
 9960.82+15.2797im  9951.04+22.8974im  9921.77+30.4397im         9921.82+0.000190735im  9951.06+7.63267im
 9843.83+30.2006im  9834.16+37.714im   9805.22+45.1234im         9805.31+15.0411im      9834.21+22.6289im
 9650.69+44.4121im  9641.19+51.7632im  9612.81+58.9841im         9612.94+29.4921im      9641.26+36.9738im
  9384.1+57.5809im  9374.85+64.7148im  9347.24+71.6939im         9347.42+43.0165im      9374.94+50.334im
  9047.8+69.3972im  9038.88+76.2618im  9012.25+82.9501im      …  9012.46+55.3005im      9038.99+62.3966im
 8646.51+79.5837im  8637.97+86.1308im  8612.51+92.4835im         8612.75+66.0603im      8638.09+72.8803im
 8185.78+87.9012im  8177.69+94.0872im  8153.58+100.064im         8153.85+75.0492im      8177.83+81.5428im
 7672.01+94.1544im  7664.41+99.9406im   7641.8+105.508im         7642.09+82.063im       7664.56+88.1835im
 7112.22+98.1964im  7105.18+103.55im   7084.21+108.679im         7084.51+86.9443im      7105.33+92.6503im
 6514.06+99.9322im  6507.59+104.825im  6488.38+109.494im      …  6488.69+89.5875im      6507.75+94.843im
 5885.56+99.321im   5879.72+103.733im  5862.35+107.925im         5862.66+89.9389im      5879.87+94.7138im
 5235.11+96.3775im   5229.9+100.294im  5214.45+103.999im         5214.75+88.0008im      5230.05+92.2716im
        ⋮                                                     ⋱                                ⋮
 5235.11-96.3775im  5230.05-92.2717im  5214.75-88.0008im         5214.45-103.999im       5229.9-100.294im
 5885.56-99.321im   5879.87-94.7138im  5862.66-89.9389im         5862.35-107.925im      5879.72-103.733im
 6514.06-99.9323im  6507.75-94.8429im  6488.69-89.5875im         6488.38-109.494im      6507.59-104.826im
 7112.22-98.1963im  7105.33-92.6503im  7084.51-86.9443im         7084.21-108.679im      7105.18-103.55im
 7672.01-94.1543im  7664.56-88.1834im  7642.09-82.0628im      …   7641.8-105.508im      7664.41-99.9406im
 8185.78-87.9011im  8177.83-81.5428im  8153.85-75.0491im         8153.58-100.064im      8177.69-94.0871im
 8646.51-79.5836im  8638.09-72.8803im  8612.75-66.0602im         8612.51-92.4834im      8637.97-86.1309im
  9047.8-69.3972im  9038.99-62.3965im  9012.46-55.3005im         9012.25-82.9501im      9038.88-76.2619im
  9384.1-57.5808im  9374.94-50.3339im  9347.42-43.0165im         9347.24-71.6937im      9374.85-64.7149im
 9650.69-44.4122im  9641.26-36.974im   9612.94-29.4923im      …  9612.81-58.9841im      9641.19-51.7635im
 9843.83-30.2006im  9834.21-22.628im   9805.31-15.0411im         9805.22-45.1234im      9834.16-37.7132im
 9960.82-15.2798im  9951.07-7.63271im  9921.82-0.000112057im     9921.77-30.4398im      9951.04-22.8975im

Anaconda 5.0.1 / Python 3.6.3 / Scipy 0.19.1 / ArrayFire 3.5.1

Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import scipy.fftpack

In [2]: import arrayfire as af

In [3]: import numpy as np

In [4]: a = np.zeros((2048,4096),dtype='float32')

In [5]: a[0:50,0:50] = 1;

In [6]: a[-50:,0:50] = 1;

In [7]: a[0:50,-50:] = 1;

In [8]: a[-50:,-50:] = 1;

In [9]: ad = af.Array(a.ctypes.data, a.shape, a.dtype.char)

In [10]: bd = af.signal.fft2(ad);

In [11]: b = scipy.fftpack.fft2(a);

In [12]: b[0:10,0:10]
Out[12]:
array([[ 10000.00000000  +0.j        ,   9990.19531250  +7.66216707j,
          9960.81933594 +15.27928734j,   9911.97460938 +22.80728149j,
          9843.83203125 +30.20039368j,   9756.63476562 +37.41600418j,
          9650.68750000 +44.41161346j,   9526.36132812 +51.14674377j,
          9384.09765625 +57.58042908j,   9224.39160156 +63.67562866j],
       [  9960.82031250 +15.27928543j,   9951.04296875 +22.89645386j,
          9921.76953125 +30.4388485j ,   9873.10449219 +37.86270905j,
          9805.21875000 +45.1227417j ,   9718.35156250 +52.17685699j,
          9612.80664062 +58.98316193j,   9488.95800781 +65.50195312j,
          9347.24218750 +71.69306183j,   9188.15234375 +77.52036285j],
       [  9843.83300781 +30.20038986j,   9834.15917969 +37.71330643j,
          9805.21875000 +45.12274551j,   9757.11230469 +52.38564301j,
          9690.01269531 +59.45753479j,   9604.15429688 +66.29711151j,
          9499.83984375 +72.86351013j,   9377.43554688 +79.11798859j,
          9237.37402344 +85.02155304j,   9080.14453125 +90.53924561j],
       [  9650.68554688 +44.41159058j,   9641.19140625 +51.76257324j,
          9612.80664062 +58.98316956j,   9565.63378906 +66.03126526j,
          9499.83984375 +72.8635025j ,   9415.65625000 +79.43978882j,
          9313.37695312 +85.72050476j,   9193.36523438 +91.66822052j,
          9056.04296875 +97.24534607j,   8901.88769531+102.41835785j],
       [  9384.09570312 +57.58043289j,   9374.85253906 +64.71422577j,
          9347.24218750 +71.69306946j,   9301.36132812 +78.47616577j,
          9237.37304688 +85.02154541j,   9155.50488281 +91.29064941j,
          9056.04199219 +97.24536133j,   8939.33398438+102.84980774j,
          8805.79687500+108.0680542j ,   8655.89160156+112.86830139j],
       [  9047.80371094 +69.39637756j,   9038.88085938 +76.26094055j,
          9012.24804688 +82.94894409j,   8968.00195312 +89.42112732j,
          8906.29687500 +95.63734436j,   8827.35156250+101.5608139j ,
          8731.44335938+107.15504456j,   8618.91015625+112.38607025j,
          8490.14746094+117.21989441j,   8345.60644531+121.62640381j],
       [  8646.50585938 +79.58358765j,   8637.96875000 +86.13063049j,
          8612.50781250 +92.48301697j,   8570.21289062 +98.60340118j,
          8511.23535156+104.4535675j ,   8435.78222656+109.99856567j,
          8344.11914062+115.20417786j,   8236.56640625+120.0382843j ,
          8113.50683594+124.46896362j,   7975.36816406+128.46818542j],
       [  8185.78369141 +87.90079498j,   8177.69140625 +94.0867157j ,
          8153.57763672+100.06369019j,   8113.52734375+105.79656982j,
          8057.68310547+111.24942017j,   7986.24121094+116.38951874j,
          7899.45312500+121.18466187j,   7797.62402344+125.60507965j,
          7681.11328125+129.6210022j ,   7550.32714844+133.20664978j],
       [  7672.00585938 +94.15422058j,   7664.41210938 +99.94036865j,
          7641.80322266+105.50764465j,   7604.25781250+110.82318115j,
          7551.91015625+115.85353851j,   7484.94335938+120.56845093j,
          7403.59472656+124.93786621j,   7308.14843750+128.93453979j,
          7198.94335938+132.53105164j,   7076.35888672+135.70358276j],
       [  7112.22558594 +98.19590759j,   7105.17773438+103.54916382j,
          7084.20947266+108.67822266j,   7049.39550781+113.55259705j,
          7000.85839844+118.14163208j,   6938.77050781+122.4172821j ,
          6863.34960938+126.35232544j,   6774.86035156+129.92172241j,
          6673.61572266+133.10049438j,   6559.96972656+135.86732483j]], dtype=complex64)

In [13]: np.reshape(af.real(bd[0:10,0:10]).to_array(),(10,10)) + 1j* np.reshape(af.imag(bd[0:10,0:10]).to_array(),(10,10))
Out[13]:
array([[ 10000.00000000  +0.j        ,   9960.82031250 +15.27970791j,
          9843.83300781 +30.20059204j,   9650.68554688 +44.41211319j,
          9384.09667969 +57.58081436j,   9047.80371094 +69.3970871j ,
          8646.50585938 +79.58370972j,   8185.78369141 +87.90104675j,
          7672.00585938 +94.15435791j,   7112.22460938 +98.19621277j],
       [  9960.82617188  +7.63974667j,   9922.37304688 +22.83113861j,
          9806.41015625 +37.60722351j,   9614.57324219 +51.62036133j,
          9349.56250000 +64.54022217j,   9015.09570312 +76.06126404j,
          8615.84765625 +85.9103241j ,   8157.37207031 +93.85339355j,
          7646.00781250 +99.70072174j,   7088.77539062+103.31070709j],
       [  9843.85546875 +15.10028267j,   9806.41992188 +30.08589172j,
          9692.37890625 +44.60408783j,   9503.34277344 +58.31238174j,
          9241.97070312 +70.88645172j,   8911.93554688 +82.02682495j,
          8517.84765625 +91.46707153j,   8065.19189453 +98.97968292j,
          7560.22851562+104.38186646j,   7009.89208984+107.53892517j],
       [  9650.73828125 +22.20603943j,   9614.59179688 +36.87163544j,
          9503.33691406 +51.02319336j,   9318.54492188 +64.32604218j,
          9062.81933594 +76.46383667j,   8739.75000000 +87.14578247j,
          8353.85546875 +96.11399078j,   7910.50878906+103.14953613j,
          7415.84082031+108.0773468j ,   6876.64550781+110.77018738j],
       [  9384.18457031 +28.79040909j,   9349.57714844 +43.02650833j,
          9241.92968750 +56.7084198j ,   9062.76269531 +69.51176453j,
          8814.60253906 +81.13082886j,   8500.93554688 +91.28530884j,
          8126.15039062 +99.72776031j,   7695.46435547+106.24877167j,
          7214.83642578+110.68280029j,   6690.86962891+112.91079712j],
       [  9047.93750000 +34.69852066j,   9015.08886719 +48.40181732j,
          8911.81347656 +61.51851654j,   8739.56835938 +73.73666382j,
          8500.78613281 +84.76317596j,   8198.82128906 +94.33047485j,
          7837.89843750+102.20306396j,   7423.04492188+108.18251801j,
          6960.00292969+112.11325073j,   6455.13378906+113.88554382j],
       [  8646.68847656 +39.79174805j,   8615.79687500 +52.86640167j,
          8517.59179688 +65.33032227j,   8353.46679688 +76.88651276j,
          8125.73632812 +87.25634766j,   7837.60400391 +96.18662262j,
          7493.10156250+103.45495605j,   7097.02929688+108.87561035j,
          6654.86914062+112.30345154j,   6172.69873047+113.6383667j ],
       [  8186.01953125 +43.95049286j,   8157.24414062 +56.30944061j,
          8064.73730469 +68.04281616j,   7909.81054688 +78.87002563j,
          7694.65234375 +88.52960205j,   7422.28906250 +96.78328705j,
          7096.53320312+103.42358398j,   6721.92529297+108.27767944j,
          6303.65136719+111.21266174j,   5847.46191406+112.13720703j],
       [  7672.29492188 +47.0770874j ,   7645.76708984 +58.64332581j,
          7559.50195312 +69.57875061j,   7414.72460938 +79.62129974j,
          7213.47998047 +88.52716827j,   6958.60009766 +96.07530212j,
          6653.65625000+102.0738678j ,   6302.89697266+106.36385345j,
          5911.18115234+108.82404327j,   5483.89501953+109.3730011j ],
       [  7112.56347656 +49.09799957j,   7088.37988281 +59.80516052j,
          7008.81201172 +69.88614655j,   6874.99218750 +79.09902954j,
          6688.81152344 +87.21903229j,   6452.88964844 +94.04324341j,
          6170.53320312 +99.39584351j,   5845.67919922+103.13275146j,
          5482.82714844+105.14454651j,   5086.96777344+105.35946655j]], dtype=complex64)

In [14]: af.display(bd[:10,:10])
bd[:10,:10]
[10 10 1 1]
         (10000.0000,0.0000)          (9960.8262,7.6397)          (9843.8555,15.1003)          (9650.7383,22.2060)          (9384.1846,28.7904)          (9047.9375,34.6985)          (8646.6885,39.7917)          (8186.0195,43.9505)          (7672.2949,47.0771)          (7112.5635,49.0980)
         (9960.8203,15.2797)          (9922.3730,22.8311)          (9806.4199,30.0859)          (9614.5918,36.8716)          (9349.5771,43.0265)          (9015.0889,48.4018)          (8615.7969,52.8664)          (8157.2441,56.3094)          (7645.7671,58.6433)          (7088.3799,59.8052)
         (9843.8330,30.2006)          (9806.4102,37.6072)          (9692.3789,44.6041)          (9503.3369,51.0232)          (9241.9297,56.7084)          (8911.8135,61.5185)          (8517.5918,65.3303)          (8064.7373,68.0428)          (7559.5020,69.5788)          (7008.8120,69.8861)
         (9650.6855,44.4121)          (9614.5732,51.6204)          (9503.3428,58.3124)          (9318.5449,64.3260)          (9062.7627,69.5118)          (8739.5684,73.7367)          (8353.4668,76.8865)          (7909.8105,78.8700)          (7414.7246,79.6213)          (6874.9922,79.0990)
         (9384.0967,57.5808)          (9349.5625,64.5402)          (9241.9707,70.8865)          (9062.8193,76.4638)          (8814.6025,81.1308)          (8500.7861,84.7632)          (8125.7363,87.2563)          (7694.6523,88.5296)          (7213.4800,88.5272)          (6688.8115,87.2190)
         (9047.8037,69.3971)          (9015.0957,76.0613)          (8911.9355,82.0268)          (8739.7500,87.1458)          (8500.9355,91.2853)          (8198.8213,94.3305)          (7837.6040,96.1866)          (7422.2891,96.7833)          (6958.6001,96.0753)          (6452.8896,94.0432)
         (8646.5059,79.5837)          (8615.8477,85.9103)          (8517.8477,91.4671)          (8353.8555,96.1140)          (8126.1504,99.7278)          (7837.8984,102.2031)          (7493.1016,103.4550)          (7096.5332,103.4236)          (6653.6563,102.0739)          (6170.5332,99.3958)
         (8185.7837,87.9010)          (8157.3721,93.8534)          (8065.1919,98.9797)          (7910.5088,103.1495)          (7695.4644,106.2488)          (7423.0449,108.1825)          (7097.0293,108.8756)          (6721.9253,108.2777)          (6302.8970,106.3639)          (5845.6792,103.1328)
         (7672.0059,94.1544)          (7646.0078,99.7007)          (7560.2285,104.3819)          (7415.8408,108.0773)          (7214.8364,110.6828)          (6960.0029,112.1133)          (6654.8691,112.3035)          (6303.6514,111.2127)          (5911.1812,108.8240)          (5482.8271,105.1445)
         (7112.2246,98.1962)          (7088.7754,103.3107)          (7009.8921,107.5389)          (6876.6455,110.7702)          (6690.8696,112.9108)          (6455.1338,113.8855)          (6172.6987,113.6384)          (5847.4619,112.1372)          (5483.8950,109.3730)          (5086.9678,105.3595)

Can you display MATLAB results at a larger precision ?

You are also not displaying bd directly. Try to use af.display(bd[:10, :10]). The numbers should be similar to what you see in matlab.

Edited the original comment to include long e output format for Matlab and the af.display output in python.

@AndyGreenwell I think it is the way you are converting numpy array to arrayfire array. I am getting correct results if I use ad = af.to_array(a) instead of the method you are using.

@pavanky Thanks, using af.to_array is giving me the proper result after subsequently performing the fft2.

I was following the third example on this page of the docs to construct the ArrayFire array from a numpy array, so possibly that example might need updating.

Proper expected output shown below.

In [15]: ad2 = af.to_array(a);

In [16]: bd2 = af.signal.fft2(ad2);

In [17]: af.display(bd2[:10,:10])
bd2[:10,:10]
[10 10 1 1]
         (10000.0000,0.0000)          (9990.1953,7.6623)          (9960.8193,15.2797)          (9911.9746,22.8072)          (9843.8320,30.2005)          (9756.6348,37.4164)          (9650.6855,44.4123)          (9526.3613,51.1467)          (9384.0977,57.5806)          (9224.3916,63.6761)
         (9960.8203,15.2797)          (9951.0430,22.8970)          (9921.7695,30.4397)          (9873.1055,37.8631)          (9805.2188,45.1232)          (9718.3506,52.1776)          (9612.8066,58.9844)          (9488.9580,65.5022)          (9347.2422,71.6936)          (9188.1523,77.5212)
         (9843.8330,30.2006)          (9834.1592,37.7136)          (9805.2188,45.1236)          (9757.1133,52.3857)          (9690.0127,59.4576)          (9604.1543,66.2975)          (9499.8398,72.8643)          (9377.4355,79.1182)          (9237.3740,85.0217)          (9080.1445,90.5398)
         (9650.6855,44.4121)          (9641.1914,51.7633)          (9612.8066,58.9841)          (9565.6348,66.0319)          (9499.8398,72.8640)          (9415.6563,79.4405)          (9313.3770,85.7216)          (9193.3652,91.6685)          (9056.0420,97.2461)          (8901.8867,102.4192)
         (9384.0967,57.5808)          (9374.8525,64.7148)          (9347.2422,71.6938)          (9301.3613,78.4765)          (9237.3740,85.0220)          (9155.5039,91.2914)          (9056.0420,97.2464)          (8939.3340,102.8501)          (8805.7969,108.0686)          (8655.8916,112.8690)
         (9047.8037,69.3971)          (9038.8809,76.2619)          (9012.2480,82.9501)          (8968.0020,89.4218)          (8906.2969,95.6381)          (8827.3516,101.5618)          (8731.4434,107.1564)          (8618.9092,112.3867)          (8490.1475,117.2207)          (8345.6064,121.6276)
         (8646.5059,79.5837)          (8637.9688,86.1312)          (8612.5078,92.4835)          (8570.2139,98.6034)          (8511.2344,104.4537)          (8435.7822,109.9988)          (8344.1172,115.2047)          (8236.5664,120.0382)          (8113.5068,124.4694)          (7975.3682,128.4686)
         (8185.7837,87.9010)          (8177.6909,94.0872)          (8153.5776,100.0644)          (8113.5278,105.7970)          (8057.6826,111.2499)          (7986.2412,116.3899)          (7899.4521,121.1855)          (7797.6230,125.6052)          (7681.1128,129.6216)          (7550.3271,133.2072)
         (7672.0059,94.1544)          (7664.4121,99.9406)          (7641.8032,105.5081)          (7604.2588,110.8233)          (7551.9102,115.8538)          (7484.9434,120.5688)          (7403.5938,124.9386)          (7308.1484,128.9346)          (7198.9434,132.5312)          (7076.3594,135.7040)
         (7112.2246,98.1962)          (7105.1772,103.5497)          (7084.2095,108.6790)          (7049.3955,113.5529)          (7000.8584,118.1421)          (6938.7705,122.4179)          (6863.3481,126.3531)          (6774.8594,129.9220)          (6673.6152,133.1010)          (6559.9688,135.8681)

I'll fix the docs thanks.