예제 #1
0
 def test_downsample2x(self):
     meshgrid = math.meshgrid(x=(0, 1, 2, 3), y=(0, -1, -2))
     half_size = math.downsample2x(meshgrid, extrapolation.BOUNDARY)
     math.print(meshgrid, 'Full size')
     math.print(half_size, 'Half size')
     math.assert_close(half_size.vector[0], wrap([[0.5, 2.5], [0.5, 2.5]], spatial('y,x')))
     math.assert_close(half_size.vector[1], wrap([[-0.5, -0.5], [-2, -2]], spatial('y,x')))
예제 #2
0
 def test_pad_tensor(self):
     for backend in BACKENDS:
         with backend:
             a = math.meshgrid(x=4, y=3)
             # 0
             p = math.pad(a, {'x': (1, 2), 'y': (0, 1)}, ZERO)
             self.assertEqual((7, 4, 2), p.shape.sizes)  # dimension check
             math.assert_close(p.x[1:-2].y[:-1], a)  # copy inner
             math.assert_close(p.x[0], 0)
             # 1
             p = math.pad(a, {'x': (1, 2), 'y': (0, 1)}, ONE)
             self.assertEqual((7, 4, 2), p.shape.sizes)  # dimension check
             math.assert_close(p.x[1:-2].y[:-1], a)  # copy inner
             math.assert_close(p.x[0], 1)
             # periodic
             p = math.pad(a, {'x': (1, 2), 'y': (0, 1)}, PERIODIC)
             self.assertEqual((7, 4, 2), p.shape.sizes)  # dimension check
             math.assert_close(p.x[1:-2].y[:-1], a)  # copy inner
             math.assert_close(p.x[0].y[:-1], a.x[-1])
             math.assert_close(p.x[-2:].y[:-1], a.x[:2])
             # boundary
             p = math.pad(a, {'x': (1, 2), 'y': (0, 1)}, BOUNDARY)
             self.assertEqual((7, 4, 2), p.shape.sizes)  # dimension check
             math.assert_close(p.x[1:-2].y[:-1], a)  # copy inner
             math.assert_close(p.x[0].y[:-1], a.x[0])
             math.assert_close(p.x[-2:].y[:-1], a.x[-1])
             # mixed
             p = math.pad(a, {'x': (1, 2), 'y': (0, 1)}, combine_sides({'x': PERIODIC, 'y': (ONE, REFLECT)}))
             math.print(p)
             self.assertEqual((7, 4, 2), p.shape.sizes)  # dimension check
             math.assert_close(p.x[1:-2].y[:-1], a)  # copy inner
             math.assert_close(p.x[0].y[:-1], a.x[-1])  # periodic
             math.assert_close(p.x[-2:].y[:-1], a.x[:2])  # periodic
예제 #3
0
 def test_upsample2x(self):
     meshgrid = math.meshgrid(x=(0, 1, 2, 3), y=(0, -1, -2))
     double_size = math.upsample2x(meshgrid, extrapolation.BOUNDARY)
     same_size = math.downsample2x(double_size)
     math.print(meshgrid, 'Normal size')
     math.print(double_size, 'Double size')
     math.print(same_size, 'Same size')
     math.assert_close(meshgrid.x[1:-1].y[1:-1], same_size.x[1:-1].y[1:-1])
예제 #4
0
 def test_grid_sample_1d(self):
     grid = math.tensor([0, 1, 2, 3], names='x')
     coords = math.tensor([[0], [1], [0.5]], names='x,vector')
     sampled = math.grid_sample(grid, coords, None)
     math.print(sampled)
     math.assert_close(sampled, [0, 1, 0.5])
예제 #5
0
 def test_grid_sample_1d(self):
     grid = math.tensor([0, 1, 2, 3], spatial('x'))
     coords = math.tensor([[0], [1], [0.5]], spatial('x'), channel('vector'))
     sampled = math.grid_sample(grid, coords, None)
     math.print(sampled)
     math.assert_close(sampled, [0, 1, 0.5])