x(:)=sparse(42) makes x sparse

David Bateman David.Bateman at motorola.com
Tue Dec 11 09:32:32 CST 2007


Kim Hansen wrote:
> On Dec 11, 2007 4:05 PM, Kim Hansen <kimhanse at gmail.com> wrote:
>   
>> On Dec 11, 2007 3:29 PM, David Bateman <David.Bateman at motorola.com> wrote:
>>     
>>> Kim Hansen wrote:
>>>       
>>>> I don't think this was meant to convert x to sparse:
>>>>
>>>> octave:1> x=zeros(2,2);
>>>> octave:2> x(:)=sparse(42)
>>>> x =
>>>>
>>>> Compressed Column Sparse (rows = 2, cols = 2, nnz = 4)
>>>>
>>>>   (1, 1) ->  42
>>>>   (2, 1) ->  42
>>>>   (1, 2) ->  42
>>>>   (2, 2) ->  42
>>>>
>>>> octave:3> x=zeros(2,2,2);
>>>> octave:4> x(:)=sparse(42)
>>>> error: invalid conversion of NDArray to Matrix
>>>> error: assignment failed, or no method for `matrix = sparse matrix'
>>>> error: evaluating assignment expression near line 4, column 5
>>>> octave:4>
>>>>
>>>>
>>>>         
>>> Ok, that should not happen apparently.. Please try the attached patch
>>>       
>> Works fine.
>>     
>
> I don't know if it was this change that broke a test on mode(), it
> fails in my newest build but not on a build from a few days ago.
>
> The output from mode(sprandn (32, 32, 0.05)) should be a sparse array,
> but it is full. The entire error is:
>
> octave:16> test mode
>   ***** test
>  a = sprandn (32, 32, 0.05);
>  [m, f, c] = mode (a);
>  [m2, f2, c2] = mode (full (a));
>  assert (m, sparse (m2, 1));
>  assert (f, sparse (f2, 1));
>  assert (c, cellfun (@(x) sparse (1, 1), c2, 'UniformOutput', false));
> !!!!! test failed
> error: assert (m,sparse (m2, 1)) expected
> Compressed Column Sparse (rows = 1, cols = 32, nnz = 0)
> but got
>    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
> 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
> Type matrix != sparse matrix
> octave:17>
>
>   
Humm, ok this is fixed in my patch9 sent in another message. I had not
thought that the assignment code should affect that part, but apparently
did..

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 Bug-octave mailing list