Skip to content

Commit

Permalink
Test updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
khatchad committed Dec 14, 2023
1 parent 8bb5c8c commit b2a8a3a
Showing 1 changed file with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static edu.cuny.hunter.hybridize.core.analysis.PreconditionFailure.HAS_NO_TENSOR_PARAMETERS;
import static edu.cuny.hunter.hybridize.core.analysis.PreconditionFailure.HAS_PRIMITIVE_PARAMETERS;
import static edu.cuny.hunter.hybridize.core.analysis.PreconditionFailure.HAS_PYTHON_SIDE_EFFECTS;
import static edu.cuny.hunter.hybridize.core.analysis.PreconditionFailure.HAS_TENSOR_PARAMETERS;
import static edu.cuny.hunter.hybridize.core.analysis.PreconditionFailure.HAS_NO_PRIMITIVE_PARAMETERS;
import static edu.cuny.hunter.hybridize.core.analysis.PreconditionFailure.IS_RECURSIVE;
import static edu.cuny.hunter.hybridize.core.analysis.PreconditionFailure.UNDETERMINABLE_SIDE_EFFECTS;
import static edu.cuny.hunter.hybridize.core.analysis.PreconditionFailure.UNDETERMINABLE_TENSOR_PARAMETER;
Expand Down Expand Up @@ -4427,7 +4427,7 @@ public void testHasLikelyTensorParameter148() throws Exception {
assertNull(function.getPassingPrecondition());
assertTrue(function.getTransformations().isEmpty());
assertTrue(function.getStatus().hasError());
assertNotNull(function.getEntryMatchingFailure(HAS_TENSOR_PARAMETERS));
assertNotNull(function.getEntryMatchingFailure(HAS_NO_PRIMITIVE_PARAMETERS));
}

/**
Expand Down Expand Up @@ -4461,7 +4461,7 @@ public void testHasLikelyTensorParameter150() throws Exception {
assertNull(function.getPassingPrecondition());
assertTrue(function.getTransformations().isEmpty());
assertTrue(function.getStatus().hasError());
assertNotNull(function.getEntryMatchingFailure(HAS_TENSOR_PARAMETERS));
assertNotNull(function.getEntryMatchingFailure(HAS_NO_PRIMITIVE_PARAMETERS));
}

/**
Expand All @@ -4477,7 +4477,7 @@ public void testHasLikelyTensorParameter151() throws Exception {
assertNull(function.getPassingPrecondition());
assertTrue(function.getTransformations().isEmpty());
assertTrue(function.getStatus().hasError());
assertNotNull(function.getEntryMatchingFailure(HAS_TENSOR_PARAMETERS));
assertNotNull(function.getEntryMatchingFailure(HAS_NO_PRIMITIVE_PARAMETERS));
}

/**
Expand All @@ -4493,7 +4493,7 @@ public void testHasLikelyTensorParameter152() throws Exception {
assertNull(function.getPassingPrecondition());
assertTrue(function.getTransformations().isEmpty());
assertTrue(function.getStatus().hasError());
assertNotNull(function.getEntryMatchingFailure(HAS_TENSOR_PARAMETERS));
assertNotNull(function.getEntryMatchingFailure(HAS_NO_PRIMITIVE_PARAMETERS));
}

/**
Expand All @@ -4510,7 +4510,7 @@ public void testHasLikelyTensorParameter153() throws Exception {
assertEquals(1, function.getTransformations().size());
assertEquals(CONVERT_TO_EAGER, function.getTransformations().iterator().next());
assertFalse(function.getStatus().hasError());
assertNull(function.getEntryMatchingFailure(HAS_TENSOR_PARAMETERS));
assertNull(function.getEntryMatchingFailure(HAS_NO_PRIMITIVE_PARAMETERS));
}

/**
Expand All @@ -4526,7 +4526,7 @@ public void testHasLikelyTensorParameter154() throws Exception {
assertNull(function.getPassingPrecondition());
assertTrue(function.getTransformations().isEmpty());
assertTrue(function.getStatus().hasError());
assertNotNull(function.getEntryMatchingFailure(HAS_TENSOR_PARAMETERS));
assertNotNull(function.getEntryMatchingFailure(HAS_NO_PRIMITIVE_PARAMETERS));
}

/**
Expand All @@ -4542,7 +4542,7 @@ public void testHasLikelyTensorParameter155() throws Exception {
assertNull(function.getPassingPrecondition());
assertTrue(function.getTransformations().isEmpty());
assertTrue(function.getStatus().hasError());
assertNotNull(function.getEntryMatchingFailure(HAS_TENSOR_PARAMETERS));
assertNotNull(function.getEntryMatchingFailure(HAS_NO_PRIMITIVE_PARAMETERS));
}

/**
Expand All @@ -4554,11 +4554,16 @@ public void testHasLikelyTensorParameter156() throws Exception {

assertTrue(function.getIsHybrid());
assertTrue(function.getLikelyHasTensorParameter());
assertTrue(function.getLikelyHasPrimitiveParameters());
// FIXME: This is a strange case. We use type hints for tf.Tensor on primitives. Since they're cast automatically, we shouldn't
// consider this parameter as a primitive.
assertEquals(OPTIMIZE_HYBRID_FUNCTION, function.getRefactoring());
assertNull(function.getPassingPrecondition());
assertTrue(function.getTransformations().isEmpty());
assertTrue(function.getStatus().hasError());
assertNotNull(function.getEntryMatchingFailure(HAS_TENSOR_PARAMETERS));
assertNotNull(function.getPassingPrecondition());
assertEquals(P3, function.getPassingPrecondition());
assertFalse(function.getTransformations().isEmpty());
assertEquals(singleton(CONVERT_TO_EAGER), function.getTransformations());
assertFalse(function.getStatus().hasError());
assertNull(function.getEntryMatchingFailure(HAS_NO_PRIMITIVE_PARAMETERS));
}

// TODO: Test arbitrary expression.
Expand Down Expand Up @@ -5375,7 +5380,7 @@ public void testPythonSideEffects45() throws Exception {

assertTrue(function.getLikelyHasTensorParameter());
// In table 2, we need it not to have a tensor parameter to de-hybridize, so this is a "failure."
assertTrue(function.getEntryMatchingFailure(PreconditionFailure.HAS_TENSOR_PARAMETERS).isError());
assertTrue(function.getEntryMatchingFailure(PreconditionFailure.HAS_NO_PRIMITIVE_PARAMETERS).isError());

assertTrue(function.getHasPythonSideEffects());
// We also can't de-hybridize if it has Python side-effects. So, that's an error.
Expand Down Expand Up @@ -5428,7 +5433,7 @@ public void testPythonSideEffects47() throws Exception {
assertFalse(capturesLeakedTensor.getStatus().hasFatalError());
RefactoringStatusEntry error = capturesLeakedTensor.getStatus().getEntryMatchingSeverity(RefactoringStatus.ERROR);
assertTrue(error.isError());
assertEquals(PreconditionFailure.HAS_TENSOR_PARAMETERS.getCode(), error.getCode());
assertEquals(PreconditionFailure.HAS_NO_PRIMITIVE_PARAMETERS.getCode(), error.getCode());

// NOTE: Change to assertEquals(..., 1, ...) once https://github.com/ponder-lab/Hybridize-Functions-Refactoring/issues/281 is fixed.
assertEquals("We should warn that the hybrid function is capturing leaked tensors.", 0,
Expand Down Expand Up @@ -5678,7 +5683,7 @@ public void testRecursion4() throws Exception {
assertEquals(Refactoring.OPTIMIZE_HYBRID_FUNCTION, f.getRefactoring());

assertTrue(f.getLikelyHasTensorParameter()); // T.
assertTrue(f.getEntryMatchingFailure(HAS_TENSOR_PARAMETERS).isError());
assertTrue(f.getEntryMatchingFailure(HAS_NO_PRIMITIVE_PARAMETERS).isError());

assertFalse(f.getHasPythonSideEffects()); // F.
assertNull(f.getEntryMatchingFailure(HAS_PYTHON_SIDE_EFFECTS));
Expand All @@ -5699,7 +5704,7 @@ public void testRecursion5() throws Exception {

assertTrue(f.getLikelyHasTensorParameter());
assertFalse("Already optimal.", f.getStatus().isOK());
assertTrue(f.getEntryMatchingFailure(HAS_TENSOR_PARAMETERS).isError());
assertTrue(f.getEntryMatchingFailure(HAS_NO_PRIMITIVE_PARAMETERS).isError());

assertFalse(f.getHasPythonSideEffects()); // F.
assertNull(f.getEntryMatchingFailure(HAS_PYTHON_SIDE_EFFECTS));
Expand All @@ -5720,7 +5725,7 @@ public void testRecursion6() throws Exception {

assertTrue(f.getLikelyHasTensorParameter()); // T.
assertFalse("Already optimal.", f.getStatus().isOK());
assertTrue(f.getEntryMatchingFailure(HAS_TENSOR_PARAMETERS).isError());
assertTrue(f.getEntryMatchingFailure(HAS_NO_PRIMITIVE_PARAMETERS).isError());

assertFalse(f.getHasPythonSideEffects()); // F.
assertNull(f.getEntryMatchingFailure(HAS_PYTHON_SIDE_EFFECTS));
Expand Down Expand Up @@ -5759,7 +5764,7 @@ public void testRecursion8() throws Exception {
assertEquals(OPTIMIZE_HYBRID_FUNCTION, f.getRefactoring());

assertFalse(f.getLikelyHasTensorParameter()); // F.
assertNull(f.getEntryMatchingFailure(HAS_TENSOR_PARAMETERS));
assertNull(f.getEntryMatchingFailure(HAS_NO_PRIMITIVE_PARAMETERS));
assertNull("Not having tensor parameters is not a failure for: " + OPTIMIZE_HYBRID_FUNCTION + ".",
f.getEntryMatchingFailure(HAS_NO_TENSOR_PARAMETERS));

Expand Down Expand Up @@ -5802,7 +5807,7 @@ public void testRecursion10() throws Exception {

assertFalse(f.getLikelyHasTensorParameter()); // F.
assertNull(f.getEntryMatchingFailure(HAS_NO_TENSOR_PARAMETERS));
assertNull(f.getEntryMatchingFailure(HAS_TENSOR_PARAMETERS));
assertNull(f.getEntryMatchingFailure(HAS_NO_PRIMITIVE_PARAMETERS));

assertFalse(f.getHasPythonSideEffects()); // F.
assertNull(f.getEntryMatchingFailure(HAS_PYTHON_SIDE_EFFECTS));
Expand Down Expand Up @@ -6041,7 +6046,6 @@ public void testRetracing5() throws Exception {
assertNull(f.getPassingPrecondition());
assertTrue(f.getStatus().hasError());
assertNotNull(f.getEntryMatchingFailure(HAS_NO_PRIMITIVE_PARAMETERS));
assertNull(f.getEntryMatchingFailure(HAS_TENSOR_PARAMETERS));
assertTrue(f.getTransformations().isEmpty());
}
}

0 comments on commit b2a8a3a

Please sign in to comment.