Exemplo n.º 1
0
    def test_pmat_neighbors_invalid_input(self):
        np.random.seed(12)
        pmat = np.random.random_sample((20, 20))
        np.fill_diagonal(pmat, 0.5)

        # Too large filter_shape
        pmat_neigh = asset._PMatNeighbors(filter_shape=(11, 3), n_largest=3)
        self.assertRaises(ValueError, pmat_neigh.compute, pmat)
        pmat_neigh = asset._PMatNeighbors(filter_shape=(21, 3), n_largest=3)
        np.fill_diagonal(pmat, 0.0)
        self.assertRaises(ValueError, pmat_neigh.compute, pmat)
        pmat_neigh = asset._PMatNeighbors(filter_shape=(11, 3), n_largest=3,
                                          max_chunk_size=10)
        if HAVE_PYOPENCL:
            # max_chunk_size > filter_shape
            self.assertRaises(ValueError, pmat_neigh.pyopencl, pmat)
        if HAVE_CUDA:
            # max_chunk_size > filter_shape
            self.assertRaises(ValueError, pmat_neigh.pycuda, pmat)

        # Too small filter_shape
        self.assertRaises(ValueError, asset._PMatNeighbors,
                          filter_shape=(11, 3), n_largest=100)

        # w >= l
        self.assertRaises(ValueError, asset._PMatNeighbors,
                          filter_shape=(9, 9), n_largest=3)

        # not centered
        self.assertWarns(UserWarning, asset._PMatNeighbors,
                         filter_shape=(10, 6), n_largest=3)
Exemplo n.º 2
0
 def test_pmat_neighbors_gpu_overlapped_chunks(self):
     # The pmat is chunked as follows:
     #   [(0, 11), (11, 22), (22, 33), (29, 40)]
     # Two last chunks overlap.
     np.random.seed(12)
     pmat = np.random.random_sample((50, 50)).astype(np.float32)
     pmat_neigh = asset._PMatNeighbors(filter_shape=(11, 5), n_largest=3,
                                       max_chunk_size=12)
     lmat_true = pmat_neigh.cpu(pmat)
     if HAVE_PYOPENCL:
         lmat_opencl = pmat_neigh.pyopencl(pmat)
         assert_array_almost_equal(lmat_opencl, lmat_true)
     if HAVE_CUDA:
         lmat_cuda = pmat_neigh.pycuda(pmat)
         assert_array_almost_equal(lmat_cuda, lmat_true)
Exemplo n.º 3
0
 def test_pmat_neighbors_gpu_chunked(self):
     np.random.seed(12)
     filter_shape = (7, 3)
     n_largest = 3
     pmat1 = np.random.random_sample((40, 40)).astype(np.float32)
     np.fill_diagonal(pmat1, 0.5)
     pmat2 = np.random.random_sample((70, 27)).astype(np.float32)
     pmat3 = np.random.random_sample((41, 80)).astype(np.float32)
     for pmat in (pmat1, pmat2, pmat3):
         pmat_neigh = asset._PMatNeighbors(filter_shape=filter_shape,
                                           n_largest=n_largest)
         lmat_true = pmat_neigh.cpu(pmat)
         for max_chunk_size in (17, 20, 29):
             pmat_neigh.max_chunk_size = max_chunk_size
             if HAVE_PYOPENCL:
                 lmat_opencl = pmat_neigh.pyopencl(pmat)
                 assert_array_almost_equal(lmat_opencl, lmat_true)
             if HAVE_CUDA:
                 lmat_cuda = pmat_neigh.pycuda(pmat)
                 assert_array_almost_equal(lmat_cuda, lmat_true)
Exemplo n.º 4
0
 def test_pmat_neighbors_gpu(self):
     np.random.seed(12)
     n_largest = 3
     pmat1 = np.random.random_sample((40, 40)).astype(np.float32)
     np.fill_diagonal(pmat1, 0.5)
     pmat2 = np.random.random_sample((70, 23)).astype(np.float32)
     pmat3 = np.random.random_sample((27, 93)).astype(np.float32)
     for pmat in (pmat1, pmat2, pmat3):
         for filter_size in (4, 8, 11):
             filter_shape = (filter_size, 3)
             with warnings.catch_warnings():
                 # ignore even filter sizes
                 warnings.simplefilter('ignore', UserWarning)
                 pmat_neigh = asset._PMatNeighbors(
                     filter_shape=filter_shape, n_largest=n_largest)
             lmat_true = pmat_neigh.cpu(pmat)
             if HAVE_PYOPENCL:
                 lmat_opencl = pmat_neigh.pyopencl(pmat)
                 assert_array_almost_equal(lmat_opencl, lmat_true)
             if HAVE_CUDA:
                 lmat_cuda = pmat_neigh.pycuda(pmat)
                 assert_array_almost_equal(lmat_cuda, lmat_true)