[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmenta
From: |
Rik |
Subject: |
[Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault |
Date: |
Tue, 06 Mar 2012 19:30:45 +0000 |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2 |
Follow-up Comment #13, bug #35679 (project octave):
The patch works for me. Quoting the troublesome part of the code (with JWE's
fix):
octave_idx_type ns = dv(dim);
octave_idx_type nn = n.length (ns);
dv(dim) = std::min (nn, ns);
dv.chop_trailing_singletons ();
dim = std::min (dim, dv.length ());
As I understand it, the code is attempting to limit the number of items to
look up either to the number of elements along the selected dimension OR the
number of elements requested to be returned. When median is called it needs
either 1 return value if the number of elements is odd or 2 values if the
number of elements is even.
This squares with the observed behavior.
median (rand (1,1,1,3), 4)
fails because std::min (3,1) = 1 and this sets dv(dim) to 1 which then causes
this dimension to be removed by chop_trailing_singletons. After that, stride
is calculated incorrectly because dim is too large.
The counter-example
median (rand (1,1,1,4), 4)
works because median requests the two values 2:3 in order to average them to
form the median. In this case std::min (4,2) = 2 and the dimension stays in
place.
A second counter-example also works
median (rand (1,1,1,3,2), 4)
In this case, chop_trailing_singletons can't remove dimension 4 because it is
protected by dimension 5 which is greater than 1.
So I think JWE's patch solves the problem by restricting the stride
calculation to what remains of the dimension vector.
As a last aside, the prototype for the length() function takes void as an
argument. I found the following code confusing because I thought ns was
somehow involved and it isn't.
octave_idx_type nn = n.length (ns);
I think this should be rewritten to
octave_idx_type nn = n.length ();
which compiles and works for me.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?35679>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, (continued)
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, Rik, 2012/03/01
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, Rik, 2012/03/01
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, anonymous, 2012/03/01
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, Marco Caliari, 2012/03/02
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, Rik, 2012/03/02
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, Jordi Gutiérrez Hermoso, 2012/03/02
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, Jordi Gutiérrez Hermoso, 2012/03/06
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, Rik, 2012/03/06
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, Jordi Gutiérrez Hermoso, 2012/03/06
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, John W. Eaton, 2012/03/06
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault,
Rik <=
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, John W. Eaton, 2012/03/06
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, anonymous, 2012/03/06
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, Jordi Gutiérrez Hermoso, 2012/03/06
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, John W. Eaton, 2012/03/06
- [Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault, Jordi Gutiérrez Hermoso, 2012/03/07
- Prev by Date:
[Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault
- Next by Date:
[Octave-bug-tracker] [bug #33798] CTRL_CLOSE_EVENT causes windows error
- Previous by thread:
[Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault
- Next by thread:
[Octave-bug-tracker] [bug #35679] median (rand (1, 1, 1, 3), 4) segmentation fault
- Index(es):