Slicing in sparse

David Bateman David.Bateman at motorola.com
Tue Dec 4 05:13:24 CST 2007


Kim Hansen wrote:
> On Dec 3, 2007 5:29 PM, David Bateman <David.Bateman at motorola.com> wrote:
>   
>> Please try the following patch
>>
>>     
>
> Thanks, it solved my problem.
>
> There is still a few differences left between sparse and full:
>
> octave:4> x=sparse(ones([2 0])); x(1)=2
> x = Compressed Column Sparse (rows = 1, cols = 1, nnz = 1)
>   (1, 1) ->  2
> octave:5> x=ones([2 0]); x(1)=2
> error: A(I) = X: unable to resize A
> error: assignment failed, or no method for `matrix = scalar'
> error: evaluating assignment expression near line 5, column 20
>
> octave:5> x=sparse(ones([2 0])); x(3,:)=2
> x = Compressed Column Sparse (rows = 2, cols = 0, nnz = 0)
> octave:6> x=ones([2 0]); x(3,:)=2
> x = [](3x0)
> octave:7>
>
>   
Running a similar set of tests under Matlab2007a I get

>> x=sparse(ones([2 0])); x(1)=2

x =

   (1,1)        2

>> size(x)

ans =

     2     1

>> x=ones([2 0]); x(1)=2
???  In an assignment  A(I) = B, a matrix A cannot be resized.

>> x=sparse(ones([2 0])); x(3,:)=2

x =

   All zero sparse: 3-by-0

>> x=ones([2 0]); x(3,:)=2

x =

   Empty matrix: 3-by-0

>> x=sparse([]); x(3,:)=2     

x =

   (3,1)        2

So yes there are some inconsistency here, both with Octave and between
full and sparse matrices in matlab itself. The attached patch makes
Octave matlab compatible wrt this subset of indexing. With this patch in
Octave I see

octave:1>  x=sparse(ones([2 0])); x(1)=2
x =

Compressed Column Sparse (rows = 2, cols = 1, nnz = 1)

  (1, 1) ->  2

octave:2> size(x)
ans =

   2   1

octave:3> x=ones([2 0]); x(1)=2
error: A(I) = X: unable to resize A
error: assignment failed, or no method for `matrix = scalar'
error: evaluating assignment expression near line 3, column 20
octave:3>  x=sparse(ones([2 0])); x(3,:)=2
x = Compressed Column Sparse (rows = 3, cols = 0, nnz = 0)

octave:4>  x=ones([2 0]); x(3,:)=2
x = [](3x0)
octave:5>  x=sparse([]); x(3,:)=2
x =

Compressed Column Sparse (rows = 3, cols = 1, nnz = 1)

  (3, 1) ->  2

which duplicates the matlab behavior.

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

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch45
Url: https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20071204/e6dff07a/attachment.ksh 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch45.changelog
Url: https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20071204/e6dff07a/attachment-0001.ksh 


More information about the Bug-octave mailing list