in src/beanmachine/ppl/compiler/gen_bmg_python.py [0:0]
def _add_constant(self, node: bn.ConstantNode) -> None: # noqa
graph_id = len(self.node_to_graph_id)
self.node_to_graph_id[node] = graph_id
t = type(node)
v = node.value
if t is bn.PositiveRealNode:
f = f"add_constant_pos_real({str(float(v))})"
elif t is bn.NegativeRealNode:
f = f"add_constant_neg_real({str(float(v))})"
elif t is bn.ProbabilityNode:
f = f"add_constant_probability({str(float(v))})"
elif t is bn.BooleanNode:
f = f"add_constant_bool({str(bool(v))})"
elif t is bn.NaturalNode:
f = f"add_constant_natural({str(int(v))})"
elif t is bn.RealNode:
f = f"add_constant_real({str(float(v))})"
elif t is bn.ConstantPositiveRealMatrixNode:
f = f"add_constant_pos_matrix({_matrix_to_python(v)})"
elif t is bn.ConstantRealMatrixNode:
f = f"add_constant_real_matrix({_matrix_to_python(v)})"
elif t is bn.ConstantNegativeRealMatrixNode:
f = f"add_constant_neg_matrix({_matrix_to_python(v)})"
elif t is bn.ConstantProbabilityMatrixNode:
f = f"add_constant_probability_matrix({_matrix_to_python(v)})"
elif t is bn.ConstantSimplexMatrixNode:
f = f"add_constant_col_simplex_matrix({_matrix_to_python(v)})"
elif t is bn.ConstantNaturalMatrixNode:
f = f"add_constant_natural_matrix({_matrix_to_python(v)})"
elif t is bn.ConstantBooleanMatrixNode:
f = f"add_constant_bool_matrix({_matrix_to_python(v)})"
elif isinstance(v, torch.Tensor) and v.numel() != 1:
f = f"add_constant_real_matrix({_matrix_to_python(v)})"
else:
f = f"add_constant_real({str(float(v))})"
self._code.append(f"n{graph_id} = g.{f}")