Esempio n. 1
0
    def test_negative_coords(self):
        print('Negative coords test')
        key = CoordsKey(D=1)
        key.setTensorStride(1)

        cm = CoordsManager(D=1)
        coords = torch.IntTensor([[0, -3], [0, -2], [0, -1], [0, 0], [0, 1],
                                  [0, 2], [0, 3]])

        # Initialize map
        mapping, inverse_mapping = cm.initialize(coords, key)
        print(mapping, len(mapping))
        cm.print_diagnostics(key)

        # Create a strided map
        stride_key = cm.stride(key, [2])
        strided_coords = cm.get_coords(stride_key).numpy().tolist()
        self.assertTrue(len(strided_coords) == 4)
        self.assertTrue([0, -4] in strided_coords)
        self.assertTrue([0, -2] in strided_coords)
        self.assertTrue([0, 2] in strided_coords)

        print('Stride: ', cm.get_coords(stride_key))
        cm.print_diagnostics(stride_key)
        print(cm)
Esempio n. 2
0
    def test_coords_map(self):
        coords, _, _ = data_loader(1)

        key = CoordsKey(D=2)
        key.setTensorStride(1)

        # Initialize map
        cm = CoordsManager(D=2)
        mapping, inverse_mapping = cm.initialize(coords,
                                                 key,
                                                 force_remap=True,
                                                 allow_duplicate_coords=False)
        print(mapping, len(mapping))
        cm.print_diagnostics(key)
        print(cm)
        print(cm.get_batch_size())
        print(cm.get_batch_indices())

        # Create a strided map
        stride_key = cm.stride(key, [2, 2])
        print('Stride: ', cm.get_coords(stride_key))
        cm.print_diagnostics(key)
        print(cm)

        ins, outs = cm.get_coords_map(1, 2)
        inc = cm.get_coords(1)
        outc = cm.get_coords(2)
        for i, o in zip(ins, outs):
            print(f"{i}: ({inc[i]}) -> {o}: ({outc[o]})")
Esempio n. 3
0
    def test_coords_manager(self):
        key = CoordsKey(D=1)
        key.setTensorStride(1)

        cm = CoordsManager(D=1)
        coords = (torch.rand(5, 2) * 100).int()
        cm.initialize(coords, key)
        print(cm.get_row_indices_per_batch(key))
        print(key)
        print(cm)
Esempio n. 4
0
 def test_hash(self):
     N, M = 1000, 1000
     I, J = np.meshgrid(np.arange(N), np.arange(M))
     I = I.reshape(-1, 1) - 100
     J = J.reshape(-1, 1) - 100
     K = np.zeros_like(I)
     C = np.hstack((I, J, K))
     coords_manager = CoordsManager(D=2)
     coords_key = CoordsKey(2)
     coords_key.setTensorStride(1)
     coords_manager.initialize(torch.from_numpy(C).int(), coords_key)
     print(coords_manager)
Esempio n. 5
0
    def test_coords_manager(self):
        key = CoordsKey(D=1)
        key.setTensorStride(1)

        cm = CoordsManager(D=1)
        coords = torch.IntTensor([[0, 1], [0, 1], [0, 2], [0, 2], [1, 0],
                                  [1, 0], [1, 1]])
        unique_coords = torch.unique(coords, dim=0)

        # Initialize map
        mapping, inverse_mapping = cm.initialize(coords,
                                                 key,
                                                 force_remap=True,
                                                 allow_duplicate_coords=False)
        self.assertTrue(len(unique_coords) == len(mapping))
        print(mapping, len(mapping))
        cm.print_diagnostics(key)
        print(cm)
        self.assertTrue(cm.get_batch_size() == 2)
        self.assertTrue(cm.get_batch_indices() == {0, 1})

        # Create a strided map
        stride_key = cm.stride(key, [4])
        strided_coords = cm.get_coords(stride_key)
        self.assertTrue(len(strided_coords) == 2)
        cm.print_diagnostics(key)
        print(cm)

        # Create a transposed stride map
        transposed_key = cm.transposed_stride(stride_key, [2], [3], [1])
        print('Transposed Stride: ', cm.get_coords(transposed_key))
        print(cm)

        # Create a transposed stride map
        transposed_key = cm.transposed_stride(stride_key, [2], [3], [1],
                                              force_creation=True)
        print('Forced Transposed Stride: ', cm.get_coords(transposed_key))
        print(cm)

        # Create a reduction map
        key = cm.reduce()
        print('Reduction: ', cm.get_coords(key))
        print(cm)

        print('Reduction mapping: ', cm.get_row_indices_per_batch(stride_key))
        print(cm)
Esempio n. 6
0
    def test_coords_manager(self):
        key = CoordsKey(D=1)
        key.setTensorStride(1)

        cm = CoordsManager(D=1)
        coords = (torch.rand(20, 2) * 10).int()
        print(coords)
        unique_coords = torch.unique(coords, dim=0)
        print('Num unique: ', unique_coords.shape)

        # Initialize map
        mapping = cm.initialize(coords,
                                key,
                                force_remap=True,
                                allow_duplicate_coords=False)
        print(mapping, len(mapping))
        cm.print_diagnostics(key)
        print(cm)
        print(cm.get_batch_size())
        print(cm.get_batch_indices())

        # Create a strided map
        stride_key = cm.stride(key, [4])
        print('Stride: ', cm.get_coords(stride_key))
        cm.print_diagnostics(key)
        print(cm)

        # Create a transposed stride map
        transposed_key = cm.transposed_stride(stride_key, [2], [3], [1])
        print('Transposed Stride: ', cm.get_coords(transposed_key))
        print(cm)

        # Create a transposed stride map
        transposed_key = cm.transposed_stride(stride_key, [2], [3], [1],
                                              force_creation=True)
        print('Forced Transposed Stride: ', cm.get_coords(transposed_key))
        print(cm)

        # Create a reduction map
        key = cm.reduce()
        print('Reduction: ', cm.get_coords(key))
        print(cm)

        print('Reduction mapping: ', cm.get_row_indices_per_batch(stride_key))
        print(cm)
Esempio n. 7
0
    def test_hash(self):
        try:
            import numpy as np
        except:
            return

        N, M = 1000, 1000
        I, J = np.meshgrid(np.arange(N), np.arange(M))
        I = I.reshape(-1, 1) - 100
        J = J.reshape(-1, 1) - 100
        K = np.zeros_like(I)
        C = np.hstack((I, J, K))
        coords_manager = CoordsManager(D=2)
        coords_key = CoordsKey(2)
        coords_manager.initialize(torch.from_numpy(C).int(), coords_key)
Esempio n. 8
0
 def test_coords_key(self):
     key = CoordsKey(D=1)
     key.setKey(1)
     self.assertTrue(key.getKey() == 1)
     key.setTensorStride([1])
     print(key)