mrcdr / pylanczos

Python wrapper for Lambda Lanczos
MIT License
16 stars 0 forks source link

problem with custom matrix-vector multiplication #4

Closed lotshawpc closed 8 months ago

lotshawpc commented 8 months ago

I am having trouble with the custom matrix-vector multiplication function, would you please help?

I am trying to adjust your example "sample3_custom.py" to include a "standard" matrix-vector multiplication, with a 2D matrix and a 1D vector, rather than a high-dimensional tensor. Eventually I would like to have a custom function for this, but for now I am just trying to verify that I can make the program work with a minimal example. For this, I have tried to solve the same problem as in your implementation of "sample3_custom.py", using

mat=np.zeros(16,dtype=np.float64).reshape(4,4)
mat[0,0]=1
mat[0,3]=1
mat[1,2]=1
mat[1,3]=1
mat[2,1]=1
mat[2,3]=1
mat[3,0]=1
mat[3,1]=1
mat[3,2]=1
def mv_mul(v_in, v_out):
    v_out = np.dot(mat,v_in)

However, this gives an eigenvalue of 0.0, which is not the same as the eigenvalue returned by your tensor-based implementation. I also found eigenvalues of 0.0 for a variety of other problems using a similar approach. Would you please help?

lotshawpc commented 8 months ago

I was able to resolve this adequately using the sparse matrix routine