octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Pkg-octave-devel] Bug#394982: octave2.9: Crashes on "x(:,


From: David Bateman
Subject: Re: [Pkg-octave-devel] Bug#394982: octave2.9: Crashes on "x(:,
Date: Thu, 26 Oct 2006 00:07:50 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

Rafael Laboissiere wrote:
> package octave2.9
> reopen 394982
> thanks
> 
> * Kim Hansen <address@hidden> [2006-10-25 13:20]:
> 
>> On 10/25/06, David Bateman <address@hidden> wrote:
>>> Ok, Please consider the attached patch. Note that this implies a double
>>> reassignment of the lhs, but really this is a crazy thing to do, so as
>>> long as it doesn't crash and gives the right result I don't feel it has
>>> to be efficient. If it was really an important case, then there should
>>> be special cases for this. With this patch I get the following results.
>> My goal is to build a large sparse matrix out of an unknown number of
>> smaller matrices, that is why I would like it to readjust its size as
>> I am assigning to it. Your fix works on the first assignment, but
>> octave crashes on the second.
>>
>> x = sparse(2,0)
>> x(:,1:2) = speye(2)  # crashed here before fix
>> x(:,3:4) = speye(2)  # now it crashes here.
> 
> I confirm the problem in octave2.9_2.9.9-4.  I am hereby reopening the bug
> report.
> 


Ok then use the attached patch in addition to the previous patch... It
essentially removes the previous patch and does it differently.

Note that this is still a very bad idea as it reallocates the memory to
the sparse matrix and every assignment, even if you size the initial
matrix correctly. This is due to the fact that only enough space for the
nonzeros is ever created... I'd therefore highly recommended forming
vectors of row, col and value and use the sparse function instead. This
is discussed in the sparse section of the manual....

Regards
David

Index: liboctave/Sparse.cc
===================================================================
RCS file: /cvs/octave/liboctave/Sparse.cc,v
retrieving revision 1.19
diff -c -r1.19 Sparse.cc
*** liboctave/Sparse.cc 25 Oct 2006 01:40:26 -0000      1.19
--- liboctave/Sparse.cc 25 Oct 2006 22:04:30 -0000
***************
*** 2471,2481 ****
  
                      Sparse<LT> stmp (new_nr, new_nc, new_nzmx);
  
-                     // Started with an empty matrix. Now that we know
-                     // the assignment will succeed, resize lhs 
-                     if (lhs_nr <= 0 || lhs_nc <= 0)
-                       lhs = Sparse<RT>(n, m);
- 
                      octave_idx_type jji = 0;
                      octave_idx_type jj = idx_j.elem (jji);
                      octave_idx_type kk = 0;
--- 2471,2476 ----
***************
*** 2487,2494 ****
                              octave_idx_type iii = 0;
                              octave_idx_type ii = idx_i.elem (iii);
                              octave_idx_type ppp = 0;
!                             octave_idx_type ppi = lhs.cidx(j+1) - 
!                               lhs.cidx(j); 
                              octave_idx_type pp = (ppp < ppi ? 
                                                    lhs.ridx(lhs.cidx(j)+ppp) :
                                                    new_nr);
--- 2482,2490 ----
                              octave_idx_type iii = 0;
                              octave_idx_type ii = idx_i.elem (iii);
                              octave_idx_type ppp = 0;
!                             octave_idx_type ppi = (j >= lhs_nc ? 0 : 
!                                                    lhs.cidx(j+1) - 
!                                                    lhs.cidx(j));
                              octave_idx_type pp = (ppp < ppi ? 
                                                    lhs.ridx(lhs.cidx(j)+ppp) :
                                                    new_nr);
***************
*** 2628,2638 ****
  
                      Sparse<LT> stmp (new_nr, new_nc, new_nzmx);
  
-                     // Started with an empty matrix. Now that we know
-                     // the assignment will succeed, resize lhs 
-                     if (lhs_nr <= 0 || lhs_nc <= 0)
-                       lhs = Sparse<RT>(n, m);
- 
                      octave_idx_type jji = 0;
                      octave_idx_type jj = idx_j.elem (jji);
                      octave_idx_type kk = 0;
--- 2624,2629 ----
***************
*** 2644,2651 ****
                              octave_idx_type iii = 0;
                              octave_idx_type ii = idx_i.elem (iii);
                              octave_idx_type ppp = 0;
!                             octave_idx_type ppi = lhs.cidx(j+1) -
!                               lhs.cidx(j);
                              octave_idx_type pp = (ppp < ppi ? 
                                                    lhs.ridx(lhs.cidx(j)+ppp) :
                                                    new_nr);
--- 2635,2643 ----
                              octave_idx_type iii = 0;
                              octave_idx_type ii = idx_i.elem (iii);
                              octave_idx_type ppp = 0;
!                             octave_idx_type ppi = (j >= lhs_nc ? 0 : 
!                                                    lhs.cidx(j+1) - 
!                                                    lhs.cidx(j));
                              octave_idx_type pp = (ppp < ppi ? 
                                                    lhs.ridx(lhs.cidx(j)+ppp) :
                                                    new_nr);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]