MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / _analyze_input_data

Method _analyze_input_data

tensorpack/dataflow/common.py:761–820  ·  view source on GitHub ↗

Gather useful debug information from a datapoint. Args: entry: the datapoint component, either a list or a dict k (int): index of this component in current datapoint depth (int, optional): recursion depth max_depth, max_list: same as

(self, entry, k, depth=1, max_depth=3, max_list=3)

Source from the content-addressed store, hash-verified

759 self.max_list = max_list
760
761 def _analyze_input_data(self, entry, k, depth=1, max_depth=3, max_list=3):
762 """
763 Gather useful debug information from a datapoint.
764
765 Args:
766 entry: the datapoint component, either a list or a dict
767 k (int): index of this component in current datapoint
768 depth (int, optional): recursion depth
769 max_depth, max_list: same as in :meth:`__init__`.
770
771 Returns:
772 string: debug message
773 """
774
775 class _elementInfo(object):
776 def __init__(self, el, pos, depth=0, max_list=3):
777 self.shape = ""
778 self.type = type(el).__name__
779 self.dtype = ""
780 self.range = ""
781
782 self.sub_elements = []
783
784 self.ident = " " * (depth * 2)
785 self.pos = pos
786
787 numpy_scalar_types = list(itertools.chain(*np.sctypes.values()))
788
789 if isinstance(el, (int, float, bool)):
790 self.range = " with value {}".format(el)
791 elif type(el) is np.ndarray:
792 self.shape = " of shape {}".format(el.shape)
793 self.dtype = ":{}".format(str(el.dtype))
794 self.range = " in range [{}, {}]".format(el.min(), el.max())
795 elif type(el) in numpy_scalar_types:
796 self.range = " with value {}".format(el)
797 elif isinstance(el, (list, tuple)):
798 self.shape = " of len {}".format(len(el))
799
800 if depth < max_depth:
801 for k, subel in enumerate(el):
802 if k < max_list:
803 self.sub_elements.append(_elementInfo(subel, k, depth + 1, max_list))
804 else:
805 self.sub_elements.append(" " * ((depth + 1) * 2) + '...')
806 break
807 else:
808 if len(el) > 0:
809 self.sub_elements.append(" " * ((depth + 1) * 2) + ' ...')
810
811 def __str__(self):
812 strings = []
813 vals = (self.ident, self.pos, self.type, self.dtype, self.shape, self.range)
814 strings.append("{}{}: {}{}{}{}".format(*vals))
815
816 for k, el in enumerate(self.sub_elements):
817 strings.append(str(el))
818 return "\n".join(strings)

Callers 1

_get_msgMethod · 0.95

Calls 1

_elementInfoClass · 0.85

Tested by

no test coverage detected