Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How and when does MatLab support symatrical vector operations?

1 回表示 (過去 30 日間)
Marc Laub
Marc Laub 2020 年 4 月 25 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 件)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by