Example #1
0
 def get_view(self):
     if self.view is None:
         self.v = m.cross(self.w, self.u)
         self.view = [[self.u[0], self.v[0], self.w[0], 0.0],
                      [self.u[1], self.v[1], self.w[1], 0.0],
                      [self.u[2], self.v[2], self.w[2], 0.0],
                      [
                          -m.dot(self.u, self.position),
                          -m.dot(self.v, self.position),
                          -m.dot(self.w, self.position), 1.0
                      ]]
     return to_tuple(self.view)
Example #2
0
 def find_leaf(self):
     index = 0
     while index > -1:
         node = self.nodes[index]
         plane = self.planes[node.plane]
         distance = mymath.dot(plane.normal,
                               self.camera.position) - plane.dist
         if distance >= 0:
             index = node.children[0]
         else:
             index = node.children[1]
     return self.leafs[-(index + 1)]
Example #3
0
    def test_known2x2(self):
        # expected to fail because upsampled_idft2 doesn't handle the nyquist
        # component properly
        A = array([[1, 4], [0, 2]])
        AA = fft2(A)
        known_out = array([[4, 2.5], [3, 1.75]])
        out = mm.upsampled_idft2(AA, 2, 2, 2, 0, 2)
        self.assertArraysClose(known_out, out)

        # code comparing the ideal fourier matrix approach with proper
        # zero-padding, to the idft_upsampled
        AAA = zpadf(AA, (2, 2))
        F = array([[1, 1, 1, 1],[1, 1j, -1, -1j],[1,-1,1,-1],[1,-1j,-1,1j]])/4.0
        out2 = mm.dot(F, AAA, F)*4.0
        out = mm.upsampled_idft2(AA, 2, 4, 4, 0, 0)
Example #4
0
    def test_simple(self):
        """
        Fourier transforms can be accomplished using matrices.

        You need two of them (one for each dimension).

        This test is a simple sanity check.
        """

        a = fft2(
            array([[0, 2, 2, 0], [0, 2, 2, 2], [0, 0, 0, 2], [10, 0, 0, 2]]))
        ny, nx = a.shape

        F = array([[1, 1, 1, 1], [1, 1j, -1, -1j], [1, -1, 1, -1],
                   [1, -1j, -1, 1j]])
        self.assertArraysClose(ifft2(a), mm.dot(F, a, F) / nx / ny)
Example #5
0
    def test_known2x2(self):
        # expected to fail because upsampled_idft2 doesn't handle the nyquist
        # component properly
        A = array([[1, 4], [0, 2]])
        AA = fft2(A)
        known_out = array([[4, 2.5], [3, 1.75]])
        out = mm.upsampled_idft2(AA, 2, 2, 2, 0, 2)
        self.assertArraysClose(known_out, out)

        # code comparing the ideal fourier matrix approach with proper
        # zero-padding, to the idft_upsampled
        AAA = zpadf(AA, (2, 2))
        F = array([[1, 1, 1, 1], [1, 1j, -1, -1j], [1, -1, 1, -1],
                   [1, -1j, -1, 1j]]) / 4.0
        out2 = mm.dot(F, AAA, F) * 4.0
        out = mm.upsampled_idft2(AA, 2, 4, 4, 0, 0)
Example #6
0
    def test_simple(self):
        """
        Fourier transforms can be accomplished using matrices.

        You need two of them (one for each dimension).

        This test is a simple sanity check.
        """

        a = fft2(array([[0, 2, 2, 0],
                        [0, 2, 2, 2],
                        [0, 0, 0, 2],
                        [10, 0, 0, 2]]))
        ny, nx = a.shape

        F = array([[1, 1, 1, 1],
                   [1, 1j, -1, -1j],
                   [1, -1, 1, -1],
                   [1, -1j, -1, 1j]])
        self.assertArraysClose(ifft2(a), mm.dot(F, a, F)/nx/ny)
Example #7
0
def network_error(activation, desired):
    diff = mymath.vec_subtract(desired, activation)
    return mymath.dot(diff, diff)