Python numpy.testing.assert_approx_equal() Examples

The following are code examples for showing how to use numpy.testing.assert_approx_equal(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: osqp-python   Author: oxfordcontrol   File: non_convex_test.py    Apache License 2.0 5 votes vote down vote up
def test_non_convex_big_sigma(self):
        # Setup workspace with new sigma
        opts = {'verbose': False, 'sigma': 5}
        self.model.setup(P=self.P, q=self.q, A=self.A, l=self.l, u=self.u, **opts)

        # Solve problem
        res = self.model.solve()

        # Assert close
        self.assertEqual(res.info.status_val, constant('OSQP_NON_CVX'))
        nptest.assert_approx_equal(res.info.obj_val, np.nan) 
Example 2
Project: osqp-python   Author: oxfordcontrol   File: non_convex_test.py    Apache License 2.0 5 votes vote down vote up
def test_nan(self):
        nptest.assert_approx_equal(constant('OSQP_NAN'), np.nan) 
Example 3
Project: mglex   Author: fungs   File: common.py    GNU General Public License v3.0 5 votes vote down vote up
def assert_probmatrix(mat):
    is_sum = mat.sum(dtype=np.float32)
    should_sum = mat.shape[0]
    assert_approx_equal(is_sum, should_sum, significant=0)
    [assert_approx_equal(rowsum, 1., significant=1) for rowsum in mat.sum(axis=1, dtype=np.float32)] 
Example 4
Project: tQuakes   Author: seap-udea   File: test_wrapper.py    GNU General Public License v2.0 5 votes vote down vote up
def test_dvnorm():
    mag = np.array([-4.0, 4, 12])
    x = np.array([1.0, np.sqrt(2.0), np.sqrt(3.0)])
    s1 = np.array([x * 10.0 ** mag[0], x]).flatten()
    s2 = np.array([x * 10.0 ** mag[1], -x]).flatten()
    s3 = np.array([[0.0, 0.0, 0.0], x * 10 ** mag[2]]).flatten()
    npt.assert_approx_equal(spice.dvnorm(s1), 2.4494897)
    npt.assert_approx_equal(spice.dvnorm(s2), -2.4494897)
    npt.assert_approx_equal(spice.dvnorm(s3), 0.0) 
Example 5
Project: tQuakes   Author: seap-udea   File: test_wrapper.py    GNU General Public License v2.0 5 votes vote down vote up
def test_dvsep():
    spice.kclear()
    spice.furnsh(_testKernelPath)
    et = spice.str2et('JAN 1 2009')
    state_e, eltime = spice.spkezr('EARTH', et, 'J2000', 'NONE', 'SUN')
    state_m, mltime = spice.spkezr('MOON', et, 'J2000', 'NONE', 'SUN')
    dsept = spice.dvsep(state_e, state_m)
    npt.assert_approx_equal(dsept, 3.8121194e-09)
    spice.kclear() 
Example 6
Project: tQuakes   Author: seap-udea   File: test_wrapper.py    GNU General Public License v2.0 5 votes vote down vote up
def test_raxisa():
    axis = [1.0, 2.0, 3.0]
    angle = 0.1 * spice.twopi()
    rotate_matrix = spice.axisar(axis, angle)
    axout, angout = spice.raxisa(rotate_matrix)
    expectedAngout = [0.26726124, 0.53452248, 0.80178373]
    npt.assert_approx_equal(angout, 0.62831853, significant=7)
    npt.assert_array_almost_equal(axout, expectedAngout) 
Example 7
Project: tQuakes   Author: seap-udea   File: test_wrapper.py    GNU General Public License v2.0 5 votes vote down vote up
def test_spkssb():
    spice.kclear()
    spice.furnsh(_testKernelPath)
    targ1 = 499
    epoch = 'July 4, 2003 11:00 AM PST'
    frame = 'J2000'
    targ2 = 399
    et = spice.str2et(epoch)
    state1 = spice.spkssb(targ1, et, frame)
    state2 = spice.spkssb(targ2, et, frame)
    dist = spice.vdist(state1[0:3], state2[0:3])
    npt.assert_approx_equal(dist, 80854820., significant=7)
    spice.kclear()