Is it possible to declare the matrix is symmetric in advance before multiplication?

조회 수: 1 (최근 30일)
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.

채택된 답변

James Tursa
James Tursa 2017년 1월 9일
편집: James Tursa 2017년 1월 9일
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
Gasper Hsieh
Gasper Hsieh 2017년 1월 10일
Dear James Tursa:
Thank you for your detailed answer, this is my first time to learn BLAS, and I just surveyed some information about this library, does the BLAS originally install in the MATLAB? My Matlab version is 8.1.0.604 (R2013a), sorry for asking this simple question, thank you for your reply again.
Walter Roberson
Walter Roberson 2017년 1월 10일
BLAS is automatically used by MATLAB; so is LAPACK or MKL (Intel's Math Kernel Library)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by