コード例 #1
0
 def test_partial_dot_mat_mat_block(self):
     mat1 = sp.arange(2 * 3 * 5 * 7 * 11)
     mat1.shape = (2, 3, 5, 7, 11)
     mat1 = algebra.make_mat(mat1,
                             axis_names=('time', 'x', 'y', 'ra', 'z'),
                             row_axes=(0, 1, 3),
                             col_axes=(0, 2, 3, 4))
     mat2 = sp.arange(2 * 13 * 5 * 7 * 17)
     mat2.shape = (2, 13, 7, 5, 17)
     mat2 = algebra.make_mat(mat2,
                             axis_names=('time', 'w', 'ra', 'y', 'freq'),
                             row_axes=(0, 1, 2, 3),
                             col_axes=(1, 2, 4))
     tmp_arr = sp.tensordot(mat1, mat2, ((2, ), (3, )))
     right_ans = sp.empty((7, 13, 2, 3, 11, 17))
     for ii in range(2):
         for jj in range(7):
             this_tmp = tmp_arr[ii, :, jj, :, ii, :, jj, :]
             this_tmp = sp.rollaxis(this_tmp, 2, 0)
             right_ans[jj, :, ii, ...] = this_tmp
     result = algebra.partial_dot(mat1, mat2)
     self.assertEqual(result.axes, ('ra', 'w', 'time', 'x', 'z', 'freq'))
     self.assertEqual(result.rows, (0, 1, 2, 3))
     self.assertEqual(result.cols, (0, 1, 4, 5))
     self.assertTrue(sp.allclose(right_ans, result))
コード例 #2
0
 def test_mat(self) :
     mat_arr = algebra.make_mat(self.data, (0,1), (0,2))
     mat_mem = algebra.make_mat(self.memmap_data, (0,1), (0,2))
     self.assertTrue(sp.allclose(mat_arr, mat_mem))
     self.assertTrue(isinstance(mat_arr, algebra.info_array))
     self.assertTrue(isinstance(mat_arr, algebra.mat))
     self.assertTrue(isinstance(mat_mem, algebra.info_memmap))
     self.assertTrue(isinstance(mat_mem, algebra.mat))
コード例 #3
0
 def test_mat(self):
     mat_arr = algebra.make_mat(self.data, (0, 1), (0, 2))
     mat_mem = algebra.make_mat(self.memmap_data, (0, 1), (0, 2))
     self.assertTrue(sp.allclose(mat_arr, mat_mem))
     self.assertTrue(isinstance(mat_arr, algebra.info_array))
     self.assertTrue(isinstance(mat_arr, algebra.mat))
     self.assertTrue(isinstance(mat_mem, algebra.info_memmap))
     self.assertTrue(isinstance(mat_mem, algebra.mat))
コード例 #4
0
 def setUp(self) :
     data = sp.arange(160)
     data.shape = (10, 4, 4)
     self.mat = algebra.make_mat(data, row_axes=(0,1), col_axes=(0,2), 
                         axis_names=('freq', 'ra', 'ra'))
     self.mat.set_axis_info('ra', 215, 0.5)
     self.mat.set_axis_info('freq', 800, 2.0)
コード例 #5
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))
コード例 #6
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))
コード例 #7
0
 def test_partial_dot_mat_mat(self):
     mat1 = sp.asarray(self.mat)
     mat1.shape = (4, 3, 2, 5)
     mat1 = algebra.make_mat(mat1, axis_names=('time', 'x', 'y', 'z'),
                             row_axes=(0,), col_axes=(1, 2, 3))
     mat2 = sp.asarray(self.mat)
     mat2.shape = (4, 2, 3, 5)
     mat2 = algebra.make_mat(mat2, axis_names=('w', 'y', 'x', 'freq'), 
                             row_axes=(0, 1, 2), col_axes=(3,))
     result = algebra.partial_dot(mat1, mat2)
     self.assertEqual(result.axes, ('time', 'w', 'z', 'freq'))
     self.assertEqual(result.rows, (0, 1))
     self.assertEqual(result.cols, (2, 3))
     self.assertEqual(result.shape, (4, 4, 5, 5))
     right_ans = sp.tensordot(mat1, mat2, ((1, 2), (2, 1)))
     right_ans = sp.swapaxes(right_ans, 1, 2)
     self.assertTrue(sp.allclose(right_ans, result))
コード例 #8
0
 def setUp(self) :
     data = sp.arange(20)
     data.shape = (5,4)
     self.mat_arr = algebra.make_mat(data.copy(), axis_names=('ra', 'dec'))
     self.vect_arr = algebra.make_vect(data.copy(), axis_names=('ra', 'dec'))
     mem = npfor.open_memmap('temp.npy', mode='w+', shape=(5, 4))
     mem[:] = data
     self.vect_mem = algebra.make_vect(mem)
     self.arr = data.copy()
コード例 #9
0
 def setUp(self):
     data = sp.arange(160)
     data.shape = (10, 4, 4)
     self.mat = algebra.make_mat(data,
                                 row_axes=(0, 1),
                                 col_axes=(0, 2),
                                 axis_names=('freq', 'ra', 'ra'))
     self.mat.set_axis_info('ra', 215, 0.5)
     self.mat.set_axis_info('freq', 800, 2.0)
コード例 #10
0
 def setUp(self):
     data = sp.arange(20)
     data.shape = (5, 4)
     self.mat_arr = algebra.make_mat(data.copy(), axis_names=('ra', 'dec'))
     self.vect_arr = algebra.make_vect(data.copy(),
                                       axis_names=('ra', 'dec'))
     mem = npfor.open_memmap('temp.npy', mode='w+', shape=(5, 4))
     mem[:] = data
     self.vect_mem = algebra.make_vect(mem)
     self.arr = data.copy()
コード例 #11
0
 def test_dot_mat_checks_dims(self) :
     """ Make sure that it checks that marticies have compatible dimensions 
     for matrix multiplication."""
     self.mat.shape = (5, 4, 2, 3)
     self.mat.cols = (0, 2, 3)
     self.mat.axes = ('freq', 'mode', 'a', 'b')
     self.assertRaises(ValueError, algebra.dot, self.vect, self.mat)
     # Matrix-Matrix multiplication not written yet.
     mat2 = sp.arange(120)
     mat2.shape = (5, 2, 3, 4)
     mat2 = algebra.make_mat(mat2, (0, 1, 2), (0, 3))
     self.assertRaises(NotImplementedError, algebra.dot, self.mat, mat2)
コード例 #12
0
 def test_dot_mat_checks_dims(self):
     """ Make sure that it checks that marticies have compatible dimensions 
     for matrix multiplication."""
     self.mat.shape = (5, 4, 2, 3)
     self.mat.cols = (0, 2, 3)
     self.mat.axes = ('freq', 'mode', 'a', 'b')
     self.assertRaises(ValueError, algebra.dot, self.vect, self.mat)
     # Matrix-Matrix multiplication not written yet.
     mat2 = sp.arange(120)
     mat2.shape = (5, 2, 3, 4)
     mat2 = algebra.make_mat(mat2, (0, 1, 2), (0, 3))
     self.assertRaises(NotImplementedError, algebra.dot, self.mat, mat2)
コード例 #13
0
 def test_partial_dot_mat_mat(self):
     mat1 = sp.asarray(self.mat)
     mat1.shape = (4, 3, 2, 5)
     mat1 = algebra.make_mat(mat1,
                             axis_names=('time', 'x', 'y', 'z'),
                             row_axes=(0, ),
                             col_axes=(1, 2, 3))
     mat2 = sp.asarray(self.mat)
     mat2.shape = (4, 2, 3, 5)
     mat2 = algebra.make_mat(mat2,
                             axis_names=('w', 'y', 'x', 'freq'),
                             row_axes=(0, 1, 2),
                             col_axes=(3, ))
     result = algebra.partial_dot(mat1, mat2)
     self.assertEqual(result.axes, ('time', 'w', 'z', 'freq'))
     self.assertEqual(result.rows, (0, 1))
     self.assertEqual(result.cols, (2, 3))
     self.assertEqual(result.shape, (4, 4, 5, 5))
     right_ans = sp.tensordot(mat1, mat2, ((1, 2), (2, 1)))
     right_ans = sp.swapaxes(right_ans, 1, 2)
     self.assertTrue(sp.allclose(right_ans, result))
コード例 #14
0
 def test_partial_dot_mat_mat_block(self):
     mat1 = sp.arange(2 * 3 * 5 * 7 *11)
     mat1.shape = (2, 3, 5, 7, 11)
     mat1 = algebra.make_mat(mat1, axis_names=('time', 'x', 'y', 'ra', 'z'),
                             row_axes=(0, 1, 3), col_axes=(0, 2, 3, 4))
     mat2 = sp.arange(2 * 13 * 5 * 7 * 17)
     mat2.shape = (2, 13, 7, 5, 17)
     mat2 = algebra.make_mat(mat2, 
         axis_names=('time', 'w', 'ra', 'y', 'freq'), 
         row_axes=(0, 1, 2, 3), col_axes=(1, 2, 4))
     tmp_arr = sp.tensordot(mat1, mat2, ((2,), (3,)))
     right_ans = sp.empty((7, 13, 2, 3, 11, 17))
     for ii in range(2):
         for jj in range(7):
             this_tmp = tmp_arr[ii,:,jj,:,ii,:,jj,:]
             this_tmp = sp.rollaxis(this_tmp, 2, 0)
             right_ans[jj,:,ii,...] = this_tmp
     result = algebra.partial_dot(mat1, mat2)
     self.assertEqual(result.axes, ('ra', 'w', 'time', 'x', 'z', 'freq'))
     self.assertEqual(result.rows, (0, 1, 2, 3))
     self.assertEqual(result.cols, (0, 1, 4, 5))
     self.assertTrue(sp.allclose(right_ans, result))