FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TensorFlow.NET/test/TensorFlowNET.UnitTest/ConstantTest.cs at master · mayuzx/TensorFlow.NET · GitHub
mayuzx
/
TensorFlow.NET
Public
forked from
SciSharp/TensorFlow.NET
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
TensorFlow.NET
/
test
/
TensorFlowNET.UnitTest
/
ConstantTest.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
129 lines (112 loc) · 3.91 KB
Breadcrumbs
TensorFlow.NET
/
test
/
TensorFlowNET.UnitTest
/
ConstantTest.cs
Copy path
File metadata and controls
129 lines (112 loc) · 3.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using
Microsoft
.
VisualStudio
.
TestTools
.
UnitTesting
;
using
NumSharp
;
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Linq
;
using
System
.
Runtime
.
InteropServices
;
using
System
.
Text
;
using
Tensorflow
;
namespace
TensorFlowNET
.
UnitTest
{
[
TestClass
]
public
class
ConstantTest
:
Python
{
Status
status
=
new
Status
(
)
;
[
TestMethod
]
public
void
ScalarConst
(
)
{
var
tensor1
=
tf
.
constant
(
8
)
;
// int
var
tensor2
=
tf
.
constant
(
6.0f
)
;
// float
var
tensor3
=
tf
.
constant
(
6.0
)
;
// double
}
[
TestMethod
]
public
void
StringConst
(
)
{
string
str
=
"Hello, TensorFlow.NET!"
;
var
tensor
=
tf
.
constant
(
str
)
;
with
(
tf
.
Session
(
)
,
sess
=>
{
var
result
=
sess
.
run
(
tensor
)
;
Assert
.
IsTrue
(
result
.
Data
<
string
>
(
)
[
0
]
==
str
)
;
}
)
;
}
[
TestMethod
]
public
void
ZerosConst
(
)
{
// small size
var
tensor
=
tf
.
zeros
(
new
Shape
(
3
,
2
)
,
TF_DataType
.
TF_INT32
,
"small"
)
;
with
(
tf
.
Session
(
)
,
sess
=>
{
var
result
=
sess
.
run
(
tensor
)
;
Assert
.
AreEqual
(
result
.
shape
[
0
]
,
3
)
;
Assert
.
AreEqual
(
result
.
shape
[
1
]
,
2
)
;
Assert
.
IsTrue
(
Enumerable
.
SequenceEqual
(
new
int
[
]
{
0
,
0
,
0
,
0
,
0
,
0
}
,
result
.
Data
<
int
>
(
)
)
)
;
}
)
;
// big size
tensor
=
tf
.
zeros
(
new
Shape
(
200
,
100
)
,
TF_DataType
.
TF_INT32
,
"big"
)
;
with
(
tf
.
Session
(
)
,
sess
=>
{
var
result
=
sess
.
run
(
tensor
)
;
Assert
.
AreEqual
(
result
.
shape
[
0
]
,
200
)
;
Assert
.
AreEqual
(
result
.
shape
[
1
]
,
100
)
;
var
data
=
result
.
Data
<
int
>
(
)
;
Assert
.
AreEqual
(
0
,
data
[
0
]
)
;
Assert
.
AreEqual
(
0
,
data
[
500
]
)
;
Assert
.
AreEqual
(
0
,
data
[
result
.
size
-
1
]
)
;
}
)
;
}
[
TestMethod
]
public
void
NDimConst
(
)
{
var
nd
=
np
.
array
(
new
int
[
]
[
]
{
new
int
[
]
{
3
,
1
,
1
}
,
new
int
[
]
{
2
,
1
,
3
}
}
)
;
var
tensor
=
tf
.
constant
(
nd
)
;
with
(
tf
.
Session
(
)
,
sess
=>
{
var
result
=
sess
.
run
(
tensor
)
;
var
data
=
result
.
Data
<
int
>
(
)
;
Assert
.
AreEqual
(
result
.
shape
[
0
]
,
2
)
;
Assert
.
AreEqual
(
result
.
shape
[
1
]
,
3
)
;
Assert
.
IsTrue
(
Enumerable
.
SequenceEqual
(
new
int
[
]
{
3
,
1
,
1
,
2
,
1
,
3
}
,
data
)
)
;
}
)
;
}
[
TestMethod
]
public
void
Multiply
(
)
{
var
a
=
tf
.
constant
(
3.0
)
;
var
b
=
tf
.
constant
(
2.0
)
;
var
c
=
a
*
b
;
var
sess
=
tf
.
Session
(
)
;
double
result
=
sess
.
run
(
c
)
;
sess
.
close
(
)
;
Assert
.
AreEqual
(
6.0
,
result
)
;
}
[
TestMethod
]
public
void
StringEncode
(
)
{
/*string str = "Hello, TensorFlow.NET!";
var handle = Marshal.StringToHGlobalAnsi(str);
ulong dst_len = c_api.TF_StringEncodedSize((UIntPtr)str.Length);
Assert.AreEqual(dst_len, (ulong)23);
IntPtr dst = Marshal.AllocHGlobal((int)dst_len);
ulong encoded_len = c_api.TF_StringEncode(handle, (ulong)str.Length, dst, dst_len, status);
Assert.AreEqual((ulong)23, encoded_len);
Assert.AreEqual(status.Code, TF_Code.TF_OK);
string encoded_str = Marshal.PtrToStringUTF8(dst + sizeof(byte));
Assert.AreEqual(encoded_str, str);
Assert.AreEqual(str.Length, Marshal.ReadByte(dst));*/
//c_api.TF_StringDecode(dst, (ulong)str.Length, IntPtr.Zero, ref dst_len, status);
}
/// <summary>
/// tensorflow\c\c_api_test.cc
/// TestEncodeDecode
/// </summary>
[
TestMethod
]
public
void
EncodeDecode
(
)
{
}
}
}
Back
|
FazBrowse Home
|
New Git URL