<div dir="ltr"><div><div><div>Hi,<br><br></div>Probably MATLAB is shipping with Intel MKL enabled, which probably is the fastest LAPACK implementation out there.  NumPy supports linking with MKL, and actually Anaconda does that by default, so switching to Anaconda would be a good option for you.<br><br></div>Here you have what I am getting with Anaconda's NumPy and a machine with 8 cores:<br><br>






<div>
<span style="font-family:monospace"><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">In [</span><span style="font-weight:bold;color:rgb(84,255,84);background-color:rgb(255,255,255)">1</span><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">]: </span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">import numpy as np
</span><br>
<br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">In [</span><span style="font-weight:bold;color:rgb(84,255,84);background-color:rgb(255,255,255)">2</span><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">]: </span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">testA = np.random.randn(15000, 15000)
</span><br>
<br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">In [</span><span style="font-weight:bold;color:rgb(84,255,84);background-color:rgb(255,255,255)">3</span><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">]: </span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">testb = np.random.randn(15000)
</span><br>
<br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">In [</span><span style="font-weight:bold;color:rgb(84,255,84);background-color:rgb(255,255,255)">4</span><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">]: </span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">%time testx = np.linalg.solve(testA, testb)
</span><br>CPU times: user 5min 36s, sys: 4.94 s, total: 5min 41s
<br>Wall time: 46.1 s
<br><br>
</span></div>This is not 20 sec, but it is not 3 min either (but of course that depends on your machine).<br><br></div>Francesc<br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-12-16 18:34 GMT+01:00 Edward Richards <span dir="ltr"><<a href="mailto:edwardlrichards@gmail.com" target="_blank">edwardlrichards@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  

    
  
  <div text="#000000" bgcolor="#FFFFFF">
    
    <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">I
        recently did a conceptual experiment to estimate the
        computational time required to solve an exact expression in
        contrast to an approximate solution (Helmholtz vs.
        Helmholtz-Kirchhoff integrals). The exact solution requires a
        matrix inversion, and in my case the matrix would contain ~15000
        rows.</span></p>
    <br>
    <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">On
        my machine MATLAB seems to perform this matrix inversion with
        random matrices about 9x faster (20 sec vs 3 mins). I thought
        the performance would be roughly the same because </span><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">I
          presume</span> both rely on the same LAPACK solvers.</span></p>
    <br>
    <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">I
        will not actually need to solve this problem (even at 20 sec it
        is prohibitive for broadband simulation), but if I needed to I
        would reluctantly choose MATLAB . I am simply wondering why
        there is this performance gap, and if there is a better way to
        solve this problem in numpy?</span></p>
    <br>
    <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">Thank
        you,</span></p>
    <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">Ned</span></p>
    <br>
    
    
    <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">#Python
        version<br>
      </span></p>
    <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">import
        numpy as np</span></p>
    <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">testA
        = np.random.randn(15000, 15000)</span></p>
    <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">testb
        = np.random.randn(15000)</span></p>
    <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">%time
        testx = np.linalg.solve(testA, testb)</span></p>
    <br>
    
    <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">%MATLAB
        version<br>
      </span></p>
    <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">testA
        = randn(15000);</span></p>
    <p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">testb
        = randn(15000, 1);</span></p>
    <span style="font-size:14.666666666666666px;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">tic();
      testx = testA \ testb; toc();</span>
  </div>

<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">Francesc Alted</div>
</div>