mahout-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Laszlo Dosa" <laszlo.d...@fredhopper.com>
Subject RE: SequentialAccessSparseVector iterator() and iterateNonZero() odd behaviour
Date Sun, 29 Aug 2010 17:30:32 GMT
Thanks.

-----Original Message-----
From: Ted Dunning [mailto:ted.dunning@gmail.com] 
Sent: Friday, August 27, 2010 10:59 PM
To: user@mahout.apache.org
Subject: Re: SequentialAccessSparseVector iterator() and iterateNonZero() odd behaviour

I formatted your tests as a patch and attached them to the bug itself.

On Fri, Aug 27, 2010 at 8:38 AM, Laszlo Dosa <laszlo.dosa@fredhopper.com>wrote:

> It is files as MAHOUT-489.
>
> Regards,
>
> Laszlo
>
> -----Original Message-----
> From: Ted Dunning [mailto:ted.dunning@gmail.com]
> Sent: 25 August 2010 19:20
> To: user@mahout.apache.org
> Subject: Re: SequentialAccessSparseVector iterator() and iterateNonZero()
> odd behaviour
>
> Can you file a bug report at http://issues.apache.org/jira/browse/MAHOUT ?
>
> Please attach your test case.
>
> On Wed, Aug 25, 2010 at 7:25 AM, Laszlo Dosa <laszlo.dosa@fredhopper.com
> >wrote:
>
> > Hi,
> >
> >
> >
> > I tried to iterate over the elements of a SequentialAccessSparseVector.
> >
> > I run the following test and I observed that both iterators skip items:
> >
> >
> >
> >                int [] index = new int[] { 0, 1, 2, 3, 4, 5 };
> >
> >                int [] values = new int[] { 0, 1, 2, 3, 4, 5 };
> >
> >                SequentialAccessSparseVector vector;
> >
> >
> >
> >                @Before
> >
> >                public void setUp() {
> >
> >                               vector = new
> SequentialAccessSparseVector(6);
> >
> >                               for(int i = 0; i < Math.min(index.length,
> > values.length); i++ ) {
> >
> >                                               vector.set(index[i],
> > values[i]);
> >
> >                               }
> >
> >                }
> >
> > Case A:
> >
> >                @Test
> >
> >                public void testIteratorAll() {
> >
> >
> >
> >                               int elements = 0;
> >
> >                               Iterator<Element> it = vector.iterator();
> >
> >                               while (it.hasNext()) {
> >
> >
> > System.out.println(it.next().get());
> >
> >                                               elements++;
> >
> >                               }
> >
> >
> >
> >
> > assertEquals((int)vector.get(Math.min(index.length,
> > values.length)-1),values[Math.min(index.length, values.length)-1]);
> >
> > à                          assertEquals(Math.min(index.length,
> > values.length),elements);
> >
> >                }
> >
> >
> >
> > Case B:
> >
> >                @Test
> >
> >                public void testIteratorNonNull() {
> >
> >                               int elements = 0;
> >
> >                               Iterator<Element> it =
> > vector.iterateNonZero();
> >
> >                               while (it.hasNext()) {
> >
> >
> > System.out.println(it.next().get());
> >
> >                                               elements++;
> >
> >
> >
> >                               }
> >
> >
> >
> >
> > assertEquals((int)vector.get(Math.min(index.length,
> > values.length)-1),values[Math.min(index.length, values.length)-1]);
> >
> > è                        assertEquals(Math.min(index.length,
> > values.length),elements);
> >
> >                }
> >
> >
> >
> > In both cases the second assertEquals fails, which indicates that not all
> > elements have been reached.
> >
> >
> >
> > The result are as follows:
> >
> > Case A: Skips the last item.
> >
> > 0.0
> >
> > 1.0
> >
> > 2.0
> >
> > 3.0
> >
> > 4.0
> >
> >
> >
> > Case B: Skips the first item.
> >
> > 1.0
> >
> > 2.0
> >
> > 3.0
> >
> > 4.0
> >
> > 5.0
> >
> >
> >
> > Is this the expected behavior or do I misuse the library?
> >
> >
> >
> > Regards,
> >
> > Laszlo
> >
> >
>
>


Mime
View raw message