コード例 #1
0
    def _check_fullresults(self):
        f = z5py.File(self.input_path)
        ds_inp = f[self.input_key]
        ds_inp.n_threads = 8
        ds_ws = f[self.ws_key]
        ds_ws.n_threads = 8

        seg = ds_ws[:]
        rag = nrag.gridRag(seg, numberOfLabels=int(seg.max()) + 1)
        inp = ds_inp[:]

        # compute nifty features
        features_nifty = nrag.accumulateEdgeStandartFeatures(rag, inp, 0., 1.)
        # load features
        features = z5py.File(self.output_path)[self.output_key][:]
        self.assertEqual(len(features_nifty), len(features))
        self.assertEqual(features_nifty.shape[1], features.shape[1] - 1)

        # we can only assert equality for mean, std, min, max and len
        print(features_nifty[:10, 0])
        print(features[:10, 0])
        # -> mean
        self.assertTrue(np.allclose(features_nifty[:, 0], features[:, 0]))
        # -> std
        self.assertTrue(np.allclose(features_nifty[:, 1], features[:, 1]))
        # -> min
        self.assertTrue(np.allclose(features_nifty[:, 2], features[:, 2]))
        # -> max
        self.assertTrue(np.allclose(features_nifty[:, 8], features[:, 8]))
        self.assertFalse(np.allcose(features[:, 3:8], 0))
        # check that the edge-lens agree
        len_nifty = nrag.accumulateEdgeMeanAndLength(rag, inp)[:, 1]
        self.assertTrue(np.allclose(len_nifty, features_block[:, -1]))
コード例 #2
0
ファイル: test_scattering.py プロジェクト: gharib85/babusca
def test_noninteracting_dimer_eigenenergies():
    """Test"""
    m = scat.Model([0] * 2, [[0, 1, 1.1]], [0] * 2)
    channels = [
        scat.Channel(site=0, strength=1),
        scat.Channel(site=1, strength=1),
    ]
    sp = scat.Setup(m, channels)

    E1, _, _ = sp.eigenbasis(1)
    E2, _, _ = sp.eigenbasis(2)

    E12 = np.zeros((len(E2), ), dtype=np.complex128)
    for i in xrange(len(E1)):
        for j in xrange(len(E1)):
            E12[i + j] = E1[i] + E1[j]

    E12 = E12[np.argsort(np.real(E12))]
    E2 = E2[np.argsort(np.real(E2))]

    assert np.allcose(E2, E12), \
        'Non-interacting dimer, single particle energies do not coincide with the two-particle energies.'
コード例 #3
0
print "Number of cores per multiprocessor:", cores_per_multiprocessor
total_cores = cores_per_multiprocessor * my_gpu.MULTIPROCESSOR_COUNT
print "Number of cores on GPU:", total_cores

print np.sin, "is of type", type(np.sin)
print np.add, "is of type", type(np.add)


@numba.vectorize(['float32(float32, float32)', 'float64(float64, float64)'],
                 target='cpu')
def cpu_sincos(x, y):
    return math.sin(x) * math.cos(y)


@numbapro.vectorize(['float32(float32, float32)', 'float64(float64, float64)'],
                    target='gpu')
def gpu_sincos(x, y):
    return math.sin(x) * math.cos(y)


n = 1000000
x = np.linspace(0, np.pi, n)
y = np.linspace(0, np.pi, n)

np_ans = np.sin(x) * np.cos(y)
nb_cpu_ans = cpu_sincos(x, y)
nb_gpu_ans = gpu_sincos(x, y)

print "CPU: ", np.allclose(nb_cpu_ans, np_ans)
print "GPU: ", np.allcose(nb_gpu_ans, np_ans)