Smart contract is a contract that relies on computers to operate in cyberspace. It spreads, validates, or executes contracts in an informational manner, and is read and executed by computers. It has the characteristics of self-help. The decentralization of blockchain and data tamper prevention determine that smart contracts are more suitable for implementation on blockchain
def format_clip(self)->None:
"""
对于不同的模型格式,clip算子将有两种不同的输入格式:
for different models,possibly clip op has the following input formats
1.min,max参数由第二、第三个输入变量给出
min,max parameter will be given by the second and third input variable
2.min,max参数由attribute给出
min,max parameter will be given by the attribute
此函数统一clip算子行为:所有clip算子的min,max参数第二第三个变量给出
this func unifies behaviors of clip op:min,max parameter will be given by input vars
针对可能存在的min,max为空的情况,将其直接置为2<<30(保证处理后非空)
当min,max参数由第二、第三个输入变量给出时,其中一个为空时直接返回ValueError
ValueError will be raised when any of min,max parameters is null
"""
interested_ops=[]
for _,operation in self.graph.operations.items():
if operation.type=='Clip'and('min'in operation.attributes or'max'in operation.attributes):
interested_ops.append(operation)
for op in interested_ops:
assert isinstance(op,Operation)
min=op.attributes.get('min',-2<<30)
max=op.attributes.get('max',+2<<30)
min_var=Variable(name=op.name+'_min',value=min,is_parameter=True,dest_ops=[op])
max_var=Variable(name=op.name+'_max',value=max,is_parameter=True,dest_ops=[op])
self.graph.append_variable(min_var)
self.graph.append_variable(max_var)
op.inputs.append(min_var)
op.inputs.append(max_var)
if'min'in op.attributes:op.attributes.pop('min')
if'max'in op.attributes:op.attributes.pop('max')