def test_non_square_input(self): with self.assertRaises(ValueError): fwdpy11.MigrationMatrix(np.array([2.] * 2)) with self.assertRaises(ValueError): """ This matrix is also invalid b/c rows don't sum to 1, but we expect a failure before that check """ fwdpy11.MigrationMatrix( np.array([i for i in range(6)]).reshape(2, 3))
def testSettingRates(self): m = fwdpy11.MigrationMatrix(np.identity(2)) m._set_migration_rates(0, [0.5, 0.5]) m._set_migration_rates(1, np.array([0.01, 0.99])) self.assertTrue( np.array_equal(m.M, np.array([0.5, 0.5, 0.01, 0.99]).reshape(2, 2))) m._set_migration_rates(np.array([0, 1, 2, 3]).reshape(2, 2)) try: m._set_migration_rates(0, [2.5, 0.5]) except: # NOQA self.fail("unexpected exception") with self.assertRaises(ValueError): # Fails because deme index out of range m._set_migration_rates(2, [0.5, 0.5])
def test_weights_greater_than_one(self): try: fwdpy11.MigrationMatrix(np.array([2.] * 4).reshape(2, 2)) except: # NOQA self.fail("unexpected exception")
def testPickle(self): m = fwdpy11.MigrationMatrix(np.identity(2)) p = pickle.dumps(m, -1) up = pickle.loads(p) self.assertEqual(up.shape, (2, 2)) self.assertTrue(np.array_equal(up.M, np.identity(2)))
def testShape(self): m = fwdpy11.MigrationMatrix(np.identity(2)) self.assertEqual(m.shape, (2, 2))
def testSimpleInit(self): fwdpy11.MigrationMatrix(np.identity(2))