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 Fri, 27 Aug 2010 14:38:37 GMT
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