-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split variable and operators name generation
This allows for a compatibility with sklearn2onnx. Moreover we now explicitely set names to operators.
- Loading branch information
Showing
8 changed files
with
247 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import NamedTuple, Callable | ||
|
||
|
||
class Context(NamedTuple): | ||
generate_variable_name: Callable[[], str] | ||
generate_operator_name: Callable[[], str] | ||
|
||
|
||
def create_name_generator() -> Callable[[str], str]: | ||
state = {} | ||
|
||
def _generate_unique_name(name: str) -> str: | ||
""" Generates a new globaly unique name in the graph | ||
""" | ||
if name in state: | ||
state[name] += 1 | ||
else: | ||
state[name] = 0 | ||
|
||
return "{}_{}".format(name, state[name]) | ||
|
||
return _generate_unique_name | ||
|
||
|
||
def create( | ||
generate_variable_name=None, | ||
generate_operator_name=None, | ||
) -> Context: | ||
generate_variable_name = generate_variable_name or create_name_generator() | ||
generate_operator_name = generate_operator_name or create_name_generator() | ||
|
||
return Context( | ||
generate_variable_name=generate_variable_name, | ||
generate_operator_name=generate_operator_name, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.