FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TensorFlow.NET/tools/Tensorflow.CodeGen/OpClassifier.cs at master · securebread/TensorFlow.NET · GitHub
securebread
TensorFlow.NET
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
TensorFlow.NET
/
tools
/
Tensorflow.CodeGen
/
OpClassifier.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (48 loc) · 2.09 KB
Breadcrumbs
TensorFlow.NET
/
tools
/
Tensorflow.CodeGen
/
OpClassifier.cs
Copy path
File metadata and controls
51 lines (48 loc) · 2.09 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
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Linq
;
using
System
.
Text
;
using
System
.
Threading
.
Tasks
;
using
System
.
Text
.
RegularExpressions
;
namespace
Tensorflow
.
CodeGen
{
public
class
OpClassifier
{
private
static
readonly
string
_filenamePattern
=
@"^gen_[a-z_]*_ops.py$"
;
private
static
readonly
string
_pythonFunctionPattern
=
@"def\s+(\w+\d*\w*)\((?:\s*\w+\s*(?:=\s*[\S]*)*,\s*)*\s*name=None\):"
;
private
Dictionary
<
string
,
HashSet
<
string
>
>
_opSet
=
new
(
)
;
public
Dictionary
<
string
,
HashSet
<
string
>
>
OpSet
=>
_opSet
;
public
OpClassifier
(
string
pythonFileFolder
,
IEnumerable
<
string
>
funcNames
)
{
DirectoryInfo
directory
=
new
DirectoryInfo
(
pythonFileFolder
)
;
Dictionary
<
string
,
string
>
fileContentMap
=
new
(
)
;
foreach
(
FileInfo
file
in
directory
.
GetFiles
(
)
)
{
if
(
Regex
.
IsMatch
(
file
.
Name
,
_filenamePattern
)
)
{
Console
.
WriteLine
(
file
.
Name
)
;
string
filenamePrefix
=
file
.
Name
.
Split
(
'.'
)
[
0
]
;
string
content
=
File
.
ReadAllText
(
file
.
FullName
)
;
fileContentMap
[
filenamePrefix
]
=
content
;
}
}
foreach
(
var
funcName
in
funcNames
)
{
Console
.
WriteLine
(
funcName
)
;
string
funcPattern
=
@$
"^def\s+
{
funcName
}
\("
;
string
fallbackFuncPattern
=
@$
"^def\s+
{
funcName
}
_eager_fallback\("
;
foreach
(
var
(
target
,
content
)
in
fileContentMap
)
{
if
(
content
.
Contains
(
$
"def
{
funcName
}
"
)
&&
content
.
Contains
(
$
"def
{
funcName
}
_eager_fallback"
)
)
{
_opSet
.
SetDefault
(
target
,
new
HashSet
<
string
>
(
)
)
.
Add
(
funcName
)
;
}
else
if
(
content
.
Contains
(
$
"def _
{
funcName
}
"
)
&&
content
.
Contains
(
$
"def _
{
funcName
}
_eager_fallback"
)
)
{
_opSet
.
SetDefault
(
target
,
new
HashSet
<
string
>
(
)
)
.
Add
(
funcName
)
;
}
}
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL