示例#1
0
    def testNormalizeHardcoded(self):
        v1 = 1/2.**(1./2)*np.array([[1., 1., 0.]])
        v2 = normalize(v1)
        self.assertTrue(is_float_equal(v1[0, :], v2[0, :]))

        v3 = normalize(np.array([[5., 0., 0.]]))
        v4 = np.array([[1., 0., 0.]])
        self.assertTrue(is_float_equal(v3[0, :], v4[0, :]))
示例#2
0
    def testComplexEquality(self):
        "Test floating-point equality of complex vectors."

        v = self.v
        v_perturb = self.v + 1e-8*self.w_complex

        self.assertTrue(is_float_equal(v, v_perturb, tol=1e-6))
        self.assertFalse(is_float_equal(v, v_perturb, tol=1e-9))        
示例#3
0
    def testRealEquality(self):
        "Test floating-point equality of real vectors."

        v = self.v
        v_perturb = self.v + 1e-8*(self.w_real + 1)

        self.assertTrue(is_float_equal(v, v))
        self.assertTrue(is_float_equal(v, v_perturb)) 
        self.assertFalse(is_float_equal(v, v_perturb, tol=1e-10))
        self.assertFalse(is_float_equal(v, v + 1))
示例#4
0
 def testHamiltonian(self):
     from continuous_vortex_system import scaled_gradient_hamiltonian
     scaled_grad = scaled_gradient_hamiltonian(self.gamma, self.x0, 
                                               self.sigma)
     
     grad2 = row_product(self.gamma, scaled_grad) 
     self.assertTrue(is_float_equal(grad2, self.grad, tol=1e-14))
    def testInverse(self):
        """Check that Hopf map composed with its inverse yield the identity."""

        # Hopf composed with the inverse should give the identity exactly
        X1 = hopf(inverse_hopf(self.X)) 
        self.assertTrue(is_float_equal(X1, self.X))

        # Inverse hopf composed with Hopf gives the identity up to phase
        psi1 = inverse_hopf(hopf(self.psi))
        phases = psi1/self.psi

        # Test whether columns of phase matrix are equal
        self.assertTrue(is_float_equal(phases[:, 0], phases[:, 1]))
        # Test whether column elements have unit norm
        p = phases[:, 0]
        self.assertTrue(is_float_equal(p*p.conjugate(), np.ones(self.N)))
示例#6
0
 def testNormalizeReal(self):
     X_normalized = normalize(self.X)
     
     for i in xrange(0, self.N):
         row = self.X[i, :]
         row /= np.linalg.norm(row)
         self.assertTrue(is_float_equal(row, X_normalized[i,:]))
示例#7
0
 def testNormalizeComplex(self):
     psi_normalized = normalize(self.psi)
     
     for i in xrange(0, self.N):
         row = self.psi[i, :]
         row /= np.linalg.norm(row)
         self.assertTrue(is_float_equal(row, psi_normalized[i,:]))
    def testPhase(self):
        """Check that the Hopf map is invariant under multiplication 
        by a random phase."""

        X = hopf(self.psi)

        theta = random_vector(self.N) # Column vector of phases
        phase = hstack(np.exp(1j*theta), 2)

        self.assertTrue(is_float_equal(X, hopf(phase*self.psi)))
示例#9
0
    def testResidueDirect(self):
        from vortex_integrator import iteration_direct, VortexSystem

        v = VortexSystem()
        v.h = self.h 
        v.gamma = self.gamma
        v.sigma = self.sigma

        r = iteration_direct(self.b, self.x0, v)
        r = 2*row_product(self.gamma, self.b - r)
        self.assertTrue(is_float_equal(r, self.res_direct, tol=1e-14))
示例#10
0
    def testCayleyKlein(self):
        """Test whether generic Cayley and Cayley-Klein agree on su(2)."""

        N = 16
        a = random_array((N, 3))
        A = hatmap(a)
     
        U1 = cayley(A)
        U2 = cayley_klein(a)

        self.assertTrue(is_float_equal(U1, U2))
示例#11
0
    def testInverseHatmap(self):
        """Test whether composition of hatmap and its inverse
        give the identity."""

        self.assertTrue(is_float_equal(inverse_hatmap(self.A), self.a))