Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYSTEMDS-3632] Sparse Reuse of RowVectors
I had an issue when reusing sparseRowVectors, where the maximum number of non zeros in a Sparse Row is set to the number of columns for the parent SparseMCSR Block. But when reusing the rows in allocations of append with other sparse blocks some edge cases increased the number of non zero values above the number of columns in the original matrix. to fix this i made a few changes inside the Sparse CSR blocks, and while at it made an mini optimization of the posFIndexGTE(int r, int c), method to reduce the number of if statements improving overall performance. Closes #1924
- Loading branch information
1 parent
65e31c7
commit 00e68df
Showing
7 changed files
with
203 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/test/java/org/apache/sysds/test/component/matrix/SparseCSRTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.sysds.test.component.matrix; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.sysds.runtime.compress.CompressedMatrixBlock; | ||
import org.apache.sysds.runtime.data.SparseBlockCSR; | ||
import org.junit.Test; | ||
|
||
public class SparseCSRTest { | ||
protected static final Log LOG = LogFactory.getLog(CompressedMatrixBlock.class.getName()); | ||
|
||
@Test | ||
public void testGTE() { | ||
int[] rs = new int[] {0, 9}; | ||
int[] colInd = new int[] {10, 20, 30, 40, 50, 60, 80, 90, 100}; | ||
double[] val = new double[] {1, 1, 1, 1, 1, 1, 1, 1, 1}; | ||
SparseBlockCSR b = new SparseBlockCSR(rs, colInd, val, val.length); | ||
|
||
assertEquals(0, b.posFIndexGTE(0, 0)); | ||
assertEquals(0, b.posFIndexGTE(0, 10)); | ||
assertEquals(1, b.posFIndexGTE(0, 11)); | ||
assertEquals(7, b.posFIndexGTE(0, 90)); | ||
assertEquals(8, b.posFIndexGTE(0, 91)); | ||
assertEquals(-1, b.posFIndexGTE(0, 101)); | ||
assertEquals(-1, b.posFIndexGTE(0, 10100)); | ||
|
||
} | ||
|
||
@Test | ||
public void testGTE2Rows() { | ||
int[] rs = new int[] {0, 0, 9}; | ||
int[] colInd = new int[] {10, 20, 30, 40, 50, 60, 80, 90, 100}; | ||
double[] val = new double[] {1, 1, 1, 1, 1, 1, 1, 1, 1}; | ||
SparseBlockCSR b = new SparseBlockCSR(rs, colInd, val, val.length); | ||
LOG.error(b); | ||
|
||
assertEquals(0, b.posFIndexGTE(1, 0)); | ||
assertEquals(0, b.posFIndexGTE(1, 10)); | ||
assertEquals(1, b.posFIndexGTE(1, 11)); | ||
assertEquals(7, b.posFIndexGTE(1, 90)); | ||
assertEquals(8, b.posFIndexGTE(1, 91)); | ||
assertEquals(-1, b.posFIndexGTE(1, 101)); | ||
assertEquals(-1, b.posFIndexGTE(1, 10100)); | ||
|
||
} | ||
|
||
@Test | ||
public void testGTE2RowsNN() { | ||
int[] rs = new int[] {0, 1, 10}; | ||
int[] colInd = new int[] {100, 10, 20, 30, 40, 50, 60, 80, 90, 100}; | ||
double[] val = new double[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; | ||
SparseBlockCSR b = new SparseBlockCSR(rs, colInd, val, val.length); | ||
LOG.error(b); | ||
|
||
assertEquals(0, b.posFIndexGTE(1, 0)); | ||
assertEquals(0, b.posFIndexGTE(1, 10)); | ||
assertEquals(1, b.posFIndexGTE(1, 11)); | ||
assertEquals(7, b.posFIndexGTE(1, 90)); | ||
assertEquals(8, b.posFIndexGTE(1, 91)); | ||
assertEquals(-1, b.posFIndexGTE(1, 101)); | ||
assertEquals(-1, b.posFIndexGTE(1, 10100)); | ||
|
||
} | ||
} |