This is an automated email from the ASF dual-hosted git repository.
mboehm7 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git
The following commit(s) were added to refs/heads/main by this push:
new 84f915715e [SYSTEMDS-3420] Fix robustness spark remove-empty operations
84f915715e is described below
commit 84f915715ea76feb1e98e242eeb78af943f07300
Author: Matthias Boehm <[email protected]>
AuthorDate: Sat Aug 13 19:03:02 2022 +0200
[SYSTEMDS-3420] Fix robustness spark remove-empty operations
This patch fixes a robustness issue of spark remove-empty rows/columns
operations where the offsets contained indexes larger than the max
output dimension, causing misleading errors such as 'Invalid block
dimensions: -1360007040 14'. However, the real underlying issue is
likely a size propagation issue, because maxDim is supported to be the
max of the offset vector.
---
.../sysds/runtime/matrix/data/LibMatrixReorg.java | 70 ++---
.../functions/unary/matrix/RemoveEmptyTest.java | 335 +++++++++------------
2 files changed, 173 insertions(+), 232 deletions(-)
diff --git
a/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixReorg.java
b/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixReorg.java
index 7c78f8f1a6..f09be4b4bf 100644
--- a/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixReorg.java
+++ b/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixReorg.java
@@ -677,29 +677,29 @@ public class LibMatrixReorg {
MatrixIndexes tmpIx = new MatrixIndexes(-1,-1);
if( rmRows ) //margin = "rows"
{
- long rlen = len;
+ long rlen = len; //max dimensionality
long clen = linData.getNumColumns();
for( int i=0; i<linOffset.getNumRows(); i++ ) {
long rix = (long)linOffset.quickGetValue(i, 0);
- if( rix > 0 ) //otherwise empty row
- {
- //get single row from source block
- MatrixBlock src = linData.slice(i, i,
0, (int)(clen-1), new MatrixBlock());
- long brix = (rix-1)/blen+1;
- long lbrix = (rix-1)%blen;
- tmpIx.setIndexes(brix,
data.getIndexes().getColumnIndex());
- //create target block if necessary
- if( !out.containsKey(tmpIx) ) {
- IndexedMatrixValue tmpIMV = new
IndexedMatrixValue(new MatrixIndexes(),new MatrixBlock());
-
tmpIMV.getIndexes().setIndexes(tmpIx);
-
((MatrixBlock)tmpIMV.getValue()).reset((int)Math.min(blen,
rlen-((brix-1)*blen)), (int)clen);
- out.put(tmpIMV.getIndexes(),
tmpIMV);
- }
- //put single row into target block
-
((MatrixBlock)out.get(tmpIx).getValue()).copy(
- (int)lbrix,
(int)lbrix, 0, (int)clen-1, src, false);
+ if( rix <= 0 || rix > rlen ) //skip empty row /
cut-off rows
+ continue;
+
+ //get single row from source block
+ MatrixBlock src = linData.slice(i, i, 0,
(int)(clen-1), new MatrixBlock());
+ long brix = (rix-1)/blen+1;
+ long lbrix = (rix-1)%blen;
+ tmpIx.setIndexes(brix,
data.getIndexes().getColumnIndex());
+ //create target block if necessary
+ if( !out.containsKey(tmpIx) ) {
+ IndexedMatrixValue tmpIMV = new
IndexedMatrixValue(new MatrixIndexes(),new MatrixBlock());
+ tmpIMV.getIndexes().setIndexes(tmpIx);
+
((MatrixBlock)tmpIMV.getValue()).reset((int)Math.min(blen,
rlen-((brix-1)*blen)), (int)clen);
+ out.put(tmpIMV.getIndexes(), tmpIMV);
}
+ //put single row into target block
+ ((MatrixBlock)out.get(tmpIx).getValue()).copy(
+ (int)lbrix, (int)lbrix, 0, (int)clen-1,
src, false);
}
}
else //margin = "cols"
@@ -709,24 +709,24 @@ public class LibMatrixReorg {
for( int i=0; i<linOffset.getNumColumns(); i++ ) {
long cix = (long)linOffset.quickGetValue(0, i);
- if( cix > 0 ) //otherwise empty row
- {
- //get single row from source block
- MatrixBlock src = linData.slice(0,
(int)(rlen-1), i, i, new MatrixBlock());
- long bcix = (cix-1)/blen+1;
- long lbcix = (cix-1)%blen;
-
tmpIx.setIndexes(data.getIndexes().getRowIndex(), bcix);
- //create target block if necessary
- if( !out.containsKey(tmpIx) ) {
- IndexedMatrixValue tmpIMV = new
IndexedMatrixValue(new MatrixIndexes(),new MatrixBlock());
-
tmpIMV.getIndexes().setIndexes(tmpIx);
-
((MatrixBlock)tmpIMV.getValue()).reset((int)rlen,(int)Math.min(blen,
clen-((bcix-1)*blen)));
- out.put(tmpIMV.getIndexes(),
tmpIMV);
- }
- //put single row into target block
-
((MatrixBlock)out.get(tmpIx).getValue()).copy(
- 0, (int)rlen-1,
(int)lbcix, (int)lbcix, src, false);
+ if( cix <= 0 || cix > clen ) //skip empty col /
cut-off cols
+ continue;
+
+ //get single row from source block
+ MatrixBlock src = linData.slice(0,
(int)(rlen-1), i, i, new MatrixBlock());
+ long bcix = (cix-1)/blen+1;
+ long lbcix = (cix-1)%blen;
+
tmpIx.setIndexes(data.getIndexes().getRowIndex(), bcix);
+ //create target block if necessary
+ if( !out.containsKey(tmpIx) ) {
+ IndexedMatrixValue tmpIMV = new
IndexedMatrixValue(new MatrixIndexes(),new MatrixBlock());
+ tmpIMV.getIndexes().setIndexes(tmpIx);
+
((MatrixBlock)tmpIMV.getValue()).reset((int)rlen,(int)Math.min(blen,
clen-((bcix-1)*blen)));
+ out.put(tmpIMV.getIndexes(), tmpIMV);
}
+ //put single row into target block
+ ((MatrixBlock)out.get(tmpIx).getValue()).copy(
+ 0, (int)rlen-1, (int)lbcix, (int)lbcix,
src, false);
}
}
diff --git
a/src/test/java/org/apache/sysds/test/functions/unary/matrix/RemoveEmptyTest.java
b/src/test/java/org/apache/sysds/test/functions/unary/matrix/RemoveEmptyTest.java
index 90ff2c3a03..e23ece97af 100644
---
a/src/test/java/org/apache/sysds/test/functions/unary/matrix/RemoveEmptyTest.java
+++
b/src/test/java/org/apache/sysds/test/functions/unary/matrix/RemoveEmptyTest.java
@@ -20,7 +20,6 @@
package org.apache.sysds.test.functions.unary.matrix;
import org.junit.Test;
-import org.apache.sysds.api.DMLScript;
import org.apache.sysds.common.Types.ExecMode;
import org.apache.sysds.hops.ParameterizedBuiltinOp;
import org.apache.sysds.common.Types.ExecType;
@@ -34,11 +33,12 @@ public class RemoveEmptyTest extends AutomatedTestBase
private final static String TEST_NAME2 = "removeEmpty2";
private final static String TEST_NAME3 = "removeEmpty3";
private final static String TEST_NAME4 = "removeEmpty4";
+
private final static String TEST_DIR = "functions/unary/matrix/";
private static final String TEST_CLASS_DIR = TEST_DIR +
RemoveEmptyTest.class.getSimpleName() + "/";
- private final static int _rows = 3500;
- private final static int _cols = 2500;
+ private final static int _rows = 2500;
+ private final static int _cols = 1500;
private final static double _sparsityDense = 0.7;
private final static double _sparsitySparse = 0.07;
@@ -57,277 +57,222 @@ public class RemoveEmptyTest extends AutomatedTestBase
}
@Test
- public void testRemoveEmptyRowsDenseCP()
- {
+ public void testRemoveEmptyRowsDenseCP() {
runTestRemoveEmpty( TEST_NAME1, "rows", ExecType.CP, false );
}
@Test
- public void testRemoveEmptyRowsSparseCP()
- {
+ public void testRemoveEmptyRowsSparseCP() {
runTestRemoveEmpty( TEST_NAME1, "rows", ExecType.CP, true );
}
@Test
- public void testRemoveEmptyColsDenseCP()
- {
+ public void testRemoveEmptyColsDenseCP() {
runTestRemoveEmpty( TEST_NAME1, "cols", ExecType.CP, false );
}
@Test
- public void testRemoveEmptyColsSparseCP()
- {
+ public void testRemoveEmptyColsSparseCP() {
runTestRemoveEmpty( TEST_NAME1, "cols", ExecType.CP, true );
}
@Test
- public void testRemoveEmptyRowsDenseSP()
- {
+ public void testRemoveEmptyRowsDenseSP() {
runTestRemoveEmpty( TEST_NAME1, "rows", ExecType.SPARK, false );
}
@Test
- public void testRemoveEmptyRowsSparseSP()
- {
+ public void testRemoveEmptyRowsSparseSP() {
runTestRemoveEmpty( TEST_NAME1, "rows", ExecType.SPARK, true );
}
@Test
- public void testRemoveEmptyColsDenseSP()
- {
+ public void testRemoveEmptyColsDenseSP() {
runTestRemoveEmpty( TEST_NAME1, "cols", ExecType.SPARK, false );
}
@Test
- public void testRemoveEmptyColsSparseSP()
- {
+ public void testRemoveEmptyColsSparseSP() {
runTestRemoveEmpty( TEST_NAME1, "cols", ExecType.SPARK, true );
}
-
@Test
- public void testRemoveEmptyRowsMultipleDenseCP()
- {
+ public void testRemoveEmptyRowsMultipleDenseCP() {
runTestRemoveEmpty( TEST_NAME2, "rows", ExecType.CP, false );
}
@Test
- public void testRemoveEmptyRowsMultipleSparseCP()
- {
+ public void testRemoveEmptyRowsMultipleSparseCP() {
runTestRemoveEmpty( TEST_NAME2, "rows", ExecType.CP, true );
}
@Test
- public void testRemoveEmptyColsMultipleDenseCP()
- {
+ public void testRemoveEmptyColsMultipleDenseCP() {
runTestRemoveEmpty( TEST_NAME2, "cols", ExecType.CP, false );
}
@Test
- public void testRemoveEmptyColsMultipleSparseCP()
- {
+ public void testRemoveEmptyColsMultipleSparseCP() {
runTestRemoveEmpty( TEST_NAME2, "cols", ExecType.CP, true );
}
@Test
- public void testRemoveEmptyRowsMultipleDenseSP()
- {
+ public void testRemoveEmptyRowsMultipleDenseSP() {
runTestRemoveEmpty( TEST_NAME2, "rows", ExecType.SPARK, false );
}
@Test
- public void testRemoveEmptyRowsMultipleSparseSP()
- {
+ public void testRemoveEmptyRowsMultipleSparseSP() {
runTestRemoveEmpty( TEST_NAME2, "rows", ExecType.SPARK, true );
}
@Test
- public void testRemoveEmptyColsMultipleDenseSP()
- {
+ public void testRemoveEmptyColsMultipleDenseSP() {
runTestRemoveEmpty( TEST_NAME2, "cols", ExecType.SPARK, false );
}
@Test
- public void testRemoveEmptyColsMultipleSparseSP()
- {
+ public void testRemoveEmptyColsMultipleSparseSP() {
runTestRemoveEmpty( TEST_NAME2, "cols", ExecType.SPARK, true );
}
-
@Test
- public void testRemoveEmptyRowsDiagDenseCP()
- {
+ public void testRemoveEmptyRowsDiagDenseCP() {
runTestRemoveEmpty( TEST_NAME3, "rows", ExecType.CP, false );
}
@Test
- public void testRemoveEmptyRowsDiagSparseCP()
- {
+ public void testRemoveEmptyRowsDiagSparseCP() {
runTestRemoveEmpty( TEST_NAME3, "rows", ExecType.CP, true );
}
@Test
- public void testRemoveEmptyColsDiagDenseCP()
- {
+ public void testRemoveEmptyColsDiagDenseCP() {
runTestRemoveEmpty( TEST_NAME3, "cols", ExecType.CP, false );
}
@Test
- public void testRemoveEmptyColsDiagSparseCP()
- {
+ public void testRemoveEmptyColsDiagSparseCP() {
runTestRemoveEmpty( TEST_NAME3, "cols", ExecType.CP, true );
}
@Test
- public void testRemoveEmptyRowsDiagDenseSP()
- {
+ public void testRemoveEmptyRowsDiagDenseSP() {
runTestRemoveEmpty( TEST_NAME3, "rows", ExecType.SPARK, false );
}
@Test
- public void testRemoveEmptyRowsDiagSparseSP()
- {
+ public void testRemoveEmptyRowsDiagSparseSP() {
runTestRemoveEmpty( TEST_NAME3, "rows", ExecType.SPARK, true );
}
@Test
- public void testRemoveEmptyColsDiagDenseSP()
- {
+ public void testRemoveEmptyColsDiagDenseSP() {
runTestRemoveEmpty( TEST_NAME3, "cols", ExecType.SPARK, false );
}
@Test
- public void testRemoveEmptyColsDiagSparseSP()
- {
+ public void testRemoveEmptyColsDiagSparseSP() {
runTestRemoveEmpty( TEST_NAME3, "cols", ExecType.SPARK, true );
}
// ------------------------------
// Remove Empty with Broadcast option
@Test
- public void testRemoveEmptyRowsDenseBcSP()
- {
+ public void testRemoveEmptyRowsDenseBcSP() {
runTestRemoveEmpty( TEST_NAME1, "rows", ExecType.SPARK, false,
false );
}
@Test
- public void testRemoveEmptyRowsSparseBcSP()
- {
+ public void testRemoveEmptyRowsSparseBcSP() {
runTestRemoveEmpty( TEST_NAME1, "rows", ExecType.SPARK, true,
false );
}
@Test
- public void testRemoveEmptyColsDenseBcSP()
- {
+ public void testRemoveEmptyColsDenseBcSP() {
runTestRemoveEmpty( TEST_NAME1, "cols", ExecType.SPARK, false,
false );
}
@Test
- public void testRemoveEmptyColsSparseBcSP()
- {
+ public void testRemoveEmptyColsSparseBcSP() {
runTestRemoveEmpty( TEST_NAME1, "cols", ExecType.SPARK, true,
false );
}
@Test
- public void testRemoveEmptyRowsMultipleDenseBcSP()
- {
+ public void testRemoveEmptyRowsMultipleDenseBcSP() {
runTestRemoveEmpty( TEST_NAME2, "rows", ExecType.SPARK, false,
false );
}
@Test
- public void testRemoveEmptyRowsMultipleSparseBcSP()
- {
+ public void testRemoveEmptyRowsMultipleSparseBcSP() {
runTestRemoveEmpty( TEST_NAME2, "rows", ExecType.SPARK, true,
false );
}
@Test
- public void testRemoveEmptyColsMultipleDenseBcSP()
- {
+ public void testRemoveEmptyColsMultipleDenseBcSP() {
runTestRemoveEmpty( TEST_NAME2, "cols", ExecType.SPARK, false,
false );
}
@Test
- public void testRemoveEmptyColsMultipleSparseBcSP()
- {
+ public void testRemoveEmptyColsMultipleSparseBcSP() {
runTestRemoveEmpty( TEST_NAME2, "cols", ExecType.SPARK, true,
false );
}
-//-------------------------------------------------------------------------------------
-// Testcases to pass index containing non-empty rows.
+
//-------------------------------------------------------------------------------------
+ // Testcases to pass index containing non-empty rows.
// CP Test cases
@Test
- public void testRemoveEmptyRowsDenseCPwIdx()
- {
+ public void testRemoveEmptyRowsDenseCPwIdx() {
runTestRemoveEmpty( TEST_NAME4, "rows", ExecType.CP, false,
true, true);
}
@Test
- public void testRemoveEmptyColsDenseCPwIdx()
- {
+ public void testRemoveEmptyColsDenseCPwIdx() {
runTestRemoveEmpty( TEST_NAME4, "cols", ExecType.CP, false,
true, true);
}
@Test
- public void testRemoveEmptyRowsSparseCPwIdx()
- {
+ public void testRemoveEmptyRowsSparseCPwIdx() {
runTestRemoveEmpty( TEST_NAME4, "rows", ExecType.CP, true,
true, true);
}
@Test
- public void testRemoveEmptyColsSparseCPwIdx()
- {
+ public void testRemoveEmptyColsSparseCPwIdx() {
runTestRemoveEmpty( TEST_NAME4, "cols", ExecType.CP, true,
true, true);
}
// Spark Test cases
@Test
- public void testRemoveEmptyRowsDenseSPwIdx()
- {
+ public void testRemoveEmptyRowsDenseSPwIdx() {
runTestRemoveEmpty( TEST_NAME4, "rows", ExecType.SPARK, false,
true, true);
}
@Test
- public void testRemoveEmptyColsDenseSPwIdx()
- {
+ public void testRemoveEmptyColsDenseSPwIdx() {
runTestRemoveEmpty( TEST_NAME4, "cols", ExecType.SPARK, false,
true, true);
}
@Test
- public void testRemoveEmptyRowsSparseSPwIdx()
- {
+ public void testRemoveEmptyRowsSparseSPwIdx() {
runTestRemoveEmpty( TEST_NAME4, "rows", ExecType.SPARK, true,
true, true);
}
@Test
- public void testRemoveEmptyColsSparseSPwIdx()
- {
+ public void testRemoveEmptyColsSparseSPwIdx() {
runTestRemoveEmpty( TEST_NAME4, "cols", ExecType.SPARK, true,
true, true);
}
-
-
- private void runTestRemoveEmpty( String testname, String margin,
ExecType et, boolean sparse )
- {
+
+ private void runTestRemoveEmpty( String testname, String margin,
ExecType et, boolean sparse ) {
runTestRemoveEmpty(testname, margin, et, sparse, true);
}
- private void runTestRemoveEmpty( String testname, String margin,
ExecType et, boolean sparse, boolean bForceDistRmEmpty)
- {
+ private void runTestRemoveEmpty( String testname, String margin,
ExecType et, boolean sparse, boolean bForceDistRmEmpty) {
runTestRemoveEmpty(testname, margin, et, sparse,
bForceDistRmEmpty, false);
}
private void runTestRemoveEmpty( String testname, String margin,
ExecType et, boolean sparse, boolean bForceDistRmEmpty, boolean bSelectIndex)
- {
- //rtplatform for MR
- ExecMode platformOld = rtplatform;
- switch( et ){
- case SPARK: rtplatform = ExecMode.SPARK; break;
- default: rtplatform = ExecMode.HYBRID; break;
- }
-
- boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG;
- if( rtplatform == ExecMode.SPARK )
- DMLScript.USE_LOCAL_SPARK_CONFIG = true;
-
+ {
+ ExecMode platformOld = setExecMode(et);
ParameterizedBuiltinOp.FORCE_DIST_RM_EMPTY = bForceDistRmEmpty;
try
@@ -368,11 +313,8 @@ public class RemoveEmptyTest extends AutomatedTestBase
compareResults();
}
- finally
- {
- //reset platform for additional tests
- rtplatform = platformOld;
- DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
+ finally {
+ resetExecMode(platformOld);
}
}
@@ -387,66 +329,66 @@ public class RemoveEmptyTest extends AutomatedTestBase
rowsp = rows;
colsp = cols/2;
}
-
+
//long seed = System.nanoTime();
- double[][] V = getRandomMatrix(rows, cols, 0, 1, sparsity, 7);
- double[][] Vp = new double[rowsp][colsp];
- double[][] Ix = null;
- int innz = 0, vnnz = 0;
-
- //clear out every other row/column
- if( margin.equals("rows") )
- {
- Ix = new double[rows][1];
- for( int i=0; i<rows; i++ )
- {
- boolean clear = i%2!=0;
- if( clear ) {
- for( int j=0; j<cols; j++ )
- V[i][j] = 0;
- Ix[i][0] = 0;
- }
- else {
- boolean bNonEmpty = false;
- for( int j=0; j<cols; j++ )
- {
- Vp[i/2][j] = V[i][j];
- bNonEmpty |= (V[i][j] !=
0.0)?true:false;
- vnnz += (V[i][j] == 0.0)?0:1;
- }
- Ix[i][0] = (bNonEmpty)?1:0;
- innz += Ix[i][0];
- }
- }
- }
- else
- {
- Ix = new double[1][cols];
- for( int j=0; j<cols; j++ )
- {
- boolean clear = j%2!=0;
- if( clear ) {
- for( int i=0; i<rows; i++ )
- V[i][j] = 0;
- Ix[0][j] = 0;
- }
- else {
- boolean bNonEmpty = false;
- for( int i=0; i<rows; i++ )
- {
- Vp[i][j/2] = V[i][j];
- bNonEmpty |= (V[i][j] !=
0.0)?true:false;
- vnnz += (V[i][j] == 0.0)?0:1;
- }
- Ix[0][j] = (bNonEmpty)?1:0;
- innz += Ix[0][j];
- }
- }
- }
-
- MatrixCharacteristics imc = new
MatrixCharacteristics(margin.equals("rows")?rows:1,
margin.equals("rows")?1:cols, 1000, innz);
- MatrixCharacteristics vmc = new MatrixCharacteristics(rows, cols,
1000, vnnz);
-
+ double[][] V = getRandomMatrix(rows, cols, 0, 1, sparsity, 7);
+ double[][] Vp = new double[rowsp][colsp];
+ double[][] Ix = null;
+ int innz = 0, vnnz = 0;
+
+ //clear out every other row/column
+ if( margin.equals("rows") )
+ {
+ Ix = new double[rows][1];
+ for( int i=0; i<rows; i++ )
+ {
+ boolean clear = i%2!=0;
+ if( clear ) {
+ for( int j=0; j<cols; j++ )
+ V[i][j] = 0;
+ Ix[i][0] = 0;
+ }
+ else {
+ boolean bNonEmpty = false;
+ for( int j=0; j<cols; j++ )
+ {
+ Vp[i/2][j] = V[i][j];
+ bNonEmpty |= (V[i][j] !=
0.0)?true:false;
+ vnnz += (V[i][j] == 0.0)?0:1;
+ }
+ Ix[i][0] = (bNonEmpty)?1:0;
+ innz += Ix[i][0];
+ }
+ }
+ }
+ else
+ {
+ Ix = new double[1][cols];
+ for( int j=0; j<cols; j++ )
+ {
+ boolean clear = j%2!=0;
+ if( clear ) {
+ for( int i=0; i<rows; i++ )
+ V[i][j] = 0;
+ Ix[0][j] = 0;
+ }
+ else {
+ boolean bNonEmpty = false;
+ for( int i=0; i<rows; i++ )
+ {
+ Vp[i][j/2] = V[i][j];
+ bNonEmpty |= (V[i][j] !=
0.0)?true:false;
+ vnnz += (V[i][j] == 0.0)?0:1;
+ }
+ Ix[0][j] = (bNonEmpty)?1:0;
+ innz += Ix[0][j];
+ }
+ }
+ }
+
+ MatrixCharacteristics imc = new
MatrixCharacteristics(margin.equals("rows")?rows:1,
margin.equals("rows")?1:cols, 1000, innz);
+ MatrixCharacteristics vmc = new MatrixCharacteristics(rows,
cols, 1000, vnnz);
+
writeInputMatrixWithMTD("V", V, false, vmc); //always text
writeExpectedMatrix("V", Vp);
if(bSelectIndex)
@@ -457,38 +399,37 @@ public class RemoveEmptyTest extends AutomatedTestBase
{
double[][] V = getRandomMatrix(rows, 1, 0, 1, sparsity, 7);
double[][] Vp = null;
- double[][] Ix = new double[rows][1];
-
- if( margin.equals("rows") )
- {
- int rowsp = 0;
+ double[][] Ix = new double[rows][1];
+
+ if( margin.equals("rows") )
+ {
+ int rowsp = 0;
for(int i=0; i<rows; i++) //count nnz
rowsp += (V[i][0]!=0)?1:0;
- Vp = new double[rowsp][1];
-
- for( int i=0, ix=0; i<rows; i++ )
- if( V[i][0]!=0 ) {
- Vp[ix++][0] = V[i][0];
- Ix[i][0] = 1;
- } else
- Ix[i][0] = 0;
- }
- else
- {
- Vp = new double[rows][1];
- for( int i=0; i<rows; i++ ) {
- Vp[i][0] = V[i][0];
- if( V[i][0]!=0 ) {
- Ix[i][0] = 1;
- } else
- Ix[i][0] = 0;
- }
- }
-
+ Vp = new double[rowsp][1];
+
+ for( int i=0, ix=0; i<rows; i++ )
+ if( V[i][0]!=0 ) {
+ Vp[ix++][0] = V[i][0];
+ Ix[i][0] = 1;
+ } else
+ Ix[i][0] = 0;
+ }
+ else
+ {
+ Vp = new double[rows][1];
+ for( int i=0; i<rows; i++ ) {
+ Vp[i][0] = V[i][0];
+ if( V[i][0]!=0 ) {
+ Ix[i][0] = 1;
+ } else
+ Ix[i][0] = 0;
+ }
+ }
+
writeInputMatrix("V", V, false); //always text
writeExpectedMatrix("V", Vp);
if(bSelectIndex)
writeInputMatrix("I", Ix, false);
}
-
-}
\ No newline at end of file
+}