Exemple #1
0
    def test_fshape_scp_specific(self):
    ############################################################
        from pykeops.numpy.shape_distance import FshapeScp
        for k, t in itertools.product(['gaussian', 'cauchy'], self.type_to_test):
            # Call cuda kernel
            kgeom = k
            ksig = 'gaussian'
            ksphere = 'gaussian_oriented'

            sigma_geom = 1.0
            sigma_sig = 1.0
            sigma_sphere = np.pi / 2
            # Call cuda kernel
            my_fshape_scp = FshapeScp(kernel_geom=kgeom, kernel_sig=ksig, kernel_sphere=ksphere, dtype=t)
            gamma = my_fshape_scp(self.x.astype(t), self.y.astype(t),
                                  self.f.astype(t), self.g.astype(t),
                                  self.a.astype(t), self.b.astype(t),
                                  sigma_geom=sigma_geom, sigma_sig=sigma_sig, sigma_sphere=sigma_sphere).ravel()

            # Python version
            areaa = np.linalg.norm(self.a, axis=1)
            areab = np.linalg.norm(self.b, axis=1)

            nalpha = self.a / areaa[:, np.newaxis]
            nbeta = self.b / areab[:, np.newaxis]

            gamma_py = np.sum((areaa[:, np.newaxis] * areab[np.newaxis, :])
                              * np_kernel(self.x, self.y, sigma_geom, kgeom)
                              * np_kernel(self.f, self.g, sigma_sig, ksig)
                              * np_kernel_sphere(nalpha, nbeta, sigma_sphere, ksphere), axis=1)

            # compare output
            print("ee")
            self.assertTrue(np.allclose(gamma, gamma_py, atol=1e-6))
Exemple #2
0
sigma_sig = 1.0
sigma_sphere = np.pi / 2
kgeom = 'gaussian'
ksig = 'gaussian'
ksphere = 'gaussian_oriented'
myconv = FshapeScp(kernel_geom=kgeom, kernel_sig=ksig, kernel_sphere=ksphere)
gamma = myconv(x,
               y,
               f,
               g,
               a,
               b,
               sigma_geom=sigma_geom,
               sigma_sig=sigma_sig,
               sigma_sphere=sigma_sphere).ravel()

areaa = np.linalg.norm(a, axis=1)
areab = np.linalg.norm(b, axis=1)

nalpha = a / areaa[:, np.newaxis]
nbeta = b / areab[:, np.newaxis]

gamma_py = np.sum(
    (areaa[:, np.newaxis] * areab[np.newaxis, :]) *
    np_kernel(x, y, sigma_geom, kgeom) * np_kernel(f, g, sigma_sig, ksig) *
    np_kernel_sphere(nalpha, nbeta, sigma_sphere, ksphere),
    axis=1)

# compare output
print(np.allclose(gamma, gamma_py, atol=1e-6))