<br><br><div class="gmail_quote">On Tue, Apr 30, 2013 at 6:37 AM, Jordi Gutiérrez Hermoso <span dir="ltr"><<a href="mailto:jordigh@octave.org" target="_blank">jordigh@octave.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

On 29 April 2013 17:51, Ed Meyer <<a href="mailto:eem2314@gmail.com">eem2314@gmail.com</a>> wrote:<br>
<br>
> I'm not saying numel() is to blame or should be changed, only that I<br>
> see no reason to ever use numel when handling sparse matrices unless<br>
> you are converting it to full in which case the current behavior is<br>
> ok.<br>
<br>
Well, look at the current implementation of trace (), in which numel<br>
is a perfectly reasonable function to call. If you don't want to ever<br>
call numel () for sparse matrices, then you would need to rewrite this<br>
function to check for sparsity as well as any other function that<br>
calls numel ().<br></blockquote><div><br></div><div>I don't see numel() used in trace(), nor in diag() which it calls - what am I missing?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


> Here again, why would you ever want A(idx) for a sparse matrix?<br>
<br>
Because this is the only way to do arbitrary indexing, say, indexing<br>
with a logical index:<br>
<br>
    n = 2^16;<br>
    A = sprandsym (n, 1e-7);<br>
    idx = A > 0.5;<br>
    A(idx) *= -1;<br>
<br>
The alternative to arbitrary indexing is looping.<br></blockquote><div> </div><div>or if octave_idx_type were a class hierarchy with a (row,col) class</div><div>in addition to linear indexing </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<br>
> I agree that a special index type is the wrong approach; what I'm<br>
> saying is that with sparse matrices you should never run into this<br>
> problem in the first place if you don't try to treat them the same<br>
> as full. Otherwise why have sparse matrices at all?<br>
<br>
It is desirable to have sparse matrices behave like ordinary matrices<br>
under most circumstances, such as indexing and when writing the trace<br>
function. Otherwise, you would have to write special code all over the<br>
place to make sure that if the matrix is sparse, you don't linearly<br>
index it nor do you call numel or who knows what other functions that<br>
I haven't thought about yet.<br>
<br>
- Jordi G. H.<br>
</blockquote></div><br>Not only is it desirable to have sparse and full matrices behave similarly,<div>I believe the user should not need to be aware of which storage format</div><div>is used so functions like eig() would work for either.</div>

<div>The key is to use the C++ class system to have different implementations</div><div>for each storage format.<br clear="all"><div><br></div>-- <br>Ed Meyer<br>
</div>