FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TensorFlow.NET/tools/Tensorflow.CodeGen/GenOpsWriter.cs at master · jcreator35/TensorFlow.NET · GitHub
jcreator35
/
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
/
tools
/
Tensorflow.CodeGen
/
GenOpsWriter.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
81 lines (68 loc) · 2.79 KB
Breadcrumbs
TensorFlow.NET
/
tools
/
Tensorflow.CodeGen
/
GenOpsWriter.cs
Copy path
File metadata and controls
81 lines (68 loc) · 2.79 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
using
Protobuf
.
Text
;
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Linq
;
using
System
.
Text
;
using
System
.
Threading
.
Tasks
;
namespace
Tensorflow
.
CodeGen
{
public
class
GenOpsWriter
{
private
string
_basePath
;
private
Dictionary
<
string
,
OpDef
>
_opMap
;
private
OpClassifier
_opClassifier
;
private
FunctionGenerator
_fg
=
new
(
)
;
private
DescriptionGenerator
_dg
;
public
GenOpsWriter
(
string
basePath
,
string
pythonFilesDirectory
,
string
apiDefFilesDirectory
,
string
opDefFilename
)
{
_basePath
=
basePath
;
var
opDefs
=
Utils
.
ReadAllOpDefs
(
opDefFilename
)
;
_opMap
=
opDefs
.
Op
.
ToDictionary
(
x
=>
Utils
.
ConvertToUnderscore
(
x
.
Name
)
,
x
=>
x
)
;
_opClassifier
=
new
OpClassifier
(
pythonFilesDirectory
,
opDefs
.
Op
.
Select
(
x
=>
Utils
.
ConvertToUnderscore
(
x
.
Name
)
)
)
;
_dg
=
new
DescriptionGenerator
(
apiDefFilesDirectory
)
;
}
public
void
WriteAll
(
)
{
foreach
(
var
(
target
,
set
)
in
_opClassifier
.
OpSet
)
{
StringBuilder
sb
=
new
StringBuilder
(
)
;
// Write file header.
sb
.
AppendLine
(
"/*Wrappers around TensorFlow ops. This file is MACHINE GENERATED! Do not edit.*/"
)
;
sb
.
AppendLine
(
)
;
// Add commonly used namespaces.
sb
.
AppendLine
(
"using Tensorflow.Eager;"
)
;
sb
.
AppendLine
(
"using Tensorflow.Contexts;"
)
;
sb
.
AppendLine
(
"using Tensorflow.Exceptions;"
)
;
sb
.
AppendLine
(
"using static Tensorflow.Binding;"
)
;
sb
.
AppendLine
(
)
;
// Specify the namespace
sb
.
AppendLine
(
"namespace Tensorflow;"
)
;
sb
.
AppendLine
(
)
;
// Write class name
sb
.
AppendLine
(
$
"public static class
{
target
}
"
)
;
sb
.
AppendLine
(
"{"
)
;
foreach
(
var
funcName
in
set
)
{
if
(
_opMap
.
ContainsKey
(
funcName
)
)
{
var
opDef
=
_opMap
[
funcName
]
;
// write the descriptions.
_dg
.
AppendDescription
(
opDef
,
sb
)
;
// write the function body.
_fg
.
AppendFunction
(
opDef
,
sb
)
;
}
else
if
(
funcName
.
StartsWith
(
"_"
)
)
{
var
opDef
=
_opMap
[
funcName
.
Substring
(
1
)
]
;
_fg
.
AppendFunction
(
opDef
,
sb
)
;
}
}
// Close class scope.
sb
.
AppendLine
(
"}"
)
;
string
fullFilePath
=
Path
.
Combine
(
_basePath
,
$
"
{
target
}
.cs"
)
;
File
.
WriteAllText
(
fullFilePath
,
sb
.
ToString
(
)
)
;
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL