예제 #1
0
 def from_json(cls, json_obj, context=None):
     # Create dummy object
     ret = cls('tmp', 'tmp', 'tmp')
     serialize.set_properties_from_json(ret, json_obj, context=context)
     # Check validity now
     ret.validate()
     return ret
예제 #2
0
    def from_json(json_obj: Dict[str, Any],
                  context: Dict[str, Any] = None) -> 'Transformation':
        try:
            xform = next(ext for ext in Transformation.extensions().keys()
                         if ext.__name__ == json_obj['transformation'])
        except StopIteration:
            return None

        # Recreate subgraph
        expr = xform.expressions()[json_obj['expr_index']]
        subgraph = {
            expr.node(int(k)): int(v)
            for k, v in json_obj['_subgraph'].items()
        }

        # Reconstruct transformation
        ret = xform(json_obj['sdfg_id'], json_obj['state_id'], subgraph,
                    json_obj['expr_index'])
        context = context or {}
        context['transformation'] = ret
        serialize.set_properties_from_json(
            ret,
            json_obj,
            context=context,
            ignore_properties={'transformation', 'type'})
        return ret
예제 #3
0
파일: data.py 프로젝트: am-ivanov/dace
    def from_json(json_obj, context=None):
        if json_obj['type'] != "Scalar":
            raise TypeError("Invalid data type")

        # Create dummy object
        ret = Scalar(dtypes.int8)
        serialize.set_properties_from_json(ret, json_obj, context=context)

        return ret
예제 #4
0
    def from_json(cls, json_obj, context=None):
        # Create dummy object
        ret = cls(dtypes.int8, ())
        serialize.set_properties_from_json(ret, json_obj, context=context)
        # TODO: This needs to be reworked (i.e. integrated into the list property)
        ret.strides = list(map(symbolic.pystr_to_symbolic, ret.strides))

        # Check validity now
        ret.validate()
        return ret
예제 #5
0
파일: data.py 프로젝트: DeathyYoung/dace
    def from_json(json_obj, context=None):
        if json_obj['type'] != "Stream":
            raise TypeError("Invalid data type")

        # Create dummy object
        ret = Stream(dtypes.int8, 1)
        serialize.set_properties_from_json(ret, json_obj, context=context)

        # Check validity now
        ret.validate()
        return ret
예제 #6
0
파일: data.py 프로젝트: DeathyYoung/dace
    def from_json(json_obj, context=None):
        if json_obj['type'] != "Array":
            raise TypeError("Invalid data type")

        # Create dummy object
        ret = Array(dtypes.int8, ())
        serialize.set_properties_from_json(ret, json_obj, context=context)
        # TODO: This needs to be reworked (i.e. integrated into the list property)
        ret.strides = list(map(symbolic.pystr_to_symbolic, ret.strides))

        # Check validity now
        ret.validate()
        return ret
예제 #7
0
    def from_json(json_obj, context=None):
        xform = next(ext for ext in SubgraphTransformation.extensions().keys()
                     if ext.__name__ == json_obj['transformation'])

        # Reconstruct transformation
        ret = xform(json_obj['subgraph'], json_obj['sdfg_id'],
                    json_obj['state_id'])
        context = context or {}
        context['transformation'] = ret
        serialize.set_properties_from_json(
            ret,
            json_obj,
            context=context,
            ignore_properties={'transformation', 'type'})
        return ret
예제 #8
0
파일: data.py 프로젝트: am-ivanov/dace
    def from_json(cls, json_obj, context=None):
        # Create dummy object
        ret = cls(dtypes.int8, ())
        serialize.set_properties_from_json(ret, json_obj, context=context)

        # Default shape-related properties
        if not ret.offset:
            ret.offset = [0] * len(ret.shape)
        if not ret.strides:
            # Default strides are C-ordered
            ret.strides = [_prod(ret.shape[i + 1:]) for i in range(len(ret.shape))]
        if ret.total_size == 0:
            ret.total_size = _prod(ret.shape)

        # Check validity now
        ret.validate()
        return ret
예제 #9
0
    def from_json(json_obj: Dict[str, Any],
                  context: Dict[str, Any] = None) -> 'SubgraphTransformation':
        xform = next(ext
                     for ext in SubgraphTransformation.subclasses_recursive()
                     if ext.__name__ == json_obj['transformation'])

        # Reconstruct transformation
        ret = xform()
        ret.setup_match(json_obj['subgraph'], json_obj['sdfg_id'],
                        json_obj['state_id'])
        context = context or {}
        context['transformation'] = ret
        serialize.set_properties_from_json(
            ret,
            json_obj,
            context=context,
            ignore_properties={'transformation', 'type'})
        return ret
예제 #10
0
    def from_json(json_obj: Dict[str, Any],
                  context: Dict[str, Any] = None) -> 'SubgraphTransformation':
        try:
            xform = next(ext
                         for ext in SubgraphTransformation.extensions().keys()
                         if ext.__name__ == json_obj['transformation'])
        except StopIteration:
            return None

        # Reconstruct transformation
        ret = xform(json_obj['subgraph'], json_obj['sdfg_id'],
                    json_obj['state_id'])
        context = context or {}
        context['transformation'] = ret
        serialize.set_properties_from_json(
            ret,
            json_obj,
            context=context,
            ignore_properties={'transformation', 'type'})
        return ret
예제 #11
0
    def from_json(json_obj: Dict[str, Any],
                  context: Dict[str, Any] = None) -> 'ExpandTransformation':
        xform = pydoc.locate(json_obj['classpath'])

        # Recreate subgraph
        expr = xform.expressions()[json_obj['expr_index']]
        subgraph = {
            expr.node(int(k)): int(v)
            for k, v in json_obj['_subgraph'].items()
        }

        # Reconstruct transformation
        ret = xform(json_obj['sdfg_id'], json_obj['state_id'], subgraph,
                    json_obj['expr_index'])
        context = context or {}
        context['transformation'] = ret
        serialize.set_properties_from_json(
            ret,
            json_obj,
            context=context,
            ignore_properties={'transformation', 'type', 'classpath'})
        return ret
예제 #12
0
    def from_json(json_obj: Dict[str, Any],
                  context: Dict[str, Any] = None) -> 'PatternTransformation':
        xform = next(ext for ext in PatternTransformation.subclasses_recursive(
            all_subclasses=True) if ext.__name__ == json_obj['transformation'])

        # Recreate subgraph
        expr = xform.expressions()[json_obj['expr_index']]
        subgraph = {
            expr.node(int(k)): int(v)
            for k, v in json_obj['_subgraph'].items()
        }

        # Reconstruct transformation
        ret = xform(None, json_obj['sdfg_id'], json_obj['state_id'], subgraph,
                    json_obj['expr_index'])
        context = context or {}
        context['transformation'] = ret
        serialize.set_properties_from_json(
            ret,
            json_obj,
            context=context,
            ignore_properties={'transformation', 'type'})
        return ret
예제 #13
0
 def from_json(json_obj, context=None):
     ret = MyObject(0.0)
     set_properties_from_json(ret, json_obj, context=context)
     return ret
예제 #14
0
파일: data.py 프로젝트: am-ivanov/dace
    def from_json(cls, json_obj, context=None):
        # Create dummy object
        ret = cls(dtypes.int8, 1)
        serialize.set_properties_from_json(ret, json_obj, context=context)

        return ret