Bug in any on sparse boolean

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug in any on sparse boolean

Kim Hansen-5
I think I have found a bug that affects any() when used on sparse booleans:

octave:1> y = sparse(false(8,1));
octave:2> y(1:2,1) = true;
octave:3> v1 = any(y,2)
v1 =

Compressed Column Sparse (rows = 8, cols = 1, nnz = 2 [25%])

  (2, 1) ->  1
  (139554649, 1) ->  115

octave:4>


I would like to fix the problem and write a test, but as the any
function is a build-in I don't really know where in the code I should
do it. Should the test be with the other any() tests in src/data.cc or
with some of the sparse matrix code? Where should I look for the
problem?

Regards,
--
Kim Hansen
Vadgårdsvej 3, 2.tv
2860 Søborg
Phone: +45 3091 2437
Reply | Threaded
Open this post in threaded view
|

Re: Bug in any on sparse boolean

Kim Hansen-5
On Wed, Jan 19, 2011 at 01:08, Kim Hansen <[hidden email]> wrote:
> I think I have found a bug that affects any() when used on sparse booleans:

I am not sure that it is any() that is the problem.

My guess is now that the error is somewhere in:
    template <class T>
    Sparse<T>::Sparse (const Array<T>& a, const idx_vector& r,
                   const idx_vector& c, octave_idx_type nr,
                   octave_idx_type nc, bool sum_terms,
                   octave_idx_type nzm)


I think this is an example of how to provoke the bug:

octave:1> sparse(1, 1:5, true, 1, 5)
ans =

Compressed Column Sparse (rows = 1, cols = 5, nnz = 5 [100%])

  (1, 1) ->  1
  (-1216302479, 2) ->  1
  (135704533, 3) ->  1
  (18, 4) ->  1
  (138870485, 5) ->  1

octave:2>


The bug is on trunk and I will keep searching for a solution.

--
Kim Hansen
Vadgårdsvej 3, 2.tv
2860 Søborg
Phone: +45 3091 2437
Reply | Threaded
Open this post in threaded view
|

Re: Bug in any on sparse boolean

David Bateman-2
Kim Hansen wrote:

> On Wed, Jan 19, 2011 at 01:08, Kim Hansen <[hidden email]> wrote:
>  
>> I think I have found a bug that affects any() when used on sparse booleans:
>>    
>
> I am not sure that it is any() that is the problem.
>
> My guess is now that the error is somewhere in:
>     template <class T>
>     Sparse<T>::Sparse (const Array<T>& a, const idx_vector& r,
>                    const idx_vector& c, octave_idx_type nr,
>                    octave_idx_type nc, bool sum_terms,
>                    octave_idx_type nzm)
>
>
> I think this is an example of how to provoke the bug:
>
> octave:1> sparse(1, 1:5, true, 1, 5)
> ans =
>
> Compressed Column Sparse (rows = 1, cols = 5, nnz = 5 [100%])
>
>   (1, 1) ->  1
>   (-1216302479, 2) ->  1
>   (135704533, 3) ->  1
>   (18, 4) ->  1
>   (138870485, 5) ->  1
>
> octave:2>
>
>
> The bug is on trunk and I will keep searching for a solution.
>
>  
It is an off by one error in the changeset

http://hg.savannah.gnu.org/hgweb/octave/rev/ded9beac7582

in the method that Kim identified. I'm about the push a fix but what to
test some more first

D.

--
David Bateman                                [hidden email]
35 rue Gambetta                              +33 1 46 04 02 18 (Home)
92100 Boulogne-Billancourt FRANCE            +33 6 72 01 06 33 (Mob)

Reply | Threaded
Open this post in threaded view
|

Re: Bug in any on sparse boolean

David Bateman-2
In reply to this post by Kim Hansen-5
Kim Hansen wrote:

> On Wed, Jan 19, 2011 at 01:08, Kim Hansen <[hidden email]> wrote:
>  
>> I think I have found a bug that affects any() when used on sparse booleans:
>>    
>
> I am not sure that it is any() that is the problem.
>
> My guess is now that the error is somewhere in:
>     template <class T>
>     Sparse<T>::Sparse (const Array<T>& a, const idx_vector& r,
>                    const idx_vector& c, octave_idx_type nr,
>                    octave_idx_type nc, bool sum_terms,
>                    octave_idx_type nzm)
>
>
> I think this is an example of how to provoke the bug:
>
> octave:1> sparse(1, 1:5, true, 1, 5)
> ans =
>
> Compressed Column Sparse (rows = 1, cols = 5, nnz = 5 [100%])
>
>   (1, 1) ->  1
>   (-1216302479, 2) ->  1
>   (135704533, 3) ->  1
>   (18, 4) ->  1
>   (138870485, 5) ->  1
>
> octave:2>
>
>
> The bug is on trunk and I will keep searching for a solution.
>
>  
In fact the second problem you found Kim was an independent bug, but I
believe the changeset

http://hg.savannah.gnu.org/hgweb/octave/rev/0e414f837c58

addresses this bug and the one identified in the any function of sparse
boolean matrices

D.


Reply | Threaded
Open this post in threaded view
|

Re: Bug in any on sparse boolean

Kim Hansen-5
On Thu, Jan 20, 2011 at 02:49, David Bateman <[hidden email]> wrote:
> In fact the second problem you found Kim was an independent bug, but I
> believe the changeset
>
> http://hg.savannah.gnu.org/hgweb/octave/rev/0e414f837c58
>
> addresses this bug and the one identified in the any function of sparse
> boolean matrices

Thanks a lot, that would have taken me days to fix.

Now my program runs all the way through octave 3.3.55 without errors,
it hits a lot of corner cases in matrix resize and use of sparse
matrices.

Regards,
--
Kim Hansen
Vadgårdsvej 3, 2.tv
2860 Søborg
Phone: +45 3091 2437