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

feat: added trivial hypergraph #335

Merged
merged 4 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/source/api/generators/xgi.generators.classic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
.. rubric:: Functions

.. autofunction:: empty_hypergraph
.. autofunction:: empty_simplicial_complex
.. autofunction:: empty_simplicial_complex
maximelucas marked this conversation as resolved.
Show resolved Hide resolved
.. autofunction:: trivial_hypergraph
10 changes: 10 additions & 0 deletions tests/generators/test_classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ def test_empty_hypergraph():
def test_empty_hypergraph():
SC = xgi.empty_simplicial_complex()
assert (SC.num_nodes, SC.num_edges) == (0, 0)

def test_trivial_hypergraph():
H = xgi.trivial_hypergraph()
assert (H.num_nodes, H.num_edges) == (1, 0)

H = xgi.trivial_hypergraph(n=1)
assert (H.num_nodes, H.num_edges) == (1, 0)

H = xgi.trivial_hypergraph(n=2)
assert (H.num_nodes, H.num_edges) == (2, 0)
41 changes: 41 additions & 0 deletions xgi/generators/classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
__all__ = [
"empty_hypergraph",
"empty_simplicial_complex",
"trivial_hypergraph",
]


Expand Down Expand Up @@ -98,3 +99,43 @@ def empty_simplicial_complex(create_using=None, default=None):
if default is None:
default = xgi.SimplicialComplex
return _empty_network(create_using, default)


def trivial_hypergraph(n=1, create_using=None, default=None):
"""Returns a hypergraph with one node and zero edges.
maximelucas marked this conversation as resolved.
Show resolved Hide resolved
maximelucas marked this conversation as resolved.
Show resolved Hide resolved

Parameters
----------
n : int, optional
Number of nodes (default is 1)
create_using : Hypergraph Instance, Constructor or None
If None, use the `default` constructor.
If a constructor, call it to create an empty hypergraph.
default : Hypergraph constructor (default None)
The constructor to use if create_using is None.
If None, then xgi.Hypergraph is used.

Returns
-------
Hypergraph object
A trivial hypergraph with `n` nodes

maximelucas marked this conversation as resolved.
Show resolved Hide resolved
Examples
--------
>>> import xgi
>>> H = xgi.trivial_hypergraph()
>>> H.num_nodes, H.num_edges
(1, 0)

"""
# this import needs to happen when the function runs, not when the module is first
# imported, to avoid circular imports
import xgi

if default is None:
default = xgi.Hypergraph
H = _empty_network(create_using, default)
nodes = range(n)
H.add_nodes_from(nodes)

return H