Пример #1
0
 def test_block_diag_1(self):
     """ block_diag with one matrix """
     assert_equal(construct.block_diag([[1, 0]]).toarray(), array([[1, 0]]))
     assert_equal(
         construct.block_diag([[[1, 0]]]).toarray(), array([[1, 0]]))
     assert_equal(
         construct.block_diag([[[1], [0]]]).toarray(), array([[1], [0]]))
     # just on scalar
     assert_equal(construct.block_diag([1]).toarray(), array([[1]]))
Пример #2
0
    def test_block_diag_sparse_matrices(self):
        """ block_diag with sparse matrices """

        sparse_col_matrices = [
            coo_matrix(([[1, 2, 3]]), shape=(1, 3)),
            coo_matrix(([[4, 5]]), shape=(1, 2))
        ]
        block_sparse_cols_matrices = construct.block_diag(sparse_col_matrices)
        assert_equal(block_sparse_cols_matrices.toarray(),
                     array([[1, 2, 3, 0, 0], [0, 0, 0, 4, 5]]))

        sparse_row_matrices = [
            coo_matrix(([[1], [2], [3]]), shape=(3, 1)),
            coo_matrix(([[4], [5]]), shape=(2, 1))
        ]
        block_sparse_row_matrices = construct.block_diag(sparse_row_matrices)
        assert_equal(block_sparse_row_matrices.toarray(),
                     array([[1, 0], [2, 0], [3, 0], [0, 4], [0, 5]]))
Пример #3
0
    def test_block_diag_basic(self):
        """ basic test for block_diag """
        A = coo_matrix([[1, 2], [3, 4]])
        B = coo_matrix([[5], [6]])
        C = coo_matrix([[7]])

        expected = array([[1, 2, 0, 0], [3, 4, 0, 0], [0, 0, 5, 0],
                          [0, 0, 6, 0], [0, 0, 0, 7]])

        assert_equal(construct.block_diag((A, B, C)).toarray(), expected)
Пример #4
0
 def test_block_diag_scalar_1d_args(self):
     """ block_diag with scalar and 1d arguments """
     # one 1d matrix and a scalar
     assert_array_equal(
         construct.block_diag([[2, 3], 4]).toarray(),
         [[2, 3, 0], [0, 0, 4]])