fortran-lang / stdlib

Fortran Standard Library
https://stdlib.fortran-lang.org
MIT License
1.05k stars 164 forks source link

Function to compute matmul(transpose(A),A)? #375

Open Beliavsky opened 3 years ago

Beliavsky commented 3 years ago

Stdlib has corr and cov functions that compute the correlation and covariance matrices of the columns of an array. Computing the correlation matrix of the columns of array A, assuming that the elements of each column have been shifted by the column mean, involves calculating

matmul(transpose(A),A)

Could this be added as a function? If this can be computed efficiently, the programmer can calculate the correlation matrix using computed or a priori means and variances, as I described in Give stats functions optional mean arguments?

BLAS does have dgemm to multiply matrices, either of which may be transposed, but does it optimize the special but common case that the two matrices are the same?

ivan-pi commented 3 years ago

I just tested this with the Linnea tool, which recommends two algorithms:

Unfortunately, the tool only supports Julia output.