Opened 4 years ago

Closed 4 years ago

#17574 closed defect (fixed)

Empty hypergraph and __str__ function

Reported by: ncohen Owned by:
Priority: major Milestone: sage-6.5
Component: combinatorial designs Keywords:
Cc: vdelecroix Merged in:
Authors: Nathann Cohen Reviewers: Dima Pasechnik
Report Upstream: N/A Work issues:
Branch: 514dd64 (Commits) Commit: 514dd6484b29cb40474f09408301b968678cc9d2
Dependencies: Stopgaps:

Description

Right now an exception is raised when building the empty hypergraph. This branch fixes it:

sage: sage: IncidenceStructure([])
Incidence structure with 0 points and 0 blocks

Also, right now the class has both a __repr__ and a __str__ function, which means that typing H in a console does not produce the same output as typing print H in a script. The two functions are made equal: I work often with this class and pretty often the result of print H takes a whole screen, as it displays *all blocks*.

Nathann

Change History (9)

comment:1 Changed 4 years ago by ncohen

  • Branch set to u/ncohen/17574
  • Status changed from new to needs_review

comment:2 Changed 4 years ago by git

  • Commit set to 871738feb57aaa75d015c2fb3af8900a57d50270

Branch pushed to git repo; I updated commit sha1. New commits:

871738ftrac #17574: Empty hypergraph and __str__ function

comment:3 follow-up: Changed 4 years ago by vdelecroix

Hey,

It can be useful to keep a function printing all blocks as it is the case with matrices right now with the method .str():

sage: m = random_matrix(ZZ,100)
sage: m
100 x 100 dense matrix over Integer Ring (use the '.str()' method to see the entries)
sage: print m
100 x 100 dense matrix over Integer Ring
sage: m.str()
... # crazy string

And it is true that __repr__ and __str__ coincide.

sage: m.__repr__()
'100 x 100 dense matrix over Integer Ring'
sage: m.__str__()
'100 x 100 dense matrix over Integer Ring'

To get a hint when only m is typed, you need to hack repl/display/fancy_repr.py.

Vincent

comment:4 in reply to: ↑ 3 Changed 4 years ago by ncohen

Yo !

It can be useful to keep a function printing all blocks as it is the case with matrices right now with the method .str():

But we have H.blocks(), don't we ? Why would we need something else ?

On the other hand, I often need to control variables, to make sure that the input is a PairwiseBalancedDesign and not just an incidence structure, and all that I could do so far was print H.__repr__().

Nathann

Last edited 4 years ago by ncohen (previous) (diff)

comment:5 Changed 4 years ago by ncohen

Beep ?...

comment:6 Changed 4 years ago by git

  • Commit changed from 871738feb57aaa75d015c2fb3af8900a57d50270 to 514dd6484b29cb40474f09408301b968678cc9d2

Branch pushed to git repo; I updated commit sha1. New commits:

9c0b7d4trac #17574: Merged with 6.8.beta6
514dd64trac #17574: broken optional doctests

comment:7 Changed 4 years ago by dimpase

  • Reviewers set to Dima Pasechnik
  • Status changed from needs_review to positive_review

LGTM

comment:8 Changed 4 years ago by ncohen

Thaaaaaaaaaaaaaaaaaaaanks!!!

Nathann

comment:9 Changed 4 years ago by vbraun

  • Branch changed from u/ncohen/17574 to 514dd6484b29cb40474f09408301b968678cc9d2
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.