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

David Bateman David.Bateman at motorola.com
Thu Sep 18 09:51:11 CDT 2008


Jaroslav Hajek wrote:
> On Sat, Sep 13, 2008 at 10:44 PM, David Bateman <dbateman at free.fr> wrote:
>   
>> 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.
>>>
>>>       
>> # HG changeset patch
>> # User David Bateman <dbateman at free.fr>
>> # Date 1221338610 -7200
>> # Node ID 71f97e500f63e0a93e9cbe7f3cd5318827d3b3f9
>> # Parent  9fe441ffcbaa7b5e2f2c41d3e83b1769f92235da
>> cut trailing singeltons in cat function
>>
>> diff --git a/src/ChangeLog b/src/ChangeLog
>> --- a/src/ChangeLog
>> +++ b/src/ChangeLog
>> @@ -1,3 +1,7 @@ 2008-09-09  David Bateman  <dbateman at fre
>> +2008-09-13  David Bateman  <dbateman at free.fr>
>> +
>> +       * data.cc (do_cat): Chopping trailing singleton dimensions.
>> +
>>  2008-09-09  David Bateman  <dbateman at free.fr>
>>
>>        * DLD-FUNCTIONS/regexp.cc (octregexp_list): Distinguish between
>> diff --git a/src/data.cc b/src/data.cc
>> --- a/src/data.cc
>> +++ b/src/data.cc
>> @@ -1802,6 +1802,10 @@ do_cat (const octave_value_list& args, s
>>                                 dv_tmp (dim) : 1);
>>            }
>>
>> +         // Reshape, chopping trailing singleton dimensions
>> +         dv.chop_trailing_singletons ();
>> +         tmp = tmp.reshape (dv);
>> +
>>          retval = tmp;
>>        }
>>       else
>>
>> _______________________________________________
>> Help-octave mailing list
>> Help-octave at octave.org
>> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>>
>>
>>     
>
> David, this does not apply cleanly to release-3-0-x. The do_cat
> function seems to have non-trivially diverged between the branches. I
> tracked the previous changes to changeset 7997 in John's repo (by you)
> that deals mainly with single prec - apparently you fixed something
> "along the way". I can't transplant 7997 and at this moment I'm not
> 100% sure how to adapt the patch. If you wish this bug to be fixed in
> 3.0.x, please adapt the patch specially for 3.0.x.
>
> regards
>
>   
Ok, will do..

D.

-- 
David Bateman                                David.Bateman at motorola.com
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



More information about the Help-octave mailing list