Exemple #1
0
def test_slicing(fargs_tests):
    dims, dtype = fargs_tests

    gpu = NervanaGPU(default_dtype=dtype)
    cpu = NervanaCPU(default_dtype=dtype)

    array_np = np.random.uniform(-1, 1, dims).astype(dtype)
    array_ng = gpu.array(array_np, dtype=dtype)
    array_nc = cpu.array(array_np, dtype=dtype)

    assert_tensors_allclose(array_ng[0], array_nc[0], rtol=0, atol=1e-3)
    assert_tensors_allclose(array_ng[-1], array_nc[-1], rtol=0, atol=1e-3)
    assert_tensors_allclose(array_ng[0, :], array_nc[0, :], rtol=0, atol=1e-3)
    assert_tensors_allclose(array_ng[0:], array_nc[0:], rtol=0, atol=1e-3)
    assert_tensors_allclose(array_ng[:-1], array_nc[:-1], rtol=0, atol=1e-3)
    assert_tensors_allclose(array_ng[:, 0], array_nc[:, 0], rtol=0, atol=1e-3)
    assert_tensors_allclose(array_ng[:, 0:1], array_nc[:, 0:1], rtol=0, atol=1e-3)
    assert_tensors_allclose(array_ng[-1, 0:], array_nc[-1:, 0:], rtol=0, atol=1e-3)

    array_ng[0] = 0
    array_nc[0] = 0

    assert_tensors_allclose(array_ng, array_nc, rtol=0, atol=1e-3)

    del(gpu)
Exemple #2
0
            if not compound:
                opts = [ dict() ]

            if ones:
                vals = 1.0
            else:
                vals = (0.5 - ng.rand()) * 2

            devI1    = ng.empty(dimI1, dtype=dtype)
            devI2    = ng.empty(dimI2, dtype=dtype)
            devO     = ng.empty(dimO,  dtype=dtype)
            devI1[:] = vals
            devI2[:] = vals
            devO[:]  = vals
            cpuI1    = nc.array(devI1.get(), dtype=np.float64)
            cpuI2    = nc.array(devI2.get(), dtype=np.float64)
            cpuO     = nc.array(devO.get(),  dtype=np.float64)

            if compound and opts is not update_opts:
                devB    = ng.empty((dimO[0], 1), dtype=np.float32)
                devS    = ng.empty((dimO[0], 1), dtype=np.float32)
                devB[:] = vals
                devS[:] = vals
                cpuB    = nc.array(devB.get(), dtype=np.float64)
                cpuS    = nc.array(devS.get(), dtype=np.float64)

            if opts is bprop_opts:
                devX    = ng.empty(dimO,  dtype=dtype)
                devX[:] = vals
                cpuX    = nc.array(devX.get(),  dtype=np.float64)
Exemple #3
0
            if not compound:
                opts = [ dict() ]

            if ones:
                vals = 1.0
            else:
                vals = (0.5 - ng.rand()) * 2

            devI1    = ng.empty(dimI1, dtype=dtype)
            devI2    = ng.empty(dimI2, dtype=dtype)
            devO     = ng.empty(dimO,  dtype=dtype)
            devI1[:] = vals
            devI2[:] = vals
            devO[:]  = vals
            cpuI1    = nc.array(devI1.get(), dtype=np.float64)
            cpuI2    = nc.array(devI2.get(), dtype=np.float64)
            cpuO     = nc.array(devO.get(),  dtype=np.float64)

            if compound and opts is not update_opts:
                devB    = ng.empty((dimO[0], 1), dtype=np.float32)
                devS    = ng.empty((dimO[0], 1), dtype=np.float32)
                devB[:] = vals
                devS[:] = vals
                cpuB    = nc.array(devB.get(), dtype=np.float64)
                cpuS    = nc.array(devS.get(), dtype=np.float64)

            if opts is bprop_opts:
                devX    = ng.empty(dimO,  dtype=dtype)
                devX[:] = vals
                cpuX    = nc.array(devX.get(),  dtype=np.float64)