def _generate_moment_matrix(self, n_vars, block_index, processed_entries,<EOL>monomialsA, monomialsB, ppt=False):
row_offset = <NUM_LIT:0><EOL>if block_index > <NUM_LIT:0>:<EOL><INDENT>for block_size in self.block_struct[<NUM_LIT:0>:block_index]:<EOL><INDENT>row_offset += block_size ** <NUM_LIT:2><EOL><DEDENT><DEDENT>N = len(monomialsA)*len(monomialsB)<EOL>func = partial(assemble_monomial_and_do_substitutions,<EOL>monomialsA=monomialsA, monomialsB=monomialsB, ppt=ppt,<EOL>substitutions=self.substitutions,<EOL>pure_substitution_rules=self.pure_substitution_rules)<EOL>if self._parallel:<EOL><INDENT>pool = Pool()<EOL>chunksize = int(max(int(np.sqrt(len(monomialsA) * len(monomialsB) *<EOL>len(monomialsA) / <NUM_LIT:2>) / cpu_count()),<EOL><NUM_LIT:1>))<EOL><DEDENT>for rowA in range(len(monomialsA)):<EOL><INDENT>if self._parallel:<EOL><INDENT>iter_ = pool.map(func, [(rowA, columnA, rowB, columnB)<EOL>for rowB in range(len(monomialsB))<EOL>for columnA in range(rowA,<EOL>len(monomialsA))<EOL>for columnB in range((rowA == columnA)*rowB,<EOL>len(monomialsB))],<EOL>chunksize)<EOL>print_criterion = processed_entries + len(iter_)<EOL><DEDENT>else:<EOL><INDENT>iter_ = imap(func, [(rowA, columnA, rowB, columnB)<EOL>for columnA in range(rowA, len(monomialsA))<EOL>for rowB in range(len(monomialsB))<EOL>for columnB in range((rowA == columnA)*rowB,<EOL>len(monomialsB))])<EOL><DEDENT>for columnA, rowB, columnB, monomial in iter_:<EOL><INDENT>processed_entries += <NUM_LIT:1><EOL>n_vars = self._push_monomial(monomial, n_vars,<EOL>row_offset, rowA,<EOL>columnA, N, rowB,<EOL>columnB, len(monomialsB),<EOL>prevent_substitutions=True)<EOL>if self.verbose > <NUM_LIT:0> and (not self._parallel or<EOL>processed_entries == self.n_vars or<EOL>processed_entries == print_criterion):<EOL><INDENT>percentage = processed_entries / self.n_vars<EOL>time_used = time.time()-self._time0<EOL>eta = (<NUM_LIT:1.0> / percentage) * time_used - time_used<EOL>hours = int(eta/<NUM_LIT>)<EOL>minutes = int((eta-<NUM_LIT>*hours)/<NUM_LIT>)<EOL>seconds = eta-<NUM_LIT>*hours-minutes*<NUM_LIT><EOL>msg = "<STR_LIT>"<EOL>if self.verbose > <NUM_LIT:1> and self._parallel:<EOL><INDENT>msg = "<STR_LIT>".format(block_index, cpu_count(),<EOL>chunksize)<EOL><DEDENT>msg = "<STR_LIT>".format(n_vars, percentage, hours, minutes, seconds) +msg<EOL>msg = "<STR_LIT>" + msg + "<STR_LIT:)>"<EOL>sys.stdout.write(msg)<EOL>sys.stdout.flush()<EOL><DEDENT><DEDENT><DEDENT>if self._parallel:<EOL><INDENT>pool.close()<EOL>pool.join()<EOL><DEDENT>if self.verbose > <NUM_LIT:0>:<EOL><INDENT>sys.stdout.write("<STR_LIT:\r>")<EOL><DEDENT>return n_vars, block_index + <NUM_LIT:1>, processed_entries<EOL>
Generate the moment matrix of monomials.

        Arguments:
        n_vars -- current number of variables
        block_index -- current block index in the SDP matrix
        monomials -- |W_d| set of words of length up to the relaxation level