def generate_copied_value(value : 'values.Value'): if isinstance(value, values.NumberValue): copied = values.NumberValue(value.internal_value) return copied if isinstance(value, values.TensorValue): copied = values.TensorValue() copied.shape = value.shape return copied if isinstance(value, values.NoneValue): copied = values.NoneValue() return copied if isinstance(value, values.BoolValue): copied = values.BoolValue(value.internal_value) return copied if isinstance(value, values.StrValue): copied = values.StrValue(value.internal_value) return copied if isinstance(value, values.RangeValue): copied = values.RangeValue() return copied if isinstance(value, values.TupleValue): copied = values.TupleValue(value.values) return copied if config.show_warnings: print('Unknown type {} is copied'.format(value)) return values.Value()
def vcall(self, module : 'Field', graph : 'Graph', inst : 'values.Object', args = [], line = -1): node = nodes.NodeGenerate('range', [v.obj.get_value() for v in args], line) graph.add_node(node) value = values.RangeValue() value.name = '@F.{}.{}'.format(line, self.name) node.set_outputs([value]) return values.Object(value)
def vcall(self, module: 'Field', graph: 'Graph', inst: 'values.ValueRef', args: 'functions.FunctionArgInput', line=-1): node = nodes.NodeGenerate( 'range', [v.get_value() for v in args.inputs], line) graph.add_node(node) value = values.RangeValue() value.name = '@F.{}.{}'.format(line, self.name) node.set_outputs([value]) return values.ValueRef(value)
def vcall(self, module: 'values.Field', graph: 'core.Graph', inst: 'Value', args=[], line=-1): node = nodes.NodeGenerate('range', [v.value for v in args], line) graph.add_node(node) value = values.RangeValue() node.set_outputs([value]) return value
def generate_copied_value(value: 'values.Value'): assert (isinstance(value, values.Value)) if isinstance(value, values.NumberValue): copied = values.NumberValue(value.internal_value) copied.dtype = value.dtype return copied if isinstance(value, values.TensorValue): copied = values.TensorValue() copied.value = value.value copied.shape = value.shape copied.dtype = value.dtype return copied if isinstance(value, values.ListValue): copied = values.ListValue() copied.is_any = value.is_any if value.internal_value is not None: copied.internal_value = value.internal_value.copy() return copied if isinstance(value, values.NoneValue): copied = values.NoneValue() return copied if isinstance(value, values.BoolValue): copied = values.BoolValue(value.internal_value) return copied if isinstance(value, values.StrValue): copied = values.StrValue(value.internal_value) return copied if isinstance(value, values.RangeValue): copied = values.RangeValue() return copied if isinstance(value, values.TupleValue): if value.internal_value is not None: copied = values.TupleValue(value.internal_value.copy()) else: copied = values.TupleValue(value.internal_value) return copied if config.show_warnings: print('Unknown type {} is copied'.format(value)) return values.Value()
def generate_value_with_same_type(value: 'values.Value', is_dummy_value=False, suffix_type=SuffixType.Unknown): assert (isinstance(value, values.Value)) ret = None if isinstance(value, values.TensorValue): ret = values.TensorValue() ret.shape = value.shape ret.dtype = value.dtype elif isinstance(value, values.NumberValue): dtype = None if value.internal_value is None: dtype = value.dtype elif isinstance(value.internal_value, int): dtype = np.array(value.internal_value).dtype elif isinstance(value.internal_value, float): dtype = np.array(value.internal_value).dtype ret = values.NumberValue(None) ret.dtype = dtype elif isinstance(value, values.StrValue): ret = values.StrValue(None) elif isinstance(value, values.BoolValue): ret = values.BoolValue(None) elif isinstance(value, values.ListValue): ret = values.ListValue(None) elif isinstance(value, values.NoneValue): ret = values.NoneValue() elif isinstance(value, values.TupleValue): ret = values.TupleValue() elif isinstance(value, values.RangeValue): ret = values.RangeValue() elif isinstance(value, values.UnknownValue): ret = values.UnknownValue() elif ret is None and isinstance(value, values.Value): ret = values.Value() else: assert (False) assert (ret is not None) ret.is_dummy_value = is_dummy_value if suffix_type == SuffixType.Unknown: ret.name = value.name + '_st' elif suffix_type == SuffixType.Unused: ret.name = value.name + '_unused' elif suffix_type == SuffixType.Dummy: ret.name = value.name + '_dummy' elif suffix_type == SuffixType.Input: ret.name = value.name + '_in' else: assert (False) return ret