I want to convert an array to a GPUarray, but Matlab truncates automatically decimals and I don´t get enough precission

Hello,
I want to convert an array to a GPUarray, but Matlab truncates automatically decimals and I don´t get enough precission. I have this simple code:
I have a file CEmb.txt, with this text:
5.0000 1256.7
5.0060 1256.71
5.0120 1256.72
5.0180 1256.73
5.0240 1256.74
5.0300 1256.75
5.0360 1256.76
5.0420 1256.77
5.0480 1256.78
5.0540 1256.79
.... a lot more.
I just type:
> CEmb=load('CEmb.txt');
>CEmb_gpu=gpuArray(CEmb);
Then I create two array of zeros and initialize Volini:
>Vol = zeros(1,6, 'gpuArray');
>Nemb = zeros (1,6, 'gpuArray');
>Volini = 69.788;
And finally I try to interpolate. When I try to do so I receive an error from interp1 that says to me some elements of the array are repeated. This is because gpuArray seems to truncate decimals.
>Vol(1)=Volini;
>Nemb(1)=interp1(CEmb(:,1),CEmb(:,2),Vol(1),'linear');
The error is the following:"Error using gpuArray/interp1
The grid (first argument) must be a finite increasing vector without repeating elements."
I want to know how to improve proper precission. When I analyse the content of CEmb_gpu I see the following:
As you can see we saved 1256.71 but in the gpu Array we obtained 1.2567, we have lost the last decimal!!!, How can we avoid this issue? Thanks in advance.
val = <page truncated: showing [1:500, 1:2] of 3474-by-2>
1.0e+03 *
0.0050 1.2567
0.0050 1.2567
0.0050 1.2567
0.0050 1.2567
0.0050 1.2567
0.0050 1.2568
0.0050 1.2568
0.0050 1.2568
0.0050 1.2568
0.0051 1.2568
[..] It continues
<... display truncated: showed [1:500, :] of 3474×2>

 Respuesta aceptada

As you can see we saved 1256.71 but in the gpu Array we obtained 1.2567, we have lost the last decimal!!!,
More likely than that what you see is not what is stored in the gpuArray. Note the " 1.0e+03 *" at the top of the display. Change the display format and check.
format longg
Now to determine why interp1 threw the error, let's check the first input of your interp1 call. Here's the error message:
The grid (first argument) must be a finite increasing vector without repeating elements.
Let's test all those pieces.
firstArgument = CEmb(:,1);
anyNonfinites = any(~isfinite(firstArgument))
increasingVectorWithoutRepeats = issorted(firstArgument, 'strictascend')
My suspicion is that at least one of anyNonfinites and increasingVectorWithoutRepeats is false.
If anyNonfinites is false, call find on isfinite(firstArgument) to locate the non-finite values. This would cause the error because as the error message states the grid must be a finite increasing vector.
If increasingVectorWithoutRepeats is false, find locations where diff(firstArgument) is less than or equal to 0. These are locations where firstArgument has either a plateau (two values that are the same) or a dip. Either of those would violate the requirement interp1 has that the grid must be increasing (either plateau or dip) and must be without repeating elements (plateau.)

Más respuestas (2)

Hello,
First, thank for your quick answer!
Next, I have tested and both functions returns Logical 0. So I think it´s false. I have executed the following (as I have understood your instructions) and I have this results(I just represent a few as my file is large):
>> find(isfinite(firstArgument))
3469
3470
3471
3472
3473
3474
>> diff(firstArgument)
ans =
0.00600000000000023
0.00599999999999934
0.00600000000000023
0.00600000000000023
0.00600000000000023
0.00599999999999934
However I don´t still understand whats happening. First because I think that these numbers are finite, maybe it is because the distance between two numbers is extremely low? Thanks again for your help!!
Finally we have found one error in the file, a value which exceeded next value, thanks for the help!

Categorías

Productos

Versión

R2018a

Etiquetas

Preguntada:

el 5 de Dic. de 2018

Respondida:

el 10 de Dic. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by