def test_joinHopMax_initial(self) : np_assert_equal( mergeHopMax( np.array([ 0., 0.]), np.array([ None, None]), np.array([ 3., 7.]), np.array([10,20]), ),( np.array([ 3., 7.]), np.array([10,20]), ))
def test_c_to_python_and_back(Class): """ checks module object can be changed and subclassed from C """ import gc from nose.tools import assert_is, assert_is_not, assert_equal from numpy.testing import assert_allclose, assert_equal as np_assert_equal from numpy import all, abs from pylada.crystal.cppwrappers import Atom from pylada.crystal.tests.atom_self import get_static_object, set_static_object, _atom a = Class(0.3,0.1,0.2, 'Au') set_static_object(a) c = get_static_object(); assert_is(c, a) assert_is(c.__class__, Class) assert_allclose(a.pos, [0.3, 0.1, 0.2]) assert_equal(a.type, 'Au') # checks same as above but with deletion. a = Class(0.4,0.1,0.2, 'Au', 'Pd', m=5) set_static_object(a) del a; del c; gc.collect() c = get_static_object(); assert_is(c.__class__, Class) assert_allclose(c.pos, [0.4, 0.1, 0.2]) np_assert_equal(c.type, ['Au', 'Pd']) assert_equal(c.__dict__, {'m': 5})
def test_joinHopMax(self) : np_assert_equal( mergeHopMax( np.array([ 5., 5.]), np.array([ 1, 2]), np.array([ 3., 7.]), np.array([10,20]), ),( np.array([ 5., 7.]), np.array([ 1,20]), ))
def test_joinHopMax_nan_after(self) : nan = np.NaN np_assert_equal( mergeHopMax( np.array([ 3., nan]), np.array([1,2]), np.array([ 5., 5.]), np.array([ 10, 20]), ),( np.array([ 5., nan]), np.array([10,2]), ))
def test_joinHopMax_isInPlace(self) : old, oldPos = np.array([ 5., 5.]), np.array([ 1, 2]), new, newPos = np.array([ 3., 7.]), np.array([10,20]), mergeHopMax(old, oldPos, new, newPos) np_assert_equal( (old, oldPos),( np.array([ 5., 7.]), np.array([ 1,20]), ))
def test_branch_order(): np_assert_equal( Incidence(n).get_index('branch'), network_flow(n, snapshots=n.snapshots[0]).get_index('branch')) pbc = n.passive_branch_components np_assert_equal( Incidence(n, branch_components=pbc).get_index('branch'), network_flow(n, snapshots=n.snapshots[0], branch_components=pbc).get_index('branch'))
def test_hopMax_boolean(self) : a1 = np.array([ [ False, False], [ True, False], [ False, False], [ False, False], [ False, False], ]) max, maxarg = hopMax(a1) np_assert_equal( max, np.array([True,False]) ) np_assert_equal( maxarg, np.array([1,0]) )
def test_hopMax_withOffset(self) : a1 = np.array([ [ 1, 1], [10, 1], [ 1, 1], [ 1,30], [ 1, 1], ]) max, maxarg = hopMax(a1, 100) np_assert_equal( max, np.array([10.,30.]) ) np_assert_equal( maxarg, np.array([101,103]) )
def test_hopMax_negative(self) : a1 = np.array([ [ 1, 1], [-10, 1], [ 1, 1], [ 1,30], [ 1, 1], ]) max, maxarg = hopMax(a1) np_assert_equal( max, np.array([10.,30.]) ) np_assert_equal( maxarg, np.array([1,3]) )
def test_hopMax_nan(self) : nan=np.NaN a1 = np.array([ [ 1, 1], [nan, 1], [ 1, 1], [ 1,30], [ 1, 1], ]) max, maxarg = hopMax(a1) np_assert_equal( max, np.array([nan,30.]) ) np_assert_equal( maxarg, np.array([1,3]) )
def test_hopMax_inf(self) : inf=np.inf a1 = np.array([ [ 1, 1], [-inf, 1], [ 1, 1], [ 1,30], [ 1, 1], [ 1, 1], ]) max, maxarg = hopMax(a1) np_assert_equal( max, np.array([inf,30.]) ) np_assert_equal( maxarg, np.array([1,3]) )
def test_multiple_diatomic_subshell_terms(): mult_1s2 = multiple_subshell_terms('diatomic', (1, 0, 2)) assert_equal(mult_1s2.max_mult, 1) assert_equal(mult_1s2.max_am, 0) np_assert_equal(mult_1s2.table, [[1]]) np_assert_equal(mult_1s2.table, [[1]]) mult_1s1_1p2_3d3 = multiple_subshell_terms('diatomic', (1, 0, 1), (2, 1, 2), (3, 2, 3)) assert_equal(mult_1s1_1p2_3d3.max_mult, 5) assert_equal(mult_1s1_1p2_3d3.max_am, 4) table = [[4, 0, 6, 0, 2], [2, 0, 4, 0, 1], [0, 0, 1, 0, 0]] np_assert_equal(mult_1s1_1p2_3d3.table, table) cleaned = [[2, 0, 2, 0, 1], [2, 0, 3, 0, 1], [0, 0, 1, 0, 0]] np_assert_equal(mult_1s1_1p2_3d3.cleaned().table, cleaned)
def test_multiple_atomic_subshell_terms(): mult_1s2 = multiple_subshell_terms('atomic', (1, 0, 2)) assert_equal(mult_1s2.max_mult, 1) assert_equal(mult_1s2.max_am, 0) np_assert_equal(mult_1s2.table, [[1]]) np_assert_equal(mult_1s2.table, [[1]]) mult_1s1_2s1_3s2 = multiple_subshell_terms('atomic', (1, 0, 1), (2, 0, 1), (3, 0, 2)) assert_equal(mult_1s1_2s1_3s2.max_mult, 3) assert_equal(mult_1s1_2s1_3s2.max_am, 0) table = [[2], [1]] np_assert_equal(mult_1s1_2s1_3s2.table, table) cleaned = [[1], [1]] np_assert_equal(mult_1s1_2s1_3s2.cleaned().table, cleaned)
def test_q2bg(): # Conversion of q vector to b value and unit vector for pos in range(3): q_vec = np.zeros((3,)) q_vec[pos] = 10. np_assert_equal(q2bg(q_vec), (10, q_vec / 10.)) # Also - check array-like q_vec = [0, 1e-6, 0] np_assert_equal(q2bg(q_vec), (0, 0)) q_vec = [0, 1e-4, 0] b, g = q2bg(q_vec) assert_array_almost_equal(b, 1e-4) assert_array_almost_equal(g, [0, 1, 0]) np_assert_equal(q2bg(q_vec, tol=5e-4), (0, 0))
def test_q2bg(): # Conversion of q vector to b value and unit vector for pos in range(3): q_vec = np.zeros((3, )) q_vec[pos] = 10. np_assert_equal(q2bg(q_vec), (10, q_vec / 10.)) # Also - check array-like q_vec = [0, 1e-6, 0] np_assert_equal(q2bg(q_vec), (0, 0)) q_vec = [0, 1e-4, 0] b, g = q2bg(q_vec) assert_array_almost_equal(b, 1e-4) assert_array_almost_equal(g, [0, 1, 0]) np_assert_equal(q2bg(q_vec, tol=5e-4), (0, 0))
def test_atomic_terms_table(): a = AtomicTermTable(2, 1) a.set(1, 1, 5) assert_equal(a.get(1, 1), 5) s2_table = AtomicTermTable(1, 0) s2_table.set(1, 0, 1) s2_terms = subshell_terms('atomic', 1, 0, 2) assert_equal(s2_terms, s2_table) np_assert_equal(s2_terms.cleaned().table, [[1]]) p2_terms = subshell_terms('atomic', 2, 1, 2) p2_table = np.array([[3, 2, 1], [1, 1, 0]]) np_assert_equal(p2_terms.table, p2_table) np_assert_equal(p2_terms.cleaned().table, [[1, 0, 1], [0, 1, 0]])
def test_loadAudio_nearleft(self) : db = HrtfDatabase('testhrtf/db.hrtfs') np_assert_equal( self._audioLeft, db.hrtf(0,91))
def test_diatomic_term_table(): d = DiatomicTermTable(2, 1) d.set(1, 1, 5) assert_equal(d.get(1, 1), 5) pi2_terms = subshell_terms('diatomic', 1, 1, 2) np_assert_equal(pi2_terms.cleaned().table, [[1, 0, 1], [1, 0, 0]])
def _test(self) : components = np.arange(1,36+1, dtype=np.float32).reshape(6,6) surface = synthesizeSH(components, nelevations=5, nazimuths=10) print surface result = analyzeSH(surface) np_assert_equal(result, components)
def test_synthesize_continuous(self) : components = np.zeros((6,6), dtype=np.float32) components[shi(0, 0)] = 1 surface = synthesizeSH(components, nelevations=5, nazimuths=8) np_assert_equal(np.ones((5,8)), surface)