def dM(self, t, param, Mt, tips=None, gaps=None):
assert isinstance(t, float) and t > <NUM_LIT:0>, "<STR_LIT>".format(t)<EOL>assert (param == '<STR_LIT:t>') or (param in self.freeparams), (<EOL>"<STR_LIT>".format(param))<EOL>if Mt is None:<EOL><INDENT>Mt = self.M(t, tips=tips, gaps=gaps)<EOL><DEDENT>if (param == '<STR_LIT>') or (param == '<STR_LIT:t>'):<EOL><INDENT>if param == '<STR_LIT>':<EOL><INDENT>alpha = t<EOL><DEDENT>else:<EOL><INDENT>alpha = self.mu<EOL><DEDENT>if tips is None:<EOL><INDENT>dM_param = broadcastMatrixMultiply(self.Prxy, Mt, alpha=alpha)<EOL><DEDENT>else:<EOL><INDENT>dM_param = broadcastMatrixVectorMultiply(self.Prxy, Mt, alpha=alpha)<EOL>if gaps is not None:<EOL><INDENT>dM_param[gaps] = scipy.zeros(N_CODON, dtype='<STR_LIT:float>')<EOL><DEDENT><DEDENT>return dM_param<EOL><DEDENT>paramval = getattr(self, param)<EOL>if isinstance(paramval, float):<EOL><INDENT>paramisvec = False<EOL><DEDENT>else:<EOL><INDENT>assert isinstance(paramval, numpy.ndarray) and paramval.ndim == <NUM_LIT:1><EOL>paramisvec = True<EOL>paramlength = paramval.shape[<NUM_LIT:0>]<EOL><DEDENT>if ('<STR_LIT>', t) not in self._cached:<EOL><INDENT>self._cached[('<STR_LIT>', t)] = scipy.exp(self.D * self.mu * t)<EOL><DEDENT>expD = self._cached[('<STR_LIT>', t)]<EOL>if ('<STR_LIT>', t) not in self._cached:<EOL><INDENT>if '<STR_LIT>' not in self._cached:<EOL><INDENT>Dyy = scipy.tile(self.D, (<NUM_LIT:1>, N_CODON)).reshape(<EOL>self.nsites, N_CODON, N_CODON)<EOL>Dxx = scipy.array([Dyy[r].transpose() for r in<EOL>range(self.nsites)])<EOL>self._cached['<STR_LIT>'] = Dxx - Dyy<EOL><DEDENT>Dxx_Dyy = self._cached['<STR_LIT>']<EOL>if '<STR_LIT>' not in self._cached:<EOL><INDENT>self._cached['<STR_LIT>'] = scipy.fabs(<EOL>Dxx_Dyy) < ALMOST_ZERO<EOL><DEDENT>Dxx_Dyy_lt_ALMOST_ZERO = self._cached['<STR_LIT>']<EOL>with scipy.errstate(divide='<STR_LIT>', under='<STR_LIT:ignore>',<EOL>over='<STR_LIT>', invalid='<STR_LIT:ignore>'):<EOL><INDENT>expDyy = scipy.tile(expD,(<NUM_LIT:1>, N_CODON)).reshape(<EOL>self.nsites, N_CODON, N_CODON)<EOL>expDxx = scipy.array([expDyy[r].transpose() for r in<EOL>range(self.nsites)])<EOL>V = (expDxx - expDyy) / Dxx_Dyy<EOL><DEDENT>with scipy.errstate(under='<STR_LIT:ignore>'): <EOL><INDENT>scipy.copyto(V, self.mu * t * expDxx, where=<EOL>Dxx_Dyy_lt_ALMOST_ZERO)<EOL><DEDENT>self._cached[('<STR_LIT>', t)] = V<EOL><DEDENT>V = self._cached[('<STR_LIT>', t)]<EOL>with scipy.errstate(under='<STR_LIT:ignore>'): <EOL><INDENT>if tips is None:<EOL><INDENT>if not paramisvec:<EOL><INDENT>dM_param = broadcastMatrixMultiply(self.A,<EOL>broadcastMatrixMultiply(self.B[param]<EOL>* V, self.Ainv))<EOL><DEDENT>else:<EOL><INDENT>dM_param = scipy.ndarray((paramlength, self.nsites,<EOL>N_CODON, N_CODON), dtype='<STR_LIT:float>')<EOL>for j in range(paramlength):<EOL><INDENT>dM_param[j] = broadcastMatrixMultiply(self.A,<EOL>broadcastMatrixMultiply(self.B[param][j]<EOL>* V, self.Ainv))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if not paramisvec:<EOL><INDENT>dM_param = broadcastMatrixVectorMultiply(self.A,<EOL>broadcastGetCols(broadcastMatrixMultiply(<EOL>self.B[param] * V, self.Ainv), tips))<EOL><DEDENT>else:<EOL><INDENT>dM_param = scipy.ndarray((paramlength, self.nsites,<EOL>N_CODON), dtype='<STR_LIT:float>')<EOL>for j in range(paramlength):<EOL><INDENT>dM_param[j] = broadcastMatrixVectorMultiply(self.A,<EOL>broadcastGetCols(broadcastMatrixMultiply(<EOL>self.B[param][j] * V, self.Ainv), tips))<EOL><DEDENT><DEDENT>if gaps is not None:<EOL><INDENT>if not paramisvec:<EOL><INDENT>dM_param[gaps] = scipy.zeros(N_CODON, dtype='<STR_LIT:float>')<EOL><DEDENT>else:<EOL><INDENT>dM_param[:, gaps] = scipy.zeros(N_CODON, dtype='<STR_LIT:float>')<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return dM_param<EOL>
See docs for method in `Model` abstract base class.