Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph(..., format='incidence_matrix') doesn't work with graphs that have loops, but G.incidence_matrix() does. So? #9714

Closed
williamstein opened this issue Aug 10, 2010 · 18 comments

Comments

@williamstein
Copy link
Contributor

We have

sage: M = matrix(3, [1,2,0, 0,2,0, 0,0,1])
sage: g = Graph(M, format='adjacency_matrix')
sage: I = g.incidence_matrix(); I
[-1 -1  0  0  0  1]
[ 1  1  0  1  1  0]
[ 0  0  1  0  0  0]

But then:

sage: Graph(I, format='incidence_matrix').show(graph_border=True)
kaboom!

Either the first .incidence_matrix() should fail, or the second Graph(...) should work.

Apply:

Component: graph theory

Author: Lukáš Lánský, Robert Miller

Reviewer: Nathann Cohen

Merged: sage-5.0.beta5

Issue created by migration from https://trac.sagemath.org/ticket/9714

@rlmill
Copy link
Mannequin

rlmill mannequin commented Aug 10, 2010

comment:1

Easy to fix, just replace (on line 944 of graph.py)

if len(NZ) != 2:
    msg += "There must be two nonzero entries (-1 & 1) per column."
    assert False

with something like

if len(NZ) == 1:
    if loops is None:
        loops = True
    elif not loops:
        msg += "There must be two nonzero entries (-1 & 1) per column."
        assert False
elif len(NZ) != 2:
    msg += "There must be two nonzero entries (-1 & 1) per column."
    assert False

@sagetrac-brunellus
Copy link
Mannequin

sagetrac-brunellus mannequin commented Jan 23, 2012

Attachment: trac_9714_incidence_checking.patch.gz

@sagetrac-brunellus
Copy link
Mannequin

sagetrac-brunellus mannequin commented Jan 23, 2012

comment:2

Then there is another problem: checking forgets possibility that there are only two vertices defined. I tried to fix that: see the second doctest.

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jan 29, 2012

Reviewer: Nathann Cohen

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jan 29, 2012

comment:3

Helloooooooooooooooo !!!

I find a bit weird that this code deals with -1 and 1 entries for undirected graphs, but well... ^^;

Anyway, here is a very small patch that just avoid some unnecessary computations.

I give a positive review to your patch, and you can review mine if you have some time :-)

Nathann

@sagetrac-brunellus
Copy link
Mannequin

sagetrac-brunellus mannequin commented Jan 31, 2012

comment:4

Hi, thanks for the review. You are certainly right that -1 is weird thing in this context and constructor should accept a normal incidence matrix with two ones in each column. I'll start another ticket for this.

I'll set positive review as soon as the tests pass.

@sagetrac-brunellus
Copy link
Mannequin

sagetrac-brunellus mannequin commented Jan 31, 2012

comment:5

What do you say to this adjustment? :-)

Lukáš.

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jan 31, 2012

comment:6

What do you say to this adjustment? :-)

"Stupid me"

Ok, now it's good to go :-)

Nathann

@sagetrac-brunellus
Copy link
Mannequin

sagetrac-brunellus mannequin commented Jan 31, 2012

Author: Lukáš Lánský

@sagetrac-brunellus
Copy link
Mannequin

sagetrac-brunellus mannequin commented Jan 31, 2012

Changed author from Lukáš Lánský to Lukáš Lánský, Robert Miller

@jdemeyer
Copy link

jdemeyer commented Feb 3, 2012

comment:9

Please state clearly which patches have to be applied.

@sagetrac-brunellus
Copy link
Mannequin

sagetrac-brunellus mannequin commented Feb 6, 2012

comment:10

Oh, sorry. :-)

@sagetrac-brunellus

This comment has been minimized.

@sagetrac-brunellus
Copy link
Mannequin

sagetrac-brunellus mannequin commented Feb 6, 2012

comment:11

(Just adding a proper commit message.)

@jdemeyer
Copy link

comment:12

The last two patches have one annoyingly long line as commit message. Could you please shorten the line length. Multiple lines are allowed, but the first line should make sense by itself.

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Feb 15, 2012

Attachment: trac_9714_review.patch.gz

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Feb 15, 2012

comment:14

Attachment: trac_9714_review_review.patch.gz

Fixed too :-)

Nathann

@nathanncohen nathanncohen mannequin removed the s: needs work label Feb 15, 2012
@jdemeyer
Copy link

Merged: sage-5.0.beta5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants