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: Wed, 25 Oct 2006 00:26:00 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

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.


octave:1> x(:,:) = speye(1)
x =  1
octave:2> y(:,:) = speye(3)
y =

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

  (1, 1) ->  1
  (2, 2) ->  1
  (3, 3) ->  1

octave:3> z(:,1:3) = speye(3)
z =

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

  (1, 1) ->  1
  (2, 2) ->  1
  (3, 3) ->  1

octave:4> q(:,1:2) = speye(3)
error: A(I, J) = X: X must be a scalar or the number of elements in I must
error: match the number of rows in X and the number of elements in J must
error: match the number of columns in X
error: assignment failed, or no method for `<unknown type> = sparse matrix'
error: evaluating assignment expression near line 4, column 10
octave:4>


D.

2006-10-24  David Bateman  <address@hidden>

        * Sparse.cc (assign (Sparse<LT>&, const Sparse<RT>&)): Resize the
        lhs at the point we know the assignment can succeed if the lhs is
        empty.

Index: liboctave/Sparse.cc
===================================================================
RCS file: /cvs/octave/liboctave/Sparse.cc,v
retrieving revision 1.18
diff -c -r1.18 Sparse.cc
*** liboctave/Sparse.cc 29 Jun 2006 18:04:21 -0000      1.18
--- liboctave/Sparse.cc 24 Oct 2006 22:24:32 -0000
***************
*** 2471,2476 ****
--- 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;
***************
*** 2623,2628 ****
--- 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;

reply via email to

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