Double Precision Complex Exponential

[Old posts from the commercial version of ArrayFire] Discussion of ArrayFire using CUDA or OpenCL.

Moderator: pavanky

Double Precision Complex Exponential

Postby neuralPanther » Mon Mar 17, 2014 9:51 pm

Hi All,

I have an issue with my data representation in the c++ version. I believe it's a single precision/double precision issue.
In my code I need to perform a complex double precision exponential on a sequence of data:
Code: Select all
% in MATLAB:
outSignal = exp(-j*[1:length]*2*pi*constant);


I've attempted to replicate this in ArrayFire C/C++ with:
Code: Select all
// in ArrayFire
af::array TempArray = af::exp((af::i)*af::seq(1,1,length)*(-2.0L)*constant*af::Pi).as(af::c64);


However I do not get the same results (first 10 elements of the sequences):

MATLAB:
0
0.098017140329561 + 0.995184726672197i
0
0
-0.857728610000272 - 0.514102744193222i
-0.290284677254462 - 0.956940335732209i
0
0
0
0


Array Fire:

0
0.098017100000000 - 0.995185000000000i
0
0
-0.857729000000000 + 0.514103000000000i
-0.290285000000000 + 0.956940000000000i
0
0
0
0



The data is very similar but the ArrayFire data is missing several digits of precision. Is there anything else I can do to force the precision of the ArrayFire Exp Function and it's sub elements (pi, i, etc). Note that both arrayFire and MATLAB are operating on identical data sets.

Thanks!

~ NP
neuralPanther
 
Posts: 25
Joined: Fri Feb 14, 2014 8:03 pm

Re: Double Precision Complex Exponential

Postby pavanky » Mon Mar 17, 2014 11:16 pm

Move the .as(c64) inside the exp.

i.e. af::exp((af::i).as(c64)).
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA

Re: Double Precision Complex Exponential

Postby pavanky » Mon Mar 17, 2014 11:19 pm

The outputs also seem to be conjugates of each other... May be something else is also missing ?
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA

Re: Double Precision Complex Exponential

Postby neuralPanther » Tue Mar 18, 2014 12:46 pm

Moving the .as(af::c64) inside the exp doesn't work (at least on af::i). When I do:
Code: Select all
af::array tempArray= af::exp((af::i).as(af::c64)*af::seq(1,1,length)*(-2.0L*(constant))*af::Pi).as(af::c64);

This section
Code: Select all
(af::i).as(af::c64)


produces:
error C2039: 'as' : is not a member of 'float2'

If I then do:
Code: Select all
 
af::array jj = af::constant(0.0,1,af::c64);
jj(0) = af::i;
af::array tempArray= af::exp(jj(0).as(af::c64)*af::seq(1,1,length)*(-2.0L*(constant))*af::Pi).as(af::c64);


The data resulting is no longer complex:
0
0.988561000000000
0
0
0.971648000000000
0.966074000000000
0
0
0
0

And there is still the truncation issue ...

Thanks again,

~ NP
neuralPanther
 
Posts: 25
Joined: Fri Feb 14, 2014 8:03 pm

Re: Double Precision Complex Exponential

Postby pavanky » Tue Mar 18, 2014 1:08 pm

Can you give me the values of length and constant so I can try to reproduce the problem ?
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA

Re: Double Precision Complex Exponential

Postby neuralPanther » Tue Mar 18, 2014 4:05 pm

Use 100 points for the length, and .11 as the constant

In AF:
Code: Select all
jj(0) = af::i;
af::array temp2Array = af::exp(jj(0).as(af::c64)*af::seq(1,1,100)*(-2.0L*(.11))*af::Pi).as(af::c64);

//first 10 elements
   0.994615000000000
   0.989259000000000
   0.983932000000000
   0.978633000000000
   0.973363000000000
   0.968121000000000
   0.962908000000000
   0.957723000000000
   0.952565000000000
   0.947436000000000



in MATLAB:
Code: Select all
temp = exp(-j*[1:100]*2*pi*(.11));
% first 10 elements

  0.770513242775789 + 0.637423989748690i
  0.187381314585725 + 0.982287250728689i
 -0.481753674101715 + 0.876306680043864i
 -0.929776485888251 + 0.368124552684678i
 -0.951056516295154 - 0.309016994374947i
 -0.535826794978997 - 0.844327925502015i
  0.125333233564304 - 0.992114701314478i
  0.728968627421411 - 0.684547105928689i
  0.998026728428272 - 0.062790519529313i
  0.809016994374948 + 0.587785252292473i

neuralPanther
 
Posts: 25
Joined: Fri Feb 14, 2014 8:03 pm

Re: Double Precision Complex Exponential

Postby pavanky » Tue Mar 18, 2014 4:13 pm

Try this:
Code: Select all
        af::array S = af::array(af::seq(1,1,100)).as(f64);
        cdouble J = {0, 1};
        af::array temp = af::exp(J * S * 2 * af::Pi * 0.11);
        cdouble *h_temp = temp.host<cdouble>();
        for (int i = 0; i < 10; i++) {
            printf("%.32lf, %.32lf\n", h_temp[i].x, h_temp[i].y);
        }


Here are the results:

$ ./helloworld_cuda
0.77051324277578925325826730841072, 0.63742398974868963446027692043572
0.18738131458572471199630626870203, 0.98228725072868861012409524846589
-0.48175367410171499038540332549019, 0.87630668004386369496216957486467
-0.92977648588825134723379051138181, 0.36812455268467814128996451472631
-0.95105651629515364220424089580774, -0.30901699437494728472941574182187
-0.53582679497899710074904078282998, -0.84432792550201474224280673297471
0.12533323356430423056728784558800, -0.99211470131447787590417419778532
0.72896862742141133040263412112836, -0.68454710592868894813989300018875
0.99802672842827155896827662218129, -0.06279051952931326285867186243195
0.80901699437494756228517189811100, 0.58778525229247291505885186779778
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA


Return to [archive-commercial] Programming & Development with ArrayFire

cron