Is Matlab do LU in pure half (FP16) if input is A_h=half(A_d)? which A_d is rand(n)
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Steven Lord
2022-6-10
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.
回答(1 个)
Balavignesh
2024-1-17
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!