Skip to content

lstsq problem #9891

@eigenjohnson

Description

@eigenjohnson

I have noticed a problem with numpy's lstsq when I have a complex matrix and multiple right hand sides. If the number of right hand sides is large enough - then I end up with a malloc core dump. This is strange since lstsq should compute the SVD and then just multiply it across all of the right hand sides (and my work around is to use SVD in exactly this way). This seems to happen on linux and windows - and also Python 2.7 and 3.5. I am attaching a code segment. I would appreciate to know if anyone thinks that I have made a mistake in my usage of lstsq or maybe a namespace conflict.

    # test python complex lstsq against multiple right hand sides
    # The lstsq code works great on real valued problems 
    # - but freaks out on complex - and can cause a malloc core dump
    from scipy import *
    from pylab import *
    
    Ntest = 700
    G = randn(200,50)+1j*randn(200,50)
    u = randn(50,Ntest) + 1j*randn(50,Ntest)
    b = dot(G,u)
    
    # this works for moderately large Ntest (linus and windows, python 2.7 and 3.5)
    U,S,VH = svd(G,full_matrices=False)
    K = dot(VH.conjugate().transpose(),dot(diag(1.0/S),U.conjugate().transpose()))
    u2 = dot(K,b)
    
    print('found u2 shape',u2.shape)
    print('SVD solution is good - error {0:g}'.format(abs(u2-u).max()))
    
    print('\n')
    
    # whereas, this crashes for some Ntest big enough for your system
    u3,res,rnk,sv = lstsq(G,b)
    print('found u3 shape',u3.shape)
    print('LSTSQ solution is good - error {0:g}'.format(abs(u3-u).max())) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions