Is it possible to declare the matrix is symmetric in advance before multiplication?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gasper Hsieh
am 9 Jan. 2017
Kommentiert: Walter Roberson
am 10 Jan. 2017
Hello,
I have a code with many large matrix multiplication and the results are all symmetric,
for example, AtA=A'*A, where A is a large real-valued matrix, and obviously AtA is a symmetric matrix.
I know in famous convex solver such as CVX which is able to declare the variable is symmetric in the beginning.
Is it possible to declare that AtA is a symmetric matrix in advance like CVX to make MATLAB computation more faster?
Thank you in advance.
0 Kommentare
Akzeptierte Antwort
James Tursa
am 9 Jan. 2017
Bearbeitet: James Tursa
am 9 Jan. 2017
No you cannot declare this explicitly. However, in some cases MATLAB will detect that there is a symmetric multiply and call symmetric BLAS matrix multiply library code instead of generic BLAS matrix multiply library code. So this speed advantage is already built into MATLAB when it can be detected. E.g., for your example:
>> A = rand(5000);
>> B = rand(5000);
>> timeit(@()A.'*B)
ans =
1.5621
>> timeit(@()A.'*A)
ans =
1.0122
For the A.'*B case, the generic BLAS matrix multiply library routine was called in the background. But in the A.'*A case, MATLAB has recognized the symmetric matrix multiply and has called a different BLAS matrix multiply routine to take advantage of this fact (as clearly evidenced by the significant timing improvement).
2 Kommentare
Walter Roberson
am 10 Jan. 2017
BLAS is automatically used by MATLAB; so is LAPACK or MKL (Intel's Math Kernel Library)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!