Browse Source

fix nullability

pull/1215/head
Alexander 1 year ago
parent
commit
b906c9a69a
2 changed files with 22 additions and 8 deletions
  1. +1
    -0
      test/TensorFlowNET.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj
  2. +21
    -8
      test/Tensorflow.UnitTest/PythonTest.cs

+ 1
- 0
test/TensorFlowNET.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj View File

@@ -25,6 +25,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\TensorFlowNET.Keras\Tensorflow.Keras.csproj" /> <ProjectReference Include="..\..\src\TensorFlowNET.Keras\Tensorflow.Keras.csproj" />
<ProjectReference Include="..\..\tools\Tensorflow.UnitTest.RedistHolder\Tensorflow.UnitTest.RedistHolder.csproj" /> <ProjectReference Include="..\..\tools\Tensorflow.UnitTest.RedistHolder\Tensorflow.UnitTest.RedistHolder.csproj" />
<ProjectReference Include="..\TensorFlow.Kernel.UnitTest\TensorFlow.Kernel.UnitTest.csproj" />
</ItemGroup> </ItemGroup>


<ItemGroup> <ItemGroup>


+ 21
- 8
test/Tensorflow.UnitTest/PythonTest.cs View File

@@ -86,9 +86,9 @@ namespace TensorFlowNET.UnitTest
Assert.AreEqual(JObject.FromObject(expected).ToString(), JObject.FromObject(given).ToString()); Assert.AreEqual(JObject.FromObject(expected).ToString(), JObject.FromObject(given).ToString());
return; return;
} }
if (given is ICollection && expected is ICollection)
if (given is ICollection collectionGiven && expected is ICollection collectionExpected)
{ {
assertItemsEqual(given as ICollection, expected as ICollection);
assertItemsEqual(collectionGiven, collectionExpected);
return; return;
} }
if (given is float && expected is float) if (given is float && expected is float)
@@ -150,8 +150,21 @@ namespace TensorFlowNET.UnitTest
{ {
_epsilon = eps; _epsilon = eps;
} }
public int Compare(object x, object y)
public int Compare(object? x, object? y)
{ {
if (x == null && y == null)
{
return 0;
}
else if (x == null)
{
return -1;
}
else if (y == null)
{
return 1;
}

var a = (double)x; var a = (double)x;
var b = (double)y; var b = (double)y;


@@ -206,7 +219,7 @@ namespace TensorFlowNET.UnitTest
// return nest.map_structure(self._eval_tensor, tensors); // return nest.map_structure(self._eval_tensor, tensors);
//} //}


protected object _eval_tensor(object tensor)
protected object? _eval_tensor(object tensor)
{ {
if (tensor == null) if (tensor == null)
return None; return None;
@@ -273,7 +286,7 @@ namespace TensorFlowNET.UnitTest




///Returns a TensorFlow Session for use in executing tests. ///Returns a TensorFlow Session for use in executing tests.
public Session cached_session(
public Session? cached_session(
Graph? graph = null, object? config = null, bool use_gpu = false, bool force_gpu = false) Graph? graph = null, object? config = null, bool use_gpu = false, bool force_gpu = false)
{ {
// This method behaves differently than self.session(): for performance reasons // This method behaves differently than self.session(): for performance reasons
@@ -369,7 +382,7 @@ namespace TensorFlowNET.UnitTest
return s.as_default(); return s.as_default();
} }


private Session _constrain_devices_and_set_default(Session sess, bool use_gpu, bool force_gpu)
private Session? _constrain_devices_and_set_default(Session sess, bool use_gpu, bool force_gpu)
{ {
// Set the session and its graph to global default and constrain devices.""" // Set the session and its graph to global default and constrain devices."""
if (tf.executing_eagerly()) if (tf.executing_eagerly())
@@ -404,7 +417,7 @@ namespace TensorFlowNET.UnitTest
} }


// See session() for details. // See session() for details.
private Session _create_session(Graph graph, object cfg, bool forceGpu)
private Session _create_session(Graph? graph, object? cfg, bool forceGpu)
{ {
var prepare_config = new Func<object, object>((config) => var prepare_config = new Func<object, object>((config) =>
{ {
@@ -485,7 +498,7 @@ namespace TensorFlowNET.UnitTest
session. Maybe create a new session with session. Maybe create a new session with
self.session()"); self.session()");
} }
return _cached_session;
return self._cached_session;
} }
} }




Loading…
Cancel
Save