Is Matlab do LU in pure half (FP16) if input is A_h=half(A_d)? which A_d is rand(n)
3 views (last 30 days)
Show older comments
I am generating random number in double and converting them to PF16 by half command. After that I am using LU like this:
[L_h, U_h, P_h]=lu(A_h);
My question is about the internal of LU for half in Matlab. Does it work purly in half? is the process same as single and double for partial pivoting? How can I understand more about it and be sure? Do matlab convert it to single and do the LU?
I think it is more accurate than what I expect. So based on my experiment it is not working in Half. Just the result is transformed to Half.
2 Comments
Steven Lord
on 10 Jun 2022
How can I understand more about it and be sure?
Do you have a specific concern about the internal implementation of the lu for half? If you want to check whether or not lu computes the correct answer you can check that L_h, U_h, P_h, and A_h satisfy the relationship in the lu documentation.
Answers (1)
Balavignesh
on 17 Jan 2024
Hi Nima,
MATLAB's built-in 'lu' function supports only 'single' and 'double' datatypes. It doesn't natively support half-precision (FP16) inputs directly. If a half-precision matrix is passed to the 'lu' function, MATLAB will likely covert it to single or double-precision internally to perform the computation. It then coverts the result back to half-precision before returning them.
If you suspect that MATLAB is coverting half-precision inputs to a higher precision for the computation, you could verify this by checking the precision of the intermediate results. You could use MATLAB's 'whos' function to inspect the variable types at various points in your code.
The following example code snippet may help you understand this:
% Generate a random matrix in double precision and convert to half precision
A = double(rand(10));
A_h = half(A);
% Perform LU decomposition
[L_h, U_h, P_h] = lu(A_h);
% Check the precision of the outputs
whos L_h U_h P_h
Kindly refer to the following documentation links to have more information on:
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!