forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperationsTest.cs
More file actions
64 lines (57 loc) · 1.76 KB
/
OperationsTest.cs
File metadata and controls
64 lines (57 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tensorflow;
using Buffer = Tensorflow.Buffer;
namespace TensorFlowNET.UnitTest
{
[TestClass]
public class OperationsTest
{
/// <summary>
/// Port from tensorflow\c\c_api_test.cc
/// `TEST(CAPI, GetAllOpList)`
/// </summary>
[TestMethod]
public void GetAllOpList()
{
var handle = c_api.TF_GetAllOpList();
var buffer = new Buffer(handle);
var op_list = OpList.Parser.ParseFrom(buffer);
var _registered_ops = new Dictionary<string, OpDef>();
foreach (var op_def in op_list.Op)
_registered_ops[op_def.Name] = op_def;
// r1.14 added NN op
var op = _registered_ops.FirstOrDefault(x => x.Key == "NearestNeighbors");
Assert.IsTrue(op_list.Op.Count > 1000);
}
[TestMethod]
public void addInPlaceholder()
{
var a = tf.placeholder(tf.float32);
var b = tf.placeholder(tf.float32);
var c = tf.add(a, b);
using(var sess = tf.Session())
{
var o = sess.run(c,
new FeedItem(a, 3.0f),
new FeedItem(b, 2.0f));
Assert.AreEqual((float)o, 5.0f);
}
}
[TestMethod]
public void addInConstant()
{
var a = tf.constant(4.0f);
var b = tf.constant(5.0f);
var c = tf.add(a, b);
using (var sess = tf.Session())
{
var o = sess.run(c);
Assert.AreEqual((float)o, 9.0f);
}
}
}
}