title: Sparse constrained linear least-squares solver
body: <p><a href="https://stackoverflow.com/questions/1242190/c-memory-efficient-solution-for-axb-linear-algebra-system/1279744#1279744">This great SO answer</a> points to a good sparse solver for <code>Ax=b</code>, but I've got constraints on <code>x</code> such that each element in <code>x</code> is <code>&gt;=0</code> an <code>&lt;=N</code>. </p>
  
  <p>Also, <code>A</code> is <em>huge</em> (around 2e6x2e6) but very sparse with <code>&lt;=4</code> elements per row.</p>
  
  <p>Any ideas/recommendations? I'm looking for something like MATLAB's <a href="http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/lsqlin.html" rel="nofollow noreferrer"><code>lsqlin</code></a> but with huge sparse matrices.</p>
  
  <p>I'm essentially trying to solve the large scale <a href="http://www.stat.berkeley.edu/users/stark/Preprints/bvls.pdf" rel="nofollow noreferrer">bounded variable least squares problem</a> on sparse matrices:</p>
  
  <p><img src="https://imgur.com/nuQFj.gif" alt="alt text"></p>
  
  <p><strong>EDIT:</strong>
  In <a href="http://cvxr.com/cvx/" rel="nofollow noreferrer">CVX</a>:</p>
  
  <pre><code>cvx_begin
      variable x(n)
      minimize( norm(A*x-b) );
      subject to 
          x &lt;= N;
          x &gt;= 0;
  cvx_end
  </code></pre>