# Path: phydmslib/constants.py
# N_CODON = len(CODON_TO_INDEX)
# 
# N_NT = len(INDEX_TO_NT)
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# N_AA = len(INDEX_TO_AA)
# 
# CODON_NT_COUNT = numpy.zeros((N_NT, N_CODON), dtype='int')


import random
import unittest
import scipy.linalg
import scipy.optimize
import numpy
import phydmslib.models
from phydmslib.constants import (N_CODON, N_NT, AA_TO_INDEX, N_AA,
                                 CODON_NT_COUNT)

        def func_dQxy(beta, expcm, x, y):
            expcm.updateParams({"beta": beta[0]})
            return expcm.dQxy_dbeta[x][y]

        for x in random.sample(range(N_CODON), 3):
            for y in range(N_CODON):
                diff = scipy.optimize.check_grad(
                    func_Qxy,
                    func_dQxy,
                    [self.model.beta],
                    self.model,
                    x,
                    y,
                    epsilon=1e-4,
                )
                self.assertTrue(
                    diff < 1e-4,
                    "dQxy_dbeta diff {0} for x = {1}, y = {2}"
                    .format(diff, x, y))
        # back to original value
        self.model.updateParams(self.params)

    def check_ExpCM_attributes(self):
        """Make sure has the expected attribute values."""
        self.assertEqual(self.nsites, self.model.nsites)

        # make sure Prxy has rows summing to zero
        self.assertFalse(numpy.isnan(self.model.Prxy).any())
        self.assertFalse(numpy.isinf(self.model.Prxy).any())

# Path: phydmslib/constants.py
# N_CODON = len(CODON_TO_INDEX)
# 
# N_NT = len(INDEX_TO_NT)
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# N_AA = len(INDEX_TO_AA)
# 
# CODON_NT_COUNT = numpy.zeros((N_NT, N_CODON), dtype='int')


# Path: tests/test_expcm_divpressure.py
import random
import unittest
import scipy.linalg
import scipy.optimize
import numpy
import phydmslib.models
from phydmslib.constants import (N_CODON, N_NT, AA_TO_INDEX, N_AA,
                                 CODON_NT_COUNT)


        def func_dQxy(beta, expcm, x, y):
            expcm.updateParams({"beta": beta[0]})
            return expcm.dQxy_dbeta[x][y]

        for x in random.sample(range(N_CODON), 3):
            for y in range(N_CODON):
                diff = scipy.optimize.check_grad(
                    func_Qxy,
                    func_dQxy,
                    [self.model.beta],
                    self.model,
                    x,
                    y,
                    epsilon=1e-4,
                )
                self.assertTrue(
                    diff < 1e-4,
                    "dQxy_dbeta diff {0} for x = {1}, y = {2}"
                    .format(diff, x, y))
        # back to original value
        self.model.updateParams(self.params)

    def check_ExpCM_attributes(self):
        """Make sure has the expected attribute values."""
        self.assertEqual(self.nsites, self.model.nsites)

        # make sure Prxy has rows summing to zero
        self.assertFalse(numpy.isnan(self.model.Prxy).any())
        self.assertFalse(numpy.isinf(self.model.Prxy).any())

        diag = numpy.eye(N_CODON, dtype="bool")