This is an automated email from the ASF dual-hosted git repository. baunsgaard 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 7d9230b78b [MINOR] Frame convert test cover 7d9230b78b is described below commit 7d9230b78b0defa1772c2946025dcf272b65af87 Author: Sebastian Baunsgaard <baunsga...@apache.org> AuthorDate: Mon Sep 23 23:38:37 2024 +0200 [MINOR] Frame convert test cover Closes #2114 --- .../frame/data/lib/FrameFromMatrixBlock.java | 24 ++++++++-------------- .../runtime/frame/data/lib/FrameLibCompress.java | 2 +- .../test/component/frame/FrameCustomTest.java | 6 +++--- .../component/frame/FrameFromMatrixBlockTest.java | 15 ++++++++++++++ 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/apache/sysds/runtime/frame/data/lib/FrameFromMatrixBlock.java b/src/main/java/org/apache/sysds/runtime/frame/data/lib/FrameFromMatrixBlock.java index 5fd60d9586..7a2a951696 100644 --- a/src/main/java/org/apache/sysds/runtime/frame/data/lib/FrameFromMatrixBlock.java +++ b/src/main/java/org/apache/sysds/runtime/frame/data/lib/FrameFromMatrixBlock.java @@ -86,19 +86,13 @@ public class FrameFromMatrixBlock { final int nRow = mb.getNumRows(); // default boolean if possible. final ValueType[] schema = UtilFunctions.nCopies(nCol, ValueType.BOOLEAN); - for(int c = 0; c < nCol; c++){ - for(int r = 0; r < nRow; r++){ - switch(schema[c]){ - case INT64: - // keep the type as FP64 if long is detected - schema[c] = ValueType.FP64; + for(int c = 0; c < nCol; c++) { + for(int r = 0; r < nRow; r++) { + switch(schema[c]) { case FP64: - break; + break; // early termination of column default to highest default: - final double v = mb.get(r, c); - if(v > Integer.MAX_VALUE) - schema[c] = ValueType.FP64; // handle Integer overflow. - schema[c] = FrameUtil.isType(v, schema[c]); + schema[c] = FrameUtil.isType(mb.get(r, c), schema[c]); } } } @@ -114,15 +108,13 @@ public class FrameFromMatrixBlock { convertToFrameBlockSparse(); else convertToFrameBlockDense(); - if(frame.getNumRows() != mb.getNumRows()) - throw new DMLRuntimeException("Invalid result"); return frame; } - catch(InterruptedException | ExecutionException e) { - throw new DMLRuntimeException("failed to convert to matrix block"); + catch(Exception e) { + throw new DMLRuntimeException("failed to convert to matrix block", e); } - finally{ + finally { if(pool != null) pool.shutdown(); } diff --git a/src/main/java/org/apache/sysds/runtime/frame/data/lib/FrameLibCompress.java b/src/main/java/org/apache/sysds/runtime/frame/data/lib/FrameLibCompress.java index 207ece8d26..cac334a8e2 100644 --- a/src/main/java/org/apache/sysds/runtime/frame/data/lib/FrameLibCompress.java +++ b/src/main/java/org/apache/sysds/runtime/frame/data/lib/FrameLibCompress.java @@ -22,7 +22,7 @@ import org.apache.sysds.runtime.compress.workload.WTreeRoot; import org.apache.sysds.runtime.frame.data.FrameBlock; import org.apache.sysds.runtime.frame.data.compress.CompressedFrameBlockFactory; -public class FrameLibCompress { +public interface FrameLibCompress { public static FrameBlock compress(FrameBlock in, int k) { return compress(in, k, null); diff --git a/src/test/java/org/apache/sysds/test/component/frame/FrameCustomTest.java b/src/test/java/org/apache/sysds/test/component/frame/FrameCustomTest.java index 3387db56ab..5e482a5369 100644 --- a/src/test/java/org/apache/sysds/test/component/frame/FrameCustomTest.java +++ b/src/test/java/org/apache/sysds/test/component/frame/FrameCustomTest.java @@ -35,7 +35,7 @@ public class FrameCustomTest { double maxp1 = Integer.MAX_VALUE + 1.0; MatrixBlock mb = TestUtils.generateTestMatrixBlock(100, 100, maxp1, maxp1, 1.0, 23); FrameBlock f = DataConverter.convertToFrameBlock(mb); - assertTrue(f.getSchema()[0] == ValueType.FP64); + assertTrue(f.getSchema()[0] == ValueType.INT64); } @Test @@ -47,10 +47,10 @@ public class FrameCustomTest { } @Test - public void castErrorValue() { + public void castIntegerValue() { MatrixBlock mb = new MatrixBlock(10, 10, Double.parseDouble("2.572306572E9")); FrameBlock f = DataConverter.convertToFrameBlock(mb); - assertTrue(f.getSchema()[0] == ValueType.FP64); + assertTrue(f.getSchema()[0] == ValueType.INT64); } @Test diff --git a/src/test/java/org/apache/sysds/test/component/frame/FrameFromMatrixBlockTest.java b/src/test/java/org/apache/sysds/test/component/frame/FrameFromMatrixBlockTest.java index 2544f18817..586f77e85a 100644 --- a/src/test/java/org/apache/sysds/test/component/frame/FrameFromMatrixBlockTest.java +++ b/src/test/java/org/apache/sysds/test/component/frame/FrameFromMatrixBlockTest.java @@ -19,12 +19,16 @@ package org.apache.sysds.test.component.frame; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.sysds.common.Types.ValueType; +import org.apache.sysds.runtime.DMLRuntimeException; import org.apache.sysds.runtime.data.DenseBlockFP64; import org.apache.sysds.runtime.frame.data.FrameBlock; import org.apache.sysds.runtime.frame.data.lib.FrameFromMatrixBlock; @@ -162,6 +166,17 @@ public class FrameFromMatrixBlockTest { verifyEquivalence(mb, fb); } + @Test + public void error(){ + MatrixBlock mb = TestUtils.ceil(TestUtils.generateTestMatrixBlock(1000, 1, 0, 199, 0.01, 213)); + MatrixBlock spy = spy(mb); + when(spy.isEmpty()).thenThrow(new DMLRuntimeException("Intended Error")); + Exception e = assertThrows(DMLRuntimeException.class, () -> FrameFromMatrixBlock.convertToFrameBlock(spy, new ValueType[]{ValueType.FP64}, 1)); + assertTrue(e.getMessage().contains("failed to convert to matrix block")); + } + + + // @Test // public void timeChange() { // MatrixBlock mb = TestUtils.generateTestMatrixBlock(64000, 2000, 1, 1, 0.5, 2340);