def _generate_multiply(self, mult_op: saldag.Multiply): """ Generate code for Multiply operations. """ store_code = '' if mult_op.is_leaf(): store_code += self._generate_store(mult_op) op_cols = mult_op.operands operands = [] scalar = 1 for op_col in op_cols: if hasattr(op_col, 'name'): operands.append(mult_op.get_in_rel().name + '.' + op_col.name) else: scalar = op_col template = open( "{0}/{1}.tmpl".format(self.template_directory, 'multiply'), 'r').read() data = { 'OPERANDS': '*'.join(c for c in operands), 'SCALAR': scalar, 'TARGET': mult_op.target_col.name, 'INREL': mult_op.get_in_rel().name, 'OUTREL': mult_op.out_rel.name, 'CACHE_VAR': cache_var(mult_op) } return pystache.render(template, data) + store_code
def _generate_multiply(self, mult_op: ccdag.Multiply): """ Generate code for Multiply operations. """ operands = [self._col_or_scalar(col) for col in mult_op.operands] lambda_expr = "lambda row : " + " * ".join([op for op in operands]) return "{}{} = arithmetic_project({}, {}, {})\n".format( self.space, mult_op.out_rel.name, mult_op.get_in_rel().name, mult_op.target_col.idx, lambda_expr)
def _generate_multiply(self, mult_op: saldag.Multiply): """ Generate code for Multiply operations. """ operands = [col.idx for col in mult_op.operands] lambda_expr = "lambda row : " + " * ".join( ["row[{}]".format(idx) for idx in operands]) return "{}{} = arithmetic_project({}, {}, {})\n".format( self.space, mult_op.out_rel.name, mult_op.get_in_rel().name, mult_op.target_col.idx, lambda_expr)
def _generate_multiply(self, multiply_op: saldag.Multiply): """ Generate code for Multiply operations. """ operand_col_str = " * ".join( [str(col) for col in multiply_op.operands]) return "MULTIPLY{} [{} -> {}] FROM ({}) AS {}\n".format( "MPC" if multiply_op.is_mpc else "", str(multiply_op.target_col), operand_col_str, multiply_op.get_in_rel().dbg_str(), multiply_op.out_rel.dbg_str())
def _rewrite_multiply(self, node: saldag.Multiply): """ Push down collusion sets for a Multiply node. """ out_rel_cols = node.out_rel.columns operands = node.operands target_col = node.target_col # Update target column collusion set target_col_out = out_rel_cols[target_col.idx] target_col_out.coll_sets |= utils.coll_sets_from_columns(operands) # The other columns weren't modified so the collusion sets # simply carry over for in_col, out_col in zip(node.get_in_rel().columns, out_rel_cols): if in_col != target_col: out_col.coll_sets |= copy.deepcopy(in_col.coll_sets)