示例#1
0
def generate_layers():
    neurons = Path('./neuron1024')
    for i in range(nneurons):
        l = Path('./neuron1024/n1024-l{}.tsv'.format(str(i + 1)))
        with l.open() as f:
            print('loading layer: ', i + 1)
            yield Matrix.from_tsv(f, lib.GrB_FP32, nneurons, nneurons)
示例#2
0
def load_images():
    images = Path('sparse-images-1024.tsv')

    with images.open() as i:
        print('loading images.')
        Y0 = Matrix.from_tsv(i, lib.GrB_FP32, nfeatures, nneurons)
    return Y0
示例#3
0
def test_matrix_tsv_read(tmp_path):
    mmf = tmp_path / 'tsv_test.mm'
    mmf.touch()
    with mmf.open('w') as f:
        f.writelines(['3\t3\t3\n', '1\t1\t2\n', '2\t2\t3\n', '3\t3\t4\n'])

    with mmf.open() as f:
        n = Matrix.from_tsv(f, int, 3, 3)
    assert n.to_lists() == [[0, 1, 2], [0, 1, 2], [2, 3, 4]]
示例#4
0
def load_layer(neurons, dest, i):
    fname = "{}/neuron{}/n{}-l{}.{}"
    binfile = fname.format(dest, neurons, neurons, str(i + 1), "ssb")
    if Path(binfile).exists():
        return Matrix.from_binfile(binfile.encode("ascii"))
    l = Path(fname.format(dest, neurons, neurons, str(i + 1), "tsv"))
    with l.open() as f:
        m = Matrix.from_tsv(f, FP32, neurons, neurons)
        m.to_binfile(binfile.encode("ascii"))
        return m
示例#5
0
def load_images(neurons, dest):
    fname = "{}/sparse-images-{}.{}"
    binfile = fname.format(dest, neurons, "ssb")
    if Path(binfile).exists():
        return Matrix.from_binfile(binfile.encode("ascii"))
    images = Path(fname.format(dest, neurons, "tsv"))
    with images.open() as i:
        m = Matrix.from_tsv(i, FP32, NFEATURES, neurons)
        m.to_binfile(binfile.encode("ascii"))
        return m
示例#6
0
def load_layer(i, dest):
    l = Path('{}/neuron{}/n{}-l{}.tsv'.format(dest, neurons, neurons, str(i+1)))
    with l.open() as f:
        return Matrix.from_tsv(f, lib.GrB_FP32, neurons, neurons)
示例#7
0
def load_images(neurons, dest):
    images = Path('{}/sparse-images-{}.tsv'.format(dest, neurons))
    with images.open() as i:
        return Matrix.from_tsv(i, lib.GrB_FP32, NFEATURES, neurons)