Следующие были моими исходными и тестовыми кодами: < /p>
Код: Выделить всё
using System;
using System.Linq;
using Tensorflow;
using static Tensorflow.Binding;
namespace SimulationLib
{
public class TfMatrix : IEquatable
{
private Tensor _matrix;
public TfMatrix(float[,] values)
{
if (values == null || values.GetLength(0) == 0 || values.GetLength(1) == 0)
throw new ArgumentException("Values array must not be null or empty.");
_matrix = tf.constant(values);
}
public TfMatrix(int rows, int cols)
{
if (rows (int)_matrix.shape[1];
}
}
Код: Выделить всё
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Tensorflow;
using static Tensorflow.Binding;
namespace SimulationLib.Tests
{
[TestClass]
public class TfMatrixTests
{
[TestMethod]
public void TestConstructorWith2DArray()
{
float[,] values = new float[,] { { 1, 2 }, { 3, 4 } };
TfMatrix matrix = new TfMatrix(values);
Assert.AreEqual(2, matrix.Rows);
Assert.AreEqual(2, matrix.Columns);
Assert.AreEqual(1, matrix[0, 0]);
Assert.AreEqual(4, matrix[1, 1]);
}
}
}
Код: Выделить всё
Test Name: TestConstructorWith2DArray
Test FullName: SimulationLib.Tests.TfMatrixTests.TestConstructorWith2DArray
Test Source: C:\git\Simulation\Simulation\unit_test_3d_for_TfMatrix\UnitTest1.cs : line 12
Test Outcome: Failed
Test Duration: 0:00:01.2855111
Result StackTrace:
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at Tensorflow.ops.RegisterFromAssembly()
at Tensorflow.tensorflow.InitGradientEnvironment()
at Tensorflow.tensorflow..ctor()
at Tensorflow.Binding..cctor()
--- End of inner exception stack trace ---
at Tensorflow.Binding.get_tf()
at SimulationLib.TfMatrix..ctor(Single[,] values) in C:\git\Simulation\Simulation\PolymerSimLib\Primitives\TfMatrix.cs:line 17
at SimulationLib.Tests.TfMatrixTests.TestConstructorWith2DArray() in C:\git\Simulation\Simulation\unit_test_3d_for_TfMatrix\UnitTest1.cs:line 15
Result Message:
Test method SimulationLib.Tests.TfMatrixTests.TestConstructorWith2DArray threw exception:
System.TypeInitializationException: The type initializer for 'Tensorflow.Binding' threw an exception. ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Подробнее здесь: https://stackoverflow.com/questions/793 ... -exception