Example #1
0
    def setUp(self):

        self.input = {}

        self.input["a1_M"] = Tensor.fromUncompressed(["M"],
                                                     [1, 0, 3, 0, 5, 0, 7])
        self.input["a1_m"] = self.input["a1_M"].getRoot()

        self.input["b1_M"] = Tensor.fromUncompressed(["M"], [2, 0, 4, 5])
        self.input["b1_m"] = self.input["b1_M"].getRoot()

        self.input['c1_M'] = Tensor.fromUncompressed(["M"], [1, 2, 3])
        self.input["c1_m"] = self.input["c1_M"].getRoot()

        self.input["a2_MK"] = Tensor.fromUncompressed(
            ["M", "K"], [[1, 0, 3, 0, 5, 0, 7], [2, 2, 0, 3, 0, 0, 8],
                         [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0],
                         [4, 0, 5, 0, 8, 0, 9]])

        self.input["a2_m"] = self.input["a2_MK"].getRoot()

        self.input["b2_MK"] = Tensor.fromUncompressed(
            ["M", "K"], [[2, 0, 4, 5], [0, 0, 0, 0], [3, 4, 6, 0],
                         [0, 0, 0, 0], [1, 2, 3, 4]])
        self.input["b2_m"] = self.input["b2_MK"].getRoot()
def get_A_HFA(a_file):
    # read in inputs
    # jhu_len = 5157
    shape = 500  # TODO: take this as input
    # generate input frontier and tile it
    A_data = [0] * shape

    # read in frontier
    count = 1
    A_HFA = None
    if not a_file.endswith('.yaml'):
        with open(a_file, 'r') as f:
            for line in f:
                elt = int(line)
                A_data[elt] = count
                count += 1
        A_untiled = Tensor.fromUncompressed(["S"], A_data, name="A")
        A_HFA = A_untiled.splitUniform(32, relativeCoords=True)  # split S
        print("A untiled shape {}, tiled shape {}".format(
            A_untiled.getShape(), A_HFA.getShape()))

    else:  # already in pretiled yaml
        A_HFA = Tensor.fromYAMLfile(a_file)
        A_HFA.setName("A")
    return A_HFA
Example #3
0
    def test_shape_fromUncompressed_1D(self):
        """Test shape of a tensor from 1D nested lists"""

        l1 = [100, 101, 0, 102]

        t1 = Tensor.fromUncompressed(["M"], l1)

        self.assertEqual(t1.getRankIds(), ["M"])
        self.assertEqual(t1.getShape(), [4])

        l2 = [100, 101, 0, 0]

        t2 = Tensor.fromUncompressed(["M"], l2)

        self.assertEqual(t2.getRankIds(), ["M"])
        self.assertEqual(t2.getShape(), [4])
Example #4
0
    def test_rankid_2D(self):
        """Test setting rank ids of 2D tensor"""

        #         0    1    2    3
        #
        l1 = [
            [0, 0, 0, 0],  # 0
            [100, 101, 102, 0],  # 1
            [0, 201, 0, 203],  # 2
            [0, 0, 0, 0],  # 3
            [400, 0, 402, 0],  # 4
            [0, 0, 0, 0],  # 5
            [0, 601, 0, 603]
        ]  # 6

        rank_ids = ["M", "K"]
        t1 = Tensor.fromUncompressed(rank_ids, l1)

        rank_ids2 = t1.getRankIds()

        self.assertEqual(rank_ids2, rank_ids)

        rank_ids_new = ["M2", "M1"]
        t1.setRankIds(rank_ids_new)

        rank_ids3 = t1.getRankIds()

        self.assertEqual(rank_ids3, rank_ids_new)
    def test_fromUncompressed_2D_wo_ids(self):
        """Test construction of a tensor from nested lists without ids"""

        tensor_in = Tensor.fromYAMLfile("./data/test_tensor-1.yaml")

        root = tensor_in.getRoot()
        tensor_ref = Tensor.fromFiber(["R1", "R0"], root)

        # Manual copy of test_tensor-1.yaml

        #         0    1    2    3
        #
        t = [
            [0, 0, 0, 0],  # 0
            [100, 101, 102, 0],  # 1
            [0, 201, 0, 203],  # 2
            [0, 0, 0, 0],  # 3
            [400, 0, 402, 0],  # 4
            [0, 0, 0, 0],  # 5
            [0, 601, 0, 603]
        ]  # 6

        tensor = Tensor.fromUncompressed(["R1", "R0"], t)

        self.assertEqual(tensor, tensor_ref)
def get_Z_HFA(B_shape):
    Z_data = [[0], [0]]
    Z_HFA = Tensor.fromUncompressed(["D1", "D0"],
                                    Z_data,
                                    shape=[B_shape[0], B_shape[2]],
                                    name="Z")
    return Z_HFA
    def test_fromUncompressed_20(self):
        """Test construction of a tensor a scalar"""

        t_ref = Tensor(rank_ids=[])
        p = t_ref.getRoot()
        p += 2

        t0 = Tensor.fromUncompressed([], 2)

        self.assertEqual(t0, t_ref)

        t1 = Tensor.fromUncompressed(rank_ids=[], root=2)

        self.assertEqual(t1, t_ref)

        t2 = Tensor.fromUncompressed(root=2)

        self.assertEqual(t2, t_ref)
    def test_flattenRanks_l3_sa(self):
        """Test flattenRanks - levels=3, coord_style=absolute"""
        t0 = Tensor.fromUncompressed(rank_ids=["A"], root=list(range(16)))
        s1 = t0.splitUniform(8, depth=0)
        s2 = s1.splitUniform(4, depth=1)
        s3 = s2.splitUniform(2, depth=2)

        f4 = s3.flattenRanks(levels=3, coord_style="absolute")
        f4.setRankIds(["A"])

        self.assertEqual(f4, t0)
    def test_fromUncompressed_1D(self):
        """Test construction of a tensor from nested lists"""

        tensor_ref = Tensor.fromYAMLfile("./data/test_tensor-1.yaml")

        # Manual copy of test_tensor-1.yaml

        #         0    1    2    3
        #
        t = [100, 101, 0, 102]

        fiber = Fiber([0, 1, 3], [100, 101, 102])
        tensor = Tensor.fromUncompressed(["M"], t)

        self.assertEqual(tensor.getRoot(), fiber)
    def test_fromRandom_wo_ids(self):
        """Test construction of a random tensor without rankids"""

        rank_ids = ["R1", "R0"]
        shape = [10, 10]
        tensor_ref = Tensor.fromUncompressed(
            rank_ids,
            [[0, 10, 10, 1, 0, 9, 8, 0, 0, 3], [
                9, 1, 0, 10, 1, 0, 10, 0, 0, 0
            ], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 3, 0, 3, 5, 0, 5, 7, 0, 0],
             [6, 0, 0, 0, 0, 0, 6, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
             [0, 0, 2, 8, 2, 3, 7, 0, 0, 10], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
             [0, 0, 0, 4, 0, 2, 9, 4, 0, 5], [6, 3, 0, 8, 0, 10, 0, 9, 4, 0]])

        tensor = Tensor.fromRandom(None, shape, [0.5, 0.5], 10, seed=3)

        self.assertEqual(tensor, tensor_ref)
        self.assertEqual(tensor.getRankIds(), rank_ids)
Example #11
0
    def test_shape_fromUncompressed_2D_A1(self):
        """Test shape of a tensor from 2D nested lists (tensor A)"""

        #         0    1    2    3
        #
        l1 = [
            [0, 0, 0, 0],  # 0
            [100, 101, 102, 0],  # 1
            [0, 201, 0, 203],  # 2
            [0, 0, 0, 0],  # 3
            [400, 0, 402, 0],  # 4
            [0, 0, 0, 0],  # 5
            [0, 601, 0, 603]
        ]  # 6

        t1 = Tensor.fromUncompressed(["M", "K"], l1)

        with self.subTest(test="All ranks"):
            self.assertEqual(t1.getRankIds(), ["M", "K"])
            self.assertEqual(t1.getShape(), [7, 4])

        with self.subTest(test="All ranks specified"):
            self.assertEqual(t1.getShape(["M", "K"]), [7, 4])

        with self.subTest(test="Just rank 'M' as list"):
            self.assertEqual(t1.getShape(["M"]), [7])

        with self.subTest(test="Just rank 'K' as list"):
            self.assertEqual(t1.getShape(["K"]), [4])

        with self.subTest(test="Just rank 'M'"):
            self.assertEqual(t1.getShape("M"), 7)

        with self.subTest(test="Just rank 'K'"):
            self.assertEqual(t1.getShape("K"), 4)

        with self.subTest(test="Check authoritative"):
            self.assertEqual(t1.getShape(authoritative=True), [7, 4])
            self.assertEqual(t1.getShape(["M", "K"], authoritative=True),
                             [7, 4])
            self.assertEqual(t1.getShape(["M"], authoritative=True), [7])
            self.assertEqual(t1.getShape(["K"], authoritative=True), [4])
            self.assertEqual(t1.getShape("M", authoritative=True), 7)
            self.assertEqual(t1.getShape("K", authoritative=True), 4)
Example #12
0
    def test_shape_fromUncompressed_2D_B(self):
        """Test shape of a tensor from 2D nested lists (tensor B)"""

        #         0    1    2    3
        #
        l2 = [
            [0, 0, 0, 0],  # 0
            [100, 101, 102, 0],  # 1
            [0, 201, 0, 0],  # 2
            [0, 0, 0, 0],  # 3
            [400, 0, 402, 0],  # 4
            [0, 0, 0, 0],  # 5
            [0, 601, 0, 0]
        ]  # 6

        t2 = Tensor.fromUncompressed(["M", "K"], l2)

        self.assertEqual(t2.getRankIds(), ["M", "K"])
        self.assertEqual(t2.getShape(), [7, 4])
    def test_fromUncompressed_2D(self):
        """Test construction of a tensor from nested lists"""

        tensor_ref = Tensor.fromYAMLfile("./data/test_tensor-1.yaml")

        # Manual copy of test_tensor-1.yaml

        #         0    1    2    3
        #
        t = [
            [0, 0, 0, 0],  # 0
            [100, 101, 102, 0],  # 1
            [0, 201, 0, 203],  # 2
            [0, 0, 0, 0],  # 3
            [400, 0, 402, 0],  # 4
            [0, 0, 0, 0],  # 5
            [0, 601, 0, 603]
        ]  # 6

        tensor = Tensor.fromUncompressed(["M", "K"], t)

        self.assertEqual(tensor, tensor_ref)
    def test_swizzleRanks(self):
        """ Test swizzleRanks """

        a_MK = Tensor.fromUncompressed(["M", "K"],
                               [[0, 0, 4, 0, 0, 5],
                                [3, 2, 0, 3, 0, 2],
                                [0, 2, 0, 0, 1, 2],
                                [0, 0, 0, 0, 0, 0],
                                [2, 5, 0, 0, 0, 5],
                                [4, 1, 0, 0, 0, 0],
                                [5, 0, 0, 1, 0, 0],
                                [4, 0, 0, 5, 1, 3]])

        a_KM = a_MK.swapRanks()

        M = 8
        M1 = 2
        M0 = (M+1)//M1

        K = 6
        K1 = 2
        K0 = (K+1)//K1

        a_MMKK = a_MK.splitUniform(M0).splitUniform(K0, depth=2)
        a_MKMK = a_MMKK.swapRanks(depth=1)
        a_KMMK = a_KM.splitUniform(K0).swapRanks(depth=1).splitUniform(M0, depth=1)

        a_KM_2 = a_MK.swizzleRanks(["K", "M"])
        self.assertEqual(a_KM_2, a_KM)

        a_MK_2 = a_KM_2.swizzleRanks(["M", "K"])
        self.assertEqual(a_MK_2, a_MK)

        a_MKMK_2 = a_MMKK.swizzleRanks(["M.1","K.1", "M.0", "K.0"])
        self.assertEqual(a_MKMK_2, a_MKMK)

        a_MMKK_2 = a_MKMK.swizzleRanks(["M.1", "M.0", "K.1", "K.0"])
        self.assertEqual(a_MMKK_2, a_MMKK)
Example #15
0
from fibertree import Tensor, TensorImage


a = Tensor.fromUncompressed(root=2)
print(a)

i = TensorImage(a)
i.show()
if __name__ == "__main__":

    print("a - multiple highlights")
    a = Tensor.fromYAMLfile("../../examples/data/sparse-matrix-a.yaml")
    a.setColor("blue")
    i = UncompressedImage(a, highlights={"PE": [(0, 1), (1, 2), (3, )]})
    i.show()

    #
    print("a - single highlights")
    i = UncompressedImage(a, {"PE": [(1, 2)]})
    i.show()

    #
    print("b")
    b = Tensor.fromUncompressed(["X"], [1, 2, 0, 0, 4])
    i = UncompressedImage(b, {"PE": [(1, ), (4, )]})
    i.show()

    #
    print("c")
    a_root = a.getRoot()
    c = Tensor.fromFiber(["X", "Y", "Z"],
                         Fiber([0, 1, 2],
                               [a_root, Fiber([], []), a_root]))
    i = UncompressedImage(c)
    i.show()

    #
    print("d")
    d = c.getRoot()
Example #17
0
from fibertree import Fiber, Tensor, TensorImage

x = [[[1, 2, 8, 20, 0, 0, 11], [1, 0, 0, 11, 0, 0, 33], [0, 0, 0, 0, 0, 0, 0],
      [1, 1, 8, 12, 0, 0, 44], [1, 3, 0, 13, 0, 0, 42], [0, 0, 4, 14, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0]],
     [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0]],
     [[1, 2, 8, 20, 0, 0, 11], [1, 0, 0, 11, 0, 0, 33], [0, 0, 0, 0, 0, 0, 0],
      [1, 1, 8, 12, 0, 0, 44], [1, 3, 0, 13, 0, 0, 42], [0, 0, 4, 14, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0]]]

f = Fiber.fromUncompressed(x)
f.dump("/tmp/tensor-3d.yaml")
f.print("Fiber from uncompressed")

t1 = Tensor.fromFiber(["X", "Y", "Z"], f)
t1.print("Tensor from fiber")

t2 = Tensor.fromUncompressed(["X", "Y", "Z"], x)
t2.print("Tensor from uncompressed")
Example #18
0
[5,  6,  7],
[6,  7,  8]],
[[8,  10, 12],
[10, 12, 14],
[12, 14, 16]]],
[[[12, 15, 18],
[15, 18, 21],
[18, 21, 24]],
[[16, 20, 24],
[20, 24, 28],
[24, 28, 32]]]
]

Z_data = [[0, 0, 0], [0, 0, 0]]

A_HFA = Tensor.fromUncompressed(["K1", "K0"], A_data, name = "A")
B_HFA = Tensor.fromUncompressed(["N1", "K1", "N0", "K0"], B_data, name = "B")
Z_HFA = Tensor.fromUncompressed(["N1", "N0"], Z_data, shape=[N1, N0], name = "Z")

str_desc = sys.argv[1]
frontier_descriptor = [str_desc[0], str_desc[1]]

myA = encodeSwoopTensorInFormat(A_HFA, frontier_descriptor)
print("encoded A")
myB = encodeSwoopTensorInFormat(B_HFA, ["U", "U", "U", "C"])
print("encoded B")
myZ = encodeSwoopTensorInFormat(Z_HFA, frontier_descriptor)
print("done encoding\n")

a.setImplementations("root", myA[0])
a.setImplementations("K1", myA[1])
Example #19
0
from fibertree import Tensor
from fibertree import Payload

print("----------------------------------------")
print("          BFS graph traversal")
print("----------------------------------------")
print("")

data_dir = "../../data"

#a = Tensor.fromYAMLfile(os.path.join(data_dir, "graph-a.yaml"))

# Adjacency matrix
a = Tensor.fromUncompressed(
    ["S", "D"], [[0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0],
                 [0, 0, 0, 0, 1, 1], [1, 0, 0, 0, 0, 1], [1, 1, 0, 0, 0, 0]])

# Fringe (current and next)
f0 = Tensor.fromUncompressed(["D"], [1, 0, 0, 0, 0, 0])

# Distance
d = Tensor(rank_ids=["S"])

# Get root fibers
a_s = a.getRoot()
f0_d = f0.getRoot()
d_d = d.getRoot()

print("BFS")
Example #20
0
z_root_update_acks = UpdatePayloads(z_root, z_root_handles,
                                    z_n1_new_fiber_handles)

# read in inputs
# jhu_len = 5157
shape = 500  # TODO: take this as input or get it from yaml somehow
# generate input frontier and tile it
A_data = [0] * shape

# read in frontier
with open(sys.argv[2], 'r') as f:
    for line in f:
        elt = int(line)
        A_data[elt] = 1

A_untiled = Tensor.fromUncompressed(["S"], A_data, name="A")
A_HFA = A_untiled.splitUniform(32, relativeCoords=False)  # split S
print("A untiled shape {}, tiled shape {}".format(A_untiled.getShape(),
                                                  A_HFA.getShape()))
# A_HFA.dump("tiled_frontier.yaml")

print("reading tiled mtx from yaml")
t0 = time.clock()
B_HFA = Tensor.fromYAMLfile(sys.argv[3])
t1 = time.clock() - t0
print("read B from yaml in {} s".format(t1))

# output
Z_data = [[0], [0]]
Z_HFA = Tensor.fromUncompressed(
    ["D1", "D0"],