feat: make get_printable_graph give correct info for np.dot

closes #204
This commit is contained in:
Benoit Chevallier-Mames
2021-09-03 09:47:34 +02:00
committed by Benoit Chevallier
parent 6b6aa7ee4e
commit 150d33ba48
6 changed files with 53 additions and 23 deletions

View File

@@ -18,7 +18,7 @@ def output_data_type_to_string(node):
str: a string representing the datatypes of the outputs of the node
"""
return ", ".join([str(o.data_type) for o in node.outputs])
return ", ".join([str(o) for o in node.outputs])
def get_printable_graph(opgraph: OPGraph, show_data_types: bool = False) -> str:
@@ -43,6 +43,11 @@ def get_printable_graph(opgraph: OPGraph, show_data_types: bool = False) -> str:
for node in nx.topological_sort(graph):
# This code doesn't work with more than a single output. For more outputs,
# we would need to change the way the destination are created: currently,
# they only are done by incrementing i
assert len(node.outputs) == 1
if isinstance(node, ir.Input):
what_to_print = node.input_name
elif isinstance(node, ir.Constant):
@@ -74,6 +79,7 @@ def get_printable_graph(opgraph: OPGraph, show_data_types: bool = False) -> str:
# Then, just print the predecessors in the right order
what_to_print += ", ".join([x[1] for x in list_of_arg_name]) + ")"
# This code doesn't work with more than a single output
new_line = f"%{i} = {what_to_print}"
# Manage datatypes

View File

@@ -17,8 +17,7 @@ class BaseValue(ABC):
self._is_encrypted = is_encrypted
def __repr__(self) -> str: # pragma: no cover
encrypted_str = "Encrypted" if self._is_encrypted else "Clear"
return f"{encrypted_str}{self.__class__.__name__}<{self.data_type!r}>"
return str(self)
@abstractmethod
def __eq__(self, other: object) -> bool:

View File

@@ -10,6 +10,10 @@ class ScalarValue(BaseValue):
def __eq__(self, other: object) -> bool:
return BaseValue.__eq__(self, other)
def __str__(self) -> str: # pragma: no cover
encrypted_str = "Encrypted" if self._is_encrypted else "Clear"
return f"{encrypted_str}Scalar<{self.data_type!r}>"
def make_clear_scalar(data_type: BaseDataType) -> ScalarValue:
"""Helper to create a clear ScalarValue.

View File

@@ -35,6 +35,10 @@ class TensorValue(BaseValue):
and super().__eq__(other)
)
def __str__(self) -> str:
encrypted_str = "Encrypted" if self._is_encrypted else "Clear"
return f"{encrypted_str}Tensor<{str(self.data_type)}, shape={self.shape}>"
@property
def shape(self) -> Tuple[int, ...]:
"""The TensorValue shape property.