You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mahout.apache.org by "Laszlo Dosa (JIRA)" <ji...@apache.org> on 2010/08/27 16:35:53 UTC

[jira] Created: (MAHOUT-489) SequentialAccessSparseVector iterators skip items

SequentialAccessSparseVector iterators skip items
-------------------------------------------------

                 Key: MAHOUT-489
                 URL: https://issues.apache.org/jira/browse/MAHOUT-489
             Project: Mahout
          Issue Type: Bug
          Components: Math
            Reporter: Laszlo Dosa


The following test cases fail, which iterates through the elements of the SequentialAccessSparseVector, because not every value is given back.
SequentialAccessSparseVector.iterator() skips the last element, while the SequentialAccessSparseVector.iterateNonZero() skips the first element.


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]);
	}
}

@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);
}

@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);  
}


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MAHOUT-489) SequentialAccessSparseVector iterators skip items

Posted by "Sean Owen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MAHOUT-489?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12914477#action_12914477 ] 

Sean Owen commented on MAHOUT-489:
----------------------------------

Lots of action here.

1. There is indeed a problem with AllIterator being off-by-one at the end. I fixed that.
2. The non-zero iterator test in the patch has a slight problem, in that it sets a value to 0 but then expects the non-zero iterator to return it. I adjusted that along with a few other small points in the test.
3. Along the way I uncovered two smallish but probably important other problems: 
  - modifying an element via the all-elements iterator didn't clear the cached length squared. Hooray for unit tests; I knew this would continue to be a gotcha though...
  - iterating over an empty vector would cause an exception :(

Commit forthcoming.

> SequentialAccessSparseVector iterators skip items
> -------------------------------------------------
>
>                 Key: MAHOUT-489
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-489
>             Project: Mahout
>          Issue Type: Bug
>          Components: Math
>            Reporter: Laszlo Dosa
>            Assignee: Sean Owen
>             Fix For: 0.4
>
>         Attachments: MAHOUT-489.patch, MAHOUT-489.patch
>
>
> The following test cases fail, which iterates through the elements of the SequentialAccessSparseVector, because not every value is given back.
> SequentialAccessSparseVector.iterator() skips the last element, while the SequentialAccessSparseVector.iterateNonZero() skips the first element.
> 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]);
> 	}
> }
> @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);
> }
> @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);  
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (MAHOUT-489) SequentialAccessSparseVector iterators skip items

Posted by "Ted Dunning (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MAHOUT-489?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ted Dunning updated MAHOUT-489:
-------------------------------

    Attachment: MAHOUT-489.patch

Updated patch with separated tests so we see both failures.

> SequentialAccessSparseVector iterators skip items
> -------------------------------------------------
>
>                 Key: MAHOUT-489
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-489
>             Project: Mahout
>          Issue Type: Bug
>          Components: Math
>            Reporter: Laszlo Dosa
>         Attachments: MAHOUT-489.patch, MAHOUT-489.patch
>
>
> The following test cases fail, which iterates through the elements of the SequentialAccessSparseVector, because not every value is given back.
> SequentialAccessSparseVector.iterator() skips the last element, while the SequentialAccessSparseVector.iterateNonZero() skips the first element.
> 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]);
> 	}
> }
> @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);
> }
> @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);  
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (MAHOUT-489) SequentialAccessSparseVector iterators skip items

Posted by "Ted Dunning (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MAHOUT-489?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ted Dunning updated MAHOUT-489:
-------------------------------

    Status: Patch Available  (was: Open)

This test should fail until the patch is updated with a fix.

> SequentialAccessSparseVector iterators skip items
> -------------------------------------------------
>
>                 Key: MAHOUT-489
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-489
>             Project: Mahout
>          Issue Type: Bug
>          Components: Math
>            Reporter: Laszlo Dosa
>         Attachments: MAHOUT-489.patch
>
>
> The following test cases fail, which iterates through the elements of the SequentialAccessSparseVector, because not every value is given back.
> SequentialAccessSparseVector.iterator() skips the last element, while the SequentialAccessSparseVector.iterateNonZero() skips the first element.
> 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]);
> 	}
> }
> @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);
> }
> @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);  
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (MAHOUT-489) SequentialAccessSparseVector iterators skip items

Posted by "Ted Dunning (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MAHOUT-489?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ted Dunning updated MAHOUT-489:
-------------------------------

    Attachment: MAHOUT-489.patch

This patch is starting as just the test as previously submitted.

All I have done is correct the style of the test and make it slightly more clear what is happening.

The fix should include this test.

> SequentialAccessSparseVector iterators skip items
> -------------------------------------------------
>
>                 Key: MAHOUT-489
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-489
>             Project: Mahout
>          Issue Type: Bug
>          Components: Math
>            Reporter: Laszlo Dosa
>         Attachments: MAHOUT-489.patch
>
>
> The following test cases fail, which iterates through the elements of the SequentialAccessSparseVector, because not every value is given back.
> SequentialAccessSparseVector.iterator() skips the last element, while the SequentialAccessSparseVector.iterateNonZero() skips the first element.
> 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]);
> 	}
> }
> @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);
> }
> @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);  
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (MAHOUT-489) SequentialAccessSparseVector iterators skip items

Posted by "Sean Owen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MAHOUT-489?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sean Owen updated MAHOUT-489:
-----------------------------

         Assignee: Sean Owen
    Fix Version/s: 0.4

I'll track this down today.

> SequentialAccessSparseVector iterators skip items
> -------------------------------------------------
>
>                 Key: MAHOUT-489
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-489
>             Project: Mahout
>          Issue Type: Bug
>          Components: Math
>            Reporter: Laszlo Dosa
>            Assignee: Sean Owen
>             Fix For: 0.4
>
>         Attachments: MAHOUT-489.patch, MAHOUT-489.patch
>
>
> The following test cases fail, which iterates through the elements of the SequentialAccessSparseVector, because not every value is given back.
> SequentialAccessSparseVector.iterator() skips the last element, while the SequentialAccessSparseVector.iterateNonZero() skips the first element.
> 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]);
> 	}
> }
> @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);
> }
> @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);  
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (MAHOUT-489) SequentialAccessSparseVector iterators skip items

Posted by "Sean Owen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MAHOUT-489?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sean Owen updated MAHOUT-489:
-----------------------------

        Status: Resolved  (was: Patch Available)
    Resolution: Fixed

> SequentialAccessSparseVector iterators skip items
> -------------------------------------------------
>
>                 Key: MAHOUT-489
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-489
>             Project: Mahout
>          Issue Type: Bug
>          Components: Math
>            Reporter: Laszlo Dosa
>            Assignee: Sean Owen
>             Fix For: 0.4
>
>         Attachments: MAHOUT-489.patch, MAHOUT-489.patch
>
>
> The following test cases fail, which iterates through the elements of the SequentialAccessSparseVector, because not every value is given back.
> SequentialAccessSparseVector.iterator() skips the last element, while the SequentialAccessSparseVector.iterateNonZero() skips the first element.
> 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]);
> 	}
> }
> @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);
> }
> @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);  
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MAHOUT-489) SequentialAccessSparseVector iterators skip items

Posted by "Hudson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MAHOUT-489?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12914559#action_12914559 ] 

Hudson commented on MAHOUT-489:
-------------------------------

Integrated in Mahout-Quality #321 (See [https://hudson.apache.org/hudson/job/Mahout-Quality/321/])
    MAHOUT-489


> SequentialAccessSparseVector iterators skip items
> -------------------------------------------------
>
>                 Key: MAHOUT-489
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-489
>             Project: Mahout
>          Issue Type: Bug
>          Components: Math
>            Reporter: Laszlo Dosa
>            Assignee: Sean Owen
>             Fix For: 0.4
>
>         Attachments: MAHOUT-489.patch, MAHOUT-489.patch
>
>
> The following test cases fail, which iterates through the elements of the SequentialAccessSparseVector, because not every value is given back.
> SequentialAccessSparseVector.iterator() skips the last element, while the SequentialAccessSparseVector.iterateNonZero() skips the first element.
> 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]);
> 	}
> }
> @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);
> }
> @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);  
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.