[Chanegset]: Re: cat does not convert sparse matrices?

David Bateman adb014 at gmail.com
Sat Sep 13 15:44:44 CDT 2008


dbateman wrote:
> In fact I think I see two bugs here
> 
> 
> Francesco Potorti`-2 wrote:
>> In Octave 3.0.1, I cannot catenate a full double matrix with a sparse
>> logical matrix.  Is this normal or a bug?
>>
>> octave> a=zeros(3,3,0);
>> octave> b1=zeros(3,3);
>> octave> b2=sparse(1,1,true,3,3);
>> octave> whos a b1 b2
>>
>> *** local user variables:
>>
>>   Prot Name        Size                     Bytes  Class
>>   ==== ====        ====                     =====  ===== 
>>    rwd a           3x3x0                        0  double
>>    rwd b1          3x3                         72  double
>>    rwd b2          3x3                         21  logical
>>
>> Total is 10 elements using 93 bytes
>>
>> octave> size(cat(3,a,b1))
>> ans =
>>
>>    3   3   1
>>
> 
> Trailing singleton dimensions should be dropped, So I suspect there is a
> function call missing in the cat function that should do this.
> 

The attached patch addresses this, but

> 
> 
>> octave> size(cat(3,a,b2))
>> error: invalid conversion of NDArray to Matrix
>> error: range error for insert
>> error: evaluating argument list element number 1
>>
> 
> The sparse logical matrix should be promoted to a sparse matrix and the
> concatenation allowed. Ok, I'll look at this wen I'm on a development
> machine.

It seems I missed the point you made by this one.. Sparse logical 
matrices are promoted to sparse double matrices before concatenation 
with another double matrix. The issue above is that a 3x3x0 is an 
NDArray and the Sparse matrix type only supports 2D arrays and so the 
conversion of the 3x3x0 array to a sparse matrices prior to the 
concatenation fails. It would be interesting to know what matlab does in 
this case, as I suspect it fails as well. If it doesn't then I suppose 
we need to special case for this.

In fact we used to special case for all empty matrices in data.cc 
(do_cat) and just drop them from the concatenation. However, something 
like "cat(1,[],single([]))" must return a single precision empty matrix 
and so even empty matrices play their part in selecting the type of the 
returned matrix. So care would have to be taken if we did allow this not 
to cause other issues.

Cheers
David






> 
> D.
> 

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch8524
Url: https://www-old.cae.wisc.edu/pipermail/help-octave/attachments/20080913/2f2939bb/attachment.ksh 


More information about the Help-octave mailing list