octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #51880] sparse() ignores value of scalar colum


From: Rik
Subject: [Octave-bug-tracker] [bug #51880] sparse() ignores value of scalar column index input arg
Date: Wed, 30 Aug 2017 14:56:36 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0

Follow-up Comment #5, bug #51880 (project octave):

The currently applied patch has a for loop over 'nc' which is the number of
columns which could be quite large for a sparse matrix, say 1e7.  David's
suggestion would improve performance as the for loop would only be over the
first c(0) blank columns which should be much less than 'nc' unless all of the
data is on the right-hand side of the sparse matrix.

However, I couldn't get the code to work.  I tried this


      for (octave_idx_type i = 0; i <= c(0); i++)
        xcidx(i) = 0;


According to David, all values above should be 'nz' already from the call to
change_capacity.  However, I used an assert and found that wasn't the case.


      assert (xcidx (c(0)+1) == std::max (nzm, new_nz));


change_capacity() is in Sparse.h


  void change_capacity (octave_idx_type nz)
  {
    if (nz < nnz ())
      make_unique (); // Unshare now because elements will be truncated.
    rep->change_length (nz);
  }


And change_length is in Sparse.cc


template <typename T>
void
Sparse<T>::SparseRep::change_length (octave_idx_type nz)
{
  for (octave_idx_type j = ncols; j > 0 && c[j] > nz; j--)
    c[j] = nz;



This would seem to set the last entries to the new_nz only on a truncation. 
So, in the constructor which is growing the sparse array (nz = 0 to true nz0),
maybe we have to keep the loop?  Comments?

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51880>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]