def test_bmat(self): A = coo_matrix([[1, 2], [3, 4]]) B = coo_matrix([[5], [6]]) C = coo_matrix([[7]]) expected = matrix([[1, 2, 5], [3, 4, 6], [0, 0, 7]]) assert_equal(construct.bmat([[A, B], [None, C]]).todense(), expected) expected = matrix([[1, 2, 0], [3, 4, 0], [0, 0, 7]]) assert_equal(construct.bmat([[A, None], [None, C]]).todense(), expected) expected = matrix([[0, 5], [0, 6], [7, 0]]) assert_equal(construct.bmat([[None, B], [C, None]]).todense(), expected)
def test_bmat(self): A = coo_matrix([[1, 2], [3, 4]]) B = coo_matrix([[5], [6]]) C = coo_matrix([[7]]) expected = matrix([[1, 2, 5], [3, 4, 6], [0, 0, 7]]) assert_equal(construct.bmat([[A, B], [None, C]]).todense(), expected) expected = matrix([[1, 2, 0], [3, 4, 0], [0, 0, 7]]) assert_equal( construct.bmat([[A, None], [None, C]]).todense(), expected) expected = matrix([[0, 5], [0, 6], [7, 0]]) assert_equal( construct.bmat([[None, B], [C, None]]).todense(), expected)
def test_bmat(self): A = coo_matrix([[1,2],[3,4]]) B = coo_matrix([[5],[6]]) C = coo_matrix([[7]]) D = coo_matrix((0,0)) expected = array([[1, 2, 5], [3, 4, 6], [0, 0, 7]]) assert_equal(construct.bmat([[A, B], [None, C]]).toarray(), expected) expected = array([[1, 2, 0], [3, 4, 0], [0, 0, 7]]) assert_equal( construct.bmat([[A, None], [None, C]]).toarray(), expected ) expected = array([[0, 5], [0, 6], [7, 0]]) assert_equal( construct.bmat([[None, B], [C, None]]).toarray(), expected ) expected = np.empty((0, 0)) assert_equal(construct.bmat([[None, None]]).toarray(), expected) assert_equal( construct.bmat([[None, D], [D, None]]).toarray(), expected ) # test bug reported in gh-5976 expected = array([[7]]) assert_equal( construct.bmat([[None, D], [C, None]]).toarray(), expected ) # test failure cases with assert_raises(ValueError) as excinfo: construct.bmat([[A], [B]]) excinfo.match(r'Got blocks\[1,0\]\.shape\[1\] == 1, expected 2') with assert_raises(ValueError) as excinfo: construct.bmat([[A, C]]) excinfo.match(r'Got blocks\[0,1\]\.shape\[0\] == 1, expected 2')
def test_bmat(self): A = coo_matrix([[1,2],[3,4]]) B = coo_matrix([[5],[6]]) C = coo_matrix([[7]]) D = coo_matrix((0,0)) expected = matrix([[1, 2, 5], [3, 4, 6], [0, 0, 7]]) assert_equal(construct.bmat([[A,B],[None,C]]).todense(), expected) expected = matrix([[1, 2, 0], [3, 4, 0], [0, 0, 7]]) assert_equal(construct.bmat([[A,None],[None,C]]).todense(), expected) expected = matrix([[0, 5], [0, 6], [7, 0]]) assert_equal(construct.bmat([[None,B],[C,None]]).todense(), expected) expected = matrix(np.empty((0,0))) assert_equal(construct.bmat([[None,None]]).todense(), expected) assert_equal(construct.bmat([[None,D],[D,None]]).todense(), expected) # test bug reported in gh-5976 expected = matrix([[7]]) assert_equal(construct.bmat([[None,D],[C,None]]).todense(), expected) # test failure cases assert_raises(ValueError, construct.bmat, [[A],[B]]) assert_raises(ValueError, construct.bmat, [[A,C]])
def test_bmat(self): A = coo_matrix([[1, 2], [3, 4]]) B = coo_matrix([[5], [6]]) C = coo_matrix([[7]]) D = coo_matrix((0, 0)) expected = matrix([[1, 2, 5], [3, 4, 6], [0, 0, 7]]) assert_equal(construct.bmat([[A, B], [None, C]]).todense(), expected) expected = matrix([[1, 2, 0], [3, 4, 0], [0, 0, 7]]) assert_equal( construct.bmat([[A, None], [None, C]]).todense(), expected) expected = matrix([[0, 5], [0, 6], [7, 0]]) assert_equal( construct.bmat([[None, B], [C, None]]).todense(), expected) expected = matrix(np.empty((0, 0))) assert_equal(construct.bmat([[None, None]]).todense(), expected) assert_equal( construct.bmat([[None, D], [D, None]]).todense(), expected) # test bug reported in gh-5976 expected = matrix([[7]]) assert_equal( construct.bmat([[None, D], [C, None]]).todense(), expected) # test failure cases assert_raises(ValueError, construct.bmat, [[A], [B]]) assert_raises(ValueError, construct.bmat, [[A, C]])
def test_bmat(self): A = coo_matrix([[1,2],[3,4]]) B = coo_matrix([[5],[6]]) C = coo_matrix([[7]]) D = coo_matrix((0,0)) expected = matrix([[1, 2, 5], [3, 4, 6], [0, 0, 7]]) assert_equal(construct.bmat([[A,B],[None,C]]).todense(), expected) expected = matrix([[1, 2, 0], [3, 4, 0], [0, 0, 7]]) assert_equal(construct.bmat([[A,None],[None,C]]).todense(), expected) expected = matrix([[0, 5], [0, 6], [7, 0]]) assert_equal(construct.bmat([[None,B],[C,None]]).todense(), expected) expected = matrix(np.empty((0,0))) assert_equal(construct.bmat([[None,None]]).todense(), expected) assert_equal(construct.bmat([[None,D],[D,None]]).todense(), expected) # test bug reported in gh-5976 expected = matrix([[7]]) assert_equal(construct.bmat([[None,D],[C,None]]).todense(), expected) # test failure cases with assert_raises(ValueError) as excinfo: construct.bmat([[A], [B]]) excinfo.match(r'Got blocks\[1,0\]\.shape\[1\] == 1, expected 2') with assert_raises(ValueError) as excinfo: construct.bmat([[A, C]]) excinfo.match(r'Got blocks\[0,1\]\.shape\[0\] == 1, expected 2')
def test_bmat(self): A = coo_matrix([[1, 2], [3, 4]]) B = coo_matrix([[5], [6]]) C = coo_matrix([[7]]) D = coo_matrix((0, 0)) expected = array([[1, 2, 5], [3, 4, 6], [0, 0, 7]]) assert_equal(construct.bmat([[A, B], [None, C]]).toarray(), expected) E = csr_matrix((1, 2), dtype=np.int32) assert_equal( construct.bmat([[A.tocsr(), B.tocsr()], [E, C.tocsr()]]).toarray(), expected) assert_equal( construct.bmat([[A.tocsc(), B.tocsc()], [E.tocsc(), C.tocsc()]]).toarray(), expected) expected = array([[1, 2, 0], [3, 4, 0], [0, 0, 7]]) assert_equal( construct.bmat([[A, None], [None, C]]).toarray(), expected) assert_equal( construct.bmat([[A.tocsr(), E.T.tocsr()], [E, C.tocsr()]]).toarray(), expected) assert_equal( construct.bmat([[A.tocsc(), E.T.tocsc()], [E.tocsc(), C.tocsc()]]).toarray(), expected) Z = csr_matrix((1, 1), dtype=np.int32) expected = array([[0, 5], [0, 6], [7, 0]]) assert_equal( construct.bmat([[None, B], [C, None]]).toarray(), expected) assert_equal( construct.bmat([[E.T.tocsr(), B.tocsr()], [C.tocsr(), Z]]).toarray(), expected) assert_equal( construct.bmat([[E.T.tocsc(), B.tocsc()], [C.tocsc(), Z.tocsc()]]).toarray(), expected) expected = matrix(np.empty((0, 0))) assert_equal(construct.bmat([[None, None]]).toarray(), expected) assert_equal( construct.bmat([[None, D], [D, None]]).toarray(), expected) # test bug reported in gh-5976 expected = array([[7]]) assert_equal( construct.bmat([[None, D], [C, None]]).toarray(), expected) # test failure cases with assert_raises(ValueError) as excinfo: construct.bmat([[A], [B]]) excinfo.match(r'Got blocks\[1,0\]\.shape\[1\] == 1, expected 2') with assert_raises(ValueError) as excinfo: construct.bmat([[A.tocsr()], [B.tocsr()]]) excinfo.match(r'incompatible dimensions for axis 1') with assert_raises(ValueError) as excinfo: construct.bmat([[A.tocsc()], [B.tocsc()]]) excinfo.match(r'Mismatching dimensions along axis 1: {1, 2}') with assert_raises(ValueError) as excinfo: construct.bmat([[A, C]]) excinfo.match(r'Got blocks\[0,1\]\.shape\[0\] == 1, expected 2') with assert_raises(ValueError) as excinfo: construct.bmat([[A.tocsr(), C.tocsr()]]) excinfo.match(r'Mismatching dimensions along axis 0: {1, 2}') with assert_raises(ValueError) as excinfo: construct.bmat([[A.tocsc(), C.tocsc()]]) excinfo.match(r'incompatible dimensions for axis 0')