Skip to content

Commit

Permalink
[MINOR] Frame convert test cover
Browse files Browse the repository at this point in the history
  • Loading branch information
Baunsgaard committed Sep 24, 2024
1 parent b979b2c commit 7d9230b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,13 @@ private static ValueType[] getSchema(MatrixBlock mb) {
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]);
}
}
}
Expand All @@ -114,15 +108,13 @@ else if(mb.isInSparseFormat())
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void castToFrame() {
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
Expand All @@ -47,10 +47,10 @@ public void castToFrame3() {
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -162,6 +166,17 @@ public void randomVerySparse() {
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);
Expand Down

0 comments on commit 7d9230b

Please sign in to comment.