def test_flatten_unflattenY():
    (g, (node_f, edges, edge_f)) = (get_simple_graph_structure(), get_simple_graph())
    y = np.array([1, 2])
    l_nf = [np.zeros((2, 3))]
    X = (l_nf, None, None)
    y_ref = [np.array([1, 2])]
    assert all([(y_typ1 == y_typ2).all() for (y_typ1, y_typ2) in zip(g.unflattenY(X, y), y_ref)])
    assert (y == g.flattenY(g.unflattenY(X, y))).all()
    (g, x, y) = more_complex_graph()
    Y = [np.array([0, 0]), np.array([0, 0, 0])]
    y = np.hstack([np.array([0, 0]), (2 + np.array([0, 0, 0]))])
    l_nf = [np.zeros((2, 3)), np.zeros((3, 4))]
    X = (l_nf, None, None)
    assert (g.flattenY(Y) == y).all()
    assert all([(y_typ1 == y_typ2).all() for (y_typ1, y_typ2) in zip(g.unflattenY(X, y), Y)])
    l_nf = [np.zeros((1, 3)), np.zeros((3, 4))]
    X = (l_nf, None, None)
    assert_raises(ValueError, g.unflattenY, X, y)
def test_flatten_unflattenY():
    (g, (node_f, edges, edge_f)) = (get_simple_graph_structure(), get_simple_graph())
    y = np.array([1, 2])
    l_nf = [np.zeros((2, 3))]
    X = (l_nf, None, None)
    y_ref = [np.array([1, 2])]
    assert all([(y_typ1 == y_typ2).all() for (y_typ1, y_typ2) in zip(g.unflattenY(X, y), y_ref)])
    assert (y == g.flattenY(g.unflattenY(X, y))).all()
    (g, x, y) = more_complex_graph()
    Y = [np.array([0, 0]), np.array([0, 0, 0])]
    y = np.hstack([np.array([0, 0]), (2 + np.array([0, 0, 0]))])
    l_nf = [np.zeros((2, 3)), np.zeros((3, 4))]
    X = (l_nf, None, None)
    assert (g.flattenY(Y) == y).all()
    assert all([(y_typ1 == y_typ2).all() for (y_typ1, y_typ2) in zip(g.unflattenY(X, y), Y)])
    l_nf = [np.zeros((1, 3)), np.zeros((3, 4))]
    X = (l_nf, None, None)
    assert_raises(ValueError, g.unflattenY, X, y)