Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_value_type(self):
if self._value_type is None:
self._value_type = ir.LiteralStructType([t.get_value_type()
for t in self._models])
return self._value_type
# FIXME: Consider enums of non-int type
assert all(round(x.value) == x.value for x in type(t))
return self.int32_ty
elif isinstance(t, (int, float, np.number)):
return self.float_ty
elif isinstance(t, np.ndarray):
return self.convert_python_struct_to_llvm_ir(t.tolist())
elif isinstance(t, np.random.RandomState):
return pnlvm.builtins.get_mersenne_twister_state_struct(self)
elif isinstance(t, Time):
return ir.ArrayType(self.int32_ty, len(Time._time_scale_attr_map))
elif isinstance(t, SampleIterator):
if isinstance(t.generator, list):
return ir.ArrayType(self.float_ty, len(t.generator))
# Generic iterator is {start, increment, count}
return ir.LiteralStructType((self.float_ty, self.float_ty, self.int32_ty))
assert False, "Don't know how to convert {}".format(type(t))
def get_private_condition_struct_type(self, composition):
time_stamp_struct = ir.LiteralStructType([self.ctx.int32_ty,
self.ctx.int32_ty,
self.ctx.int32_ty])
structure = ir.LiteralStructType([
time_stamp_struct, # current time stamp
ir.ArrayType( # for each node
ir.LiteralStructType([
self.ctx.int32_ty, # number of executions
time_stamp_struct # time stamp of last execution
]), len(composition.nodes)
)
])
return structure
def _llvmType(self, module):
return ll.LiteralStructType([t.llvmType(module) for t in self.types])
def convert_python_struct_to_llvm_ir(self, t):
self._stats["types_converted"] += 1
if t is None:
return ir.LiteralStructType([])
elif type(t) is list:
if len(t) == 0:
return ir.LiteralStructType([])
elems_t = [self.convert_python_struct_to_llvm_ir(x) for x in t]
if all(x == elems_t[0] for x in elems_t):
return ir.ArrayType(elems_t[0], len(elems_t))
return ir.LiteralStructType(elems_t)
elif type(t) is tuple:
elems_t = (self.convert_python_struct_to_llvm_ir(x) for x in t)
return ir.LiteralStructType(elems_t)
elif isinstance(t, enum.Enum):
# FIXME: Consider enums of non-int type
assert all(round(x.value) == x.value for x in type(t))
return self.int32_ty
elif isinstance(t, (int, float, np.number)):
return self.float_ty
elif isinstance(t, np.ndarray):
return self.convert_python_struct_to_llvm_ir(t.tolist())
elif isinstance(t, np.random.RandomState):
def get_condition_struct_type(self, composition=None):
composition = self.composition if composition is None else composition
structs = [self.get_private_condition_struct_type(composition)]
for node in composition.nodes:
structs.append(self.get_condition_struct_type(node) if isinstance(node, type(self.composition)) else ir.LiteralStructType([]))
return ir.LiteralStructType(structs)
def get_mersenne_twister_state_struct(ctx):
return ir.LiteralStructType([
ir.ArrayType(ctx.int32_ty, _MERSENNE_N), # array
ctx.int32_ty, # index
ctx.int32_ty, # last_gauss available
ctx.float_ty]) # last_gauss
def convert_python_struct_to_llvm_ir(self, t):
self._stats["types_converted"] += 1
if t is None:
return ir.LiteralStructType([])
elif type(t) is list:
if len(t) == 0:
return ir.LiteralStructType([])
elems_t = [self.convert_python_struct_to_llvm_ir(x) for x in t]
if all(x == elems_t[0] for x in elems_t):
return ir.ArrayType(elems_t[0], len(elems_t))
return ir.LiteralStructType(elems_t)
elif type(t) is tuple:
elems_t = (self.convert_python_struct_to_llvm_ir(x) for x in t)
return ir.LiteralStructType(elems_t)
elif isinstance(t, enum.Enum):
# FIXME: Consider enums of non-int type
assert all(round(x.value) == x.value for x in type(t))
return self.int32_ty
elif isinstance(t, (int, float, np.number)):
return self.float_ty
elif isinstance(t, np.ndarray):
return self.convert_python_struct_to_llvm_ir(t.tolist())
elif isinstance(t, np.random.RandomState):
return pnlvm.builtins.get_mersenne_twister_state_struct(self)
elif isinstance(t, Time):
return ir.ArrayType(self.int32_ty, len(Time._time_scale_attr_map))
elif isinstance(t, SampleIterator):
def get_condition_struct_type(self, composition=None):
composition = self.composition if composition is None else composition
structs = [self.get_private_condition_struct_type(composition)]
for node in composition.nodes:
structs.append(self.get_condition_struct_type(node) if isinstance(node, type(self.composition)) else ir.LiteralStructType([]))
return ir.LiteralStructType(structs)