ARM-software / CMSIS-DSP

CMSIS-DSP embedded compute library for Cortex-M and Cortex-A
https://arm-software.github.io/CMSIS-DSP
Apache License 2.0
548 stars 143 forks source link

LDLT decomposition returns diagonal matrix D non-optimally #119

Open yuvpg opened 1 year ago

yuvpg commented 1 year ago

1. LDL^t decomposition function arm_mat_ldlt_f32 return diagonal matrix D as n×n matrix, but it real application you will probably never need it as a matrix, just n-vector with diagonal values will be sufficient.

For example, when solving system of linear equations with the help of LDLt, in intermediate calculations one should solve equation D.z=y, which is trivial element-by-element vector division z=y/diag(D).

Maybe it is worth considering return D as an vector instead of matrix?

2. Additionally, the description of permutation vector P in documentation is not complete. It is impossible to understand how to use returned vector pp from documentation. Hopefully in examples there is a piece of python code which describe the intent:

print("LDLT")

def swaprow(m,k,j):
    tmp = np.copy(m[j,:])
    m[j,:] = np.copy(m[k,:])
    m[k,:] = tmp 
    return(m)

# F32 test
status,resl,resd,resperm=dsp.arm_mat_ldlt_f32(a)
n=3
p=np.identity(n)
for k in range(0,n):
    p = swaprow(p,k,resperm[k])

res=resl.dot(resd).dot(resl.T)

permutedSrc=p.dot(a).dot(p.T)
christophe0606 commented 1 year ago

@yuvpg Thank for good feedback. I'll look at the implementation to understand why D is not returned as vector.