Exemplo n.º 1
0
 def setUp(self) :
     data = sp.arange(30)
     data.shape = (5, 2, 3)
     self.vect = algebra.info_array(data)
     self.vect = algebra.vect_array(self.vect, 
                                    axis_names=('freq', 'a', 'b'))
     data = sp.arange(120)
     self.mat = algebra.info_array(data)
     self.mat.shape = (5, 4, 6)
     self.mat = algebra.mat_array(self.mat, row_axes=(0,1), col_axes=(0,2), 
                                   axis_names=('freq', 'mode1', 'mode2'))
Exemplo n.º 2
0
 def setUp(self):
     data = sp.arange(30, dtype=float)
     data.shape = (5, 2, 3)
     self.vect = algebra.info_array(data)
     self.vect = algebra.vect_array(self.vect,
                                    axis_names=('freq', 'a', 'b'))
     data = sp.arange(120, dtype=float)
     self.mat = algebra.info_array(data)
     self.mat.shape = (5, 4, 6)
     self.mat = algebra.mat_array(self.mat,
                                  row_axes=(0, 1),
                                  col_axes=(0, 2),
                                  axis_names=('freq', 'mode1', 'mode2'))
Exemplo n.º 3
0
 def test_from_info(self) :
     arr = algebra.info_array(self.data)
     mat_arr = algebra.make_mat(arr, (0,1), (0,2))
     self.assertTrue(isinstance(mat_arr, algebra.mat))
     mem = algebra.info_memmap(self.memmap_data)
     vect_mem = algebra.make_vect(mem)
     self.assertTrue(isinstance(vect_mem, algebra.vect))
Exemplo n.º 4
0
 def test_from_info(self):
     arr = algebra.info_array(self.data)
     mat_arr = algebra.make_mat(arr, (0, 1), (0, 2))
     self.assertTrue(isinstance(mat_arr, algebra.mat))
     mem = algebra.info_memmap(self.memmap_data)
     vect_mem = algebra.make_vect(mem)
     self.assertTrue(isinstance(vect_mem, algebra.vect))
Exemplo n.º 5
0
 def test_from_memory(self) :
     # Works if constructed from array.
     data = sp.empty((5, 6, 6))
     data[:] = 4.0
     Mat = algebra.info_array(data, {'a' : 'b'})
     self.assertEqual(Mat.shape, (5, 6, 6))
     self.assertEqual(Mat.info['a'], 'b')
     self.assertTrue(sp.allclose(Mat, 4.0))
     # Check that the dictionary is there and empty if uninitialized.
     Mat4 = algebra.info_array(data)
     self.assertEqual(Mat4.info, {})
     # Works if constructed from a slice.
     Mat2 = Mat[1:2, :, :]
     self.assertEqual(Mat2.shape, (1, 6, 6))
     self.assertEqual(Mat2.info['a'], 'b')
     # Works if constructed from a view.
     Mat3 = data.view(algebra.info_array)
     self.assertEqual(Mat3.shape, (5, 6, 6))
     Mat3.info['a'] = 'b'
Exemplo n.º 6
0
 def test_from_memory(self):
     # Works if constructed from array.
     data = sp.empty((5, 6, 6))
     data[:] = 4.0
     Mat = algebra.info_array(data, {'a': 'b'})
     self.assertEqual(Mat.shape, (5, 6, 6))
     self.assertEqual(Mat.info['a'], 'b')
     self.assertTrue(sp.allclose(Mat, 4.0))
     # Check that the dictionary is there and empty if uninitialized.
     Mat4 = algebra.info_array(data)
     self.assertEqual(Mat4.info, {})
     # Works if constructed from a slice.
     Mat2 = Mat[1:2, :, :]
     self.assertEqual(Mat2.shape, (1, 6, 6))
     self.assertEqual(Mat2.info['a'], 'b')
     # Works if constructed from a view.
     Mat3 = data.view(algebra.info_array)
     self.assertEqual(Mat3.shape, (5, 6, 6))
     Mat3.info['a'] = 'b'
Exemplo n.º 7
0
    def test_slice_interpolate_cubic(self):
        # Construct a 3D array that is a quadratic function.
        data = sp.arange(140, dtype=float)
        data.shape = (5, 4, 7)
        vect = algebra.info_array(data)
        vect = algebra.vect_array(vect, axis_names=('freq', 'a', 'b'))

        v = vect
        a = sp.arange(-2, 3)**2
        a.shape = (5, 1, 1)
        b = sp.arange(-1, 3)**2
        b.shape = (1, 4, 1)
        c = sp.arange(-1, 6)**2
        c.shape = (1, 1, 7)
        v[:, :, :] = a + b + c
        v.set_axis_info('freq', 0, 1)
        v.set_axis_info('a', 1, 1)
        v.set_axis_info('b', 2, 1)

        #### First test the weights.

        # Test cubic conv interpolations in multi D.
        points, weights = v.slice_interpolate_weights([0, 1, 2], [0, 0, 0],
                                                      'cubic')
        self.assertTrue(1. in weights)
        self.assertTrue(weights.tolist().count(0) == 63)
        self.assertTrue(points[sp.where(weights == 1)[0][0]][0] == 2)
        self.assertTrue(points[sp.where(weights == 1)[0][0]][1] == 1)
        self.assertTrue(points[sp.where(weights == 1)[0][0]][2] == 1)

        points, weights = v.slice_interpolate_weights([0, 1, 2], [1.5, 0.5, 0],
                                                      'cubic')
        self.assertTrue(points.shape[0] == 64)
        self.assertTrue(weights.shape[0] == 64)

        # Test full interpolation.
        out = v.slice_interpolate([0, 1, 2], [0, 0, 0], 'cubic')
        self.assertTrue(sp.allclose(out, 0.0))

        out = v.slice_interpolate([0, 1, 2], [-1.34, 0.55, 0.86], 'cubic')
        self.assertTrue(sp.allclose(out, 2.8377))

        # Test partial interpolation.
        out = v.slice_interpolate([0, 2], [1.4, -0.3], 'cubic')
        out1 = v.slice_interpolate([0, 1, 2], [1.4, -1, -0.3], 'cubic')
        out2 = v.slice_interpolate([0, 1, 2], [1.4, 0, -0.3], 'cubic')
        out3 = v.slice_interpolate([0, 1, 2], [1.4, 1, -0.3], 'cubic')
        out4 = v.slice_interpolate([0, 1, 2], [1.4, 2, -0.3], 'cubic')
        self.assertTrue(sp.allclose(out, [out1, out2, out3, out4]))
Exemplo n.º 8
0
 def test_assert_info(self) :
     """Test the assert_info function."""
     # info_memaps should pass.
     data = npfor.open_memmap('temp.npy', mode='w+', shape=(4,3,3))
     data[:] = 5.0
     Mat = algebra.info_memmap(data)
     algebra.assert_info(Mat)
     del Mat
     os.remove('temp.npy')
     # info_arrays should pass.
     data = sp.empty((5, 6, 6))
     data[:] = 4.0
     Mat = algebra.info_array(data)
     algebra.assert_info(Mat)
     # arrays should fail.
     self.assertRaises(TypeError, algebra.assert_info, data)
Exemplo n.º 9
0
 def test_assert_info(self):
     """Test the assert_info function."""
     # info_memaps should pass.
     data = npfor.open_memmap('temp.npy', mode='w+', shape=(4, 3, 3))
     data[:] = 5.0
     Mat = algebra.info_memmap(data)
     algebra.assert_info(Mat)
     del Mat
     os.remove('temp.npy')
     # info_arrays should pass.
     data = sp.empty((5, 6, 6))
     data[:] = 4.0
     Mat = algebra.info_array(data)
     algebra.assert_info(Mat)
     # arrays should fail.
     self.assertRaises(TypeError, algebra.assert_info, data)
Exemplo n.º 10
0
 def setUp(self) :
     info = { 'a' : 42, 'b' : 'a string', 'c' : 3.14159 }
     data = sp.arange(80).reshape((2,8,5))
     self.Mat = algebra.info_array(data, info)
Exemplo n.º 11
0
 def setUp(self) :
     data = sp.arange(60, dtype=float)
     data.shape = (2, 5, 6)
     self.array = algebra.info_array(data)
Exemplo n.º 12
0
 def setUp(self):
     info = {'a': 42, 'b': 'a string', 'c': 3.14159}
     data = sp.arange(80).reshape((2, 8, 5))
     self.Mat = algebra.info_array(data, info)
Exemplo n.º 13
0
 def setUp(self):
     data = sp.arange(60, dtype=float)
     data.shape = (2, 5, 6)
     self.array = algebra.info_array(data)
Exemplo n.º 14
0
    def test_slice_interpolate_cubic(self) :
        # Construct a 3D array that is a quadratic function.
        data = sp.arange(140, dtype=float)
        data.shape = (5, 4, 7)
        vect = algebra.info_array(data)
        vect = algebra.vect_array(vect,axis_names=('freq', 'a', 'b'))

        v = vect
        a = sp.arange(-2,3)**2
        a.shape = (5, 1, 1)
        b = sp.arange(-1,3)**2
        b.shape = (1, 4, 1)
        c = sp.arange(-1,6)**2
        c.shape = (1, 1, 7)
        v[:,:,:] = a + b + c
        v.set_axis_info('freq', 0, 1)
        v.set_axis_info('a', 1, 1)
        v.set_axis_info('b', 2, 1)
        
        #### First test the weights.

        # Test cubic conv interpolations in multi D.
        points, weights = v.slice_interpolate_weights([0, 1, 2], 
                                                      [0, 0, 0],
                                                      'cubic')
        self.assertTrue(1. in weights)
        self.assertTrue(weights.tolist().count(0) == 63)
        self.assertTrue(points[sp.where(weights==1)[0][0]][0] == 2)
        self.assertTrue(points[sp.where(weights==1)[0][0]][1] == 1)
        self.assertTrue(points[sp.where(weights==1)[0][0]][2] == 1)

        points, weights = v.slice_interpolate_weights([0, 1, 2], 
                                                      [1.5, 0.5, 0],
                                                      'cubic')
        self.assertTrue(points.shape[0] == 64)
        self.assertTrue(weights.shape[0] == 64)

        # Test full interpolation.
        out = v.slice_interpolate([0, 1, 2], 
                                  [0, 0, 0],
                                  'cubic')
        self.assertTrue(sp.allclose(out,0.0))

        out = v.slice_interpolate([0, 1, 2], 
                                  [-1.34, 0.55, 0.86],
                                  'cubic')
        self.assertTrue(sp.allclose(out,2.8377))

        # Test partial interpolation.
        out = v.slice_interpolate([0, 2], 
                                  [1.4, -0.3],
                                  'cubic')
        out1 = v.slice_interpolate([0, 1, 2], 
                                   [1.4, -1, -0.3],
                                   'cubic')
        out2 = v.slice_interpolate([0, 1, 2], 
                                   [1.4, 0, -0.3],
                                   'cubic')
        out3 = v.slice_interpolate([0, 1, 2], 
                                   [1.4, 1, -0.3],
                                   'cubic')
        out4 = v.slice_interpolate([0, 1, 2], 
                                   [1.4, 2, -0.3],
                                   'cubic')
        self.assertTrue(sp.allclose(out,[out1,out2,out3,out4]))