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

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

[Octave-bug-tracker] [bug #41799] Example sparse matrix created in oct-f


From: Rik
Subject: [Octave-bug-tracker] [bug #41799] Example sparse matrix created in oct-file with 0 index
Date: Thu, 05 Jun 2014 00:22:52 +0000
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0

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

The manual lists 3 different ways of creating a sparse matrix.  The first
method listed, which has the problem code, is actually not even recommended
for significant usage.  The issue is that two copies of the matrix will exist
which doubles the host memory requirement.  So, in practice, method 1 should
only be used for small problems.  If it is only being used for small problems,
then I think it is better to emphasize code readability rather than
performance.  In this case, creating a sparse matrix in an oct-file looks
pretty much like writing the same code in an m-file.  The C++ code looks very
much like the following Octave code.


i = [1 2 2 3];
j = [1 2 4 4];
v = [1 2 3 4];
S = sparse (i, j, v);


versus


ColumnVector ridx (nz);
ColumnVector cidx (nz);
ColumnVector data (nz);

ridx(0) = 1; cidx(0) = 1; data(0) = 1;
ridx(1) = 2; cidx(1) = 2; data(1) = 2;
ridx(2) = 2; cidx(2) = 4; data(2) = 3;
ridx(3) = 3; cidx(3) = 4; data(3) = 4;
SparseMatrix sm (data, ridx, cidx, nr, nc);



    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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