Ejemplo n.º 1
0
def test_unsorted_coordinates(format, indices, vals, permutation):
    data = [
        ((0, 0), 6),
        ((0, 2), 9),
        ((0, 3), 8),
        ((2, 0), 5),
        ((2, 3), 7),
    ]

    permutated_data = [data[i] for i in permutation]
    coordinates, values = zip(*permutated_data)

    A = Tensor.from_aos(coordinates, values, dimensions=(3, 4), format=format)

    assert A.taco_indices == indices
    assert A.taco_vals == vals

    A = Tensor.from_soa(zip(*coordinates),
                        values,
                        dimensions=(3, 4),
                        format=format)

    assert A.taco_indices == indices
    assert A.taco_vals == vals

    A = Tensor.from_dok(dict(permutated_data),
                        dimensions=(3, 4),
                        format=format)

    assert A.taco_indices == indices
    assert A.taco_vals == vals
Ejemplo n.º 2
0
def test_from_soa():
    format = Format((Mode.dense, Mode.compressed, Mode.compressed), (0, 1, 2))
    x = Tensor.from_soa(
        ([0, 1, 1, 0], [0, 0, 1, 1], [0, 1, 2, 1]),
        [4.5, 3.2, -3.0, 5.0],
        dimensions=(2, 3, 3),
        format=format,
    )

    assert x.order == 3
    assert x.dimensions == (2, 3, 3)
    assert x.modes == (Mode.dense, Mode.compressed, Mode.compressed)
    assert x.mode_ordering == (0, 1, 2)
    assert x.format == format
    assert x.to_dok() == {
        (0, 0, 0): 4.5,
        (1, 0, 1): 3.2,
        (1, 1, 2): -3.0,
        (0, 1, 1): 5.0,
    }