Info
此问题已关闭。 请重新打开它进行编辑或回答。
How and when does MatLab support symatrical vector operations?
2 次查看(过去 30 天)
显示 更早的评论
Hello,
my question is following?
I want to do a vector operation and I want to be sure that MatLab takes advantage of symmetrie.
Actually I want to get the nearest neighbour of points, so i have to calculate the distance from every point to each oter point. Since I am only interest about the order and not the distance, I neglect the sqrt since its only time consuming.
So my code loooks like following:
A=rand(10000,2);
Dista=(A(:,1)-A(:,1)').^2+(A(:,2)-A(:,2)').^2
The operation
A(:,1)-A(:,1)').^2
and
(A(:,2)-A(:,2)').^2
are symmetric, since (Ai-Aj)^2==(Aj-Ai)^2.
ans i want to take advantage of this.
I read about the fact that Matlab uses a differen BLAS when detecting symmetric operations, as you can read here:
So i did the same with my code:
A = rand(10000);
B = rand(10000);
timeit(@()(A-B').^2)
timeit(@()(A-A').^2)
It shows that the difference is nearly 0, maybe 0.001%, sometimes also the asymetric one is the "faster" one.
So is there a possibility to get the advantage of the symmetrie? Or do i have to malually do it and try to linearize the problem and do some logic indexing and hopefully save some time? I mean its clearly a logical operation and MatLab supports them, but how can i benefit from it in my case??
Many thanks in advance,
Best regards
Marc
0 个评论
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!