```import numpy as np

from ...core.utils import as_id_array
from ...utils.jaggedarray import JaggedArray
from ..nodestatus import NodeStatus

"""
Examples
--------
>>> _split_link_ends(((0, 1, 2), (3, 4, 5)))
(array([0, 1, 2]), array([3, 4, 5]))
>>> _split_link_ends([(0, 3), (1, 4), (2, 5)])
(array([0, 1, 2]), array([3, 4, 5]))
(array([0]), array([3]))
"""

return (np.array([], dtype=int), np.array([], dtype=int))
else:

Links are *inactive* if they connect two boundary nodes or touch a
closed boundary. Otherwise, the link is *active*.

Parameters
----------
status0, status1 : sequence of array-like
Status at link start and end

Returns
-------
ndarray, boolean :
Boolean array that indicates if a link is active.
"""

return (
) | (
)

Parameters
----------
node_status : ndarray
Status of nodes.
node0, node1 : sequence of array-like
Node ID at link start and end.

Returns
-------
ndarray :

Examples
--------
>>> links = [(0, 2), (1, 3), (0, 1), (1, 2), (0, 3)]
>>> status = np.array([0, 0, 0, 0])
array([0, 1, 2, 3, 4])
"""

raise ValueError("Link arrays must be the same length")

)

Parameters
----------
node0, node1 : sequence of array-like
Node ID at link start and end.
number_of_nodes : int, optional
Number of nodes in the grid

Returns
-------
ndarray :

Examples
--------
>>> link_ends = [(0, 3), (1, 4), (2, 5), (3, 6), (4, 7), (5, 8)]
array([0, 0, 0, 1, 1, 1, 1, 1, 1])
"""

#    raise ValueError('Link arrays must be the same length')

Parameters
----------
node0, node1 : sequence of array-like
Node ID at link start and end.
number_of_nodes : int, optional
Number of nodes in the grid

Returns
-------
ndarray :

Examples
--------
>>> out_link_count_per_node(([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]))
array([1, 1, 1, 1, 1, 1])
>>> out_link_count_per_node(([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]),
...     number_of_nodes=9)
array([1, 1, 1, 1, 1, 1, 0, 0, 0])
"""
raise ValueError("Link arrays must be the same length")

Parameters
----------
node0, node1 : sequence of array-like
Node ID at link start and end.
number_of_nodes : int, optional
Number of nodes in the grid

Returns
-------
ndarray :

Examples
--------
>>> link_count_per_node(([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]))
array([1, 1, 1, 2, 2, 2, 1, 1, 1])
"""

node_count = number_of_nodes or max(len(in_count), len(out_count))

if len(in_count) < node_count:
in_count = np.pad(in_count, (0, node_count - len(in_count)), mode="constant")
if len(out_count) < node_count:
out_count = np.pad(out_count, (0, node_count - len(out_count)), mode="constant")

return in_count + out_count

else:

nodes.

Parameters
----------
node0, node1 : sequence of array-like
Node ID at link start and end.
number_of_nodes : int, optional
Number of nodes in the grid

Returns
-------
tuple :

Examples
--------
...                                       [3, 4, 5, 6, 7, 8]))
array([0, 1, 2, 3, 4, 5])
>>> count
array([0, 0, 0, 1, 1, 1, 1, 1, 1])

...                                       [3, 4, 5, 6, 7, 8]),
array([1, 2, 3, 4, 5, 6])
>>> count
array([0, 0, 0, 1, 1, 1, 1, 1, 1])
"""

)

nodes.

Parameters
----------
node0, node1 : sequence of array-like
Node ID at link start and end.
number_of_nodes : int, optional
Number of nodes in the grid

Returns
-------
tuple :

Examples
--------
...     ([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]), link_ids=range(-1, 5),
...     number_of_nodes=9)
array([-1,  0,  1,  2,  3,  4])
>>> count
array([1, 1, 1, 1, 1, 1, 0, 0, 0])

...     ([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]), number_of_nodes=9)
array([0, 1, 2, 3, 4, 5])
>>> count
array([1, 1, 1, 1, 1, 1, 0, 0, 0])
"""

)

and leaving nodes.

Parameters
----------
node0, node1 : sequence of array-like
Node ID at link start and end.
number_of_nodes : int, optional
Number of nodes in the grid

Returns
-------
tuple :

Examples
--------
...     ([0, 1, 2, 3, 4, 5], [3, 4, 5, 6, 7, 8]), number_of_nodes=9)
array([0, 1, 2, 0, 3, 1, 4, 2, 5, 3, 4, 5])
>>> count
array([1, 1, 1, 2, 2, 2, 1, 1, 1])
"""
)

)
)

offset = 0
)

"""Create a grid of links that enter and leave nodes. __init__((node0,
node1), number_of_nodes=None)

Parameters
----------
node0, node1 : sequence of array-like
Node ID at link start and end.
number_of_nodes : int, optional
Number of nodes in the grid

Returns
-------
A newly-created grid

Examples
--------
>>> lgrid = LinkGrid([(0, 1, 0, 2, 0), (2, 3, 1, 3, 3)], 4)
5
>>> lgrid.number_of_nodes
4
0
3
array([0, 2, 4])
array([1, 3])

>>> lgrid = LinkGrid([(0, 1, 0, 2, 0), (2, 3, 1, 3, 3)], 4,
array([[0, 2],
[1, 3],
[0, 1],
[2, 3],
[0, 3]])
array([1, 3, 5])
array([0, 2])
"""

"""Create a grid of links that enter and leave nodes. __init__((node0,
node1), number_of_nodes=None)

Parameters
----------
node0, node1 : sequence of array-like
Node ID at link start and end.
number_of_nodes : int, optional
Number of nodes in the grid

Returns
-------
A newly-created grid

Examples
--------
>>> lgrid = LinkGrid([(0, 1, 0, 2, 0), (2, 3, 1, 3, 3)], 4)
5
>>> lgrid.number_of_nodes
4
0
3
array([0, 2, 4])
array([1, 3])

>>> lgrid = LinkGrid([(0, 1, 0, 2, 0), (2, 3, 1, 3, 3)], 4,
array([[0, 2],
[1, 3],
[0, 1],
[2, 3],
[0, 3]])
array([1, 3, 5])
array([0, 2])
"""

)
)
)
)

self._number_of_nodes = number_of_nodes

self._node_status = node_status

@property
"""Number of links in the grid."""

@property
def number_of_nodes(self):
"""Number of nodes in the grid."""
return self._number_of_nodes

"""Number of links entering a node.

Parameters
----------
node : int
Node ID

Returns
-------
int :
Number of links entering the node.

Examples
--------
>>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4)
>>> [lgrid.number_of_in_links_at_node(node) for node in range(4)]
[0, 1, 1, 2]
"""

"""Number of links leaving a node.

Parameters
----------
node : int
Node ID

Returns
-------
int :
Number of links leaving the node.

Examples
--------
>>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4)
>>> [lgrid.number_of_out_links_at_node(node) for node in range(4)]
[2, 1, 1, 0]
"""

"""Number of links entering and leaving a node.

Parameters
----------
node : int
Node ID

Returns
-------
int :
Number of links entering and leaving the node.

Examples
--------
>>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4)
>>> [lgrid.number_of_links_at_node(node) for node in range(4)]
[2, 2, 2, 2]
"""
node
)

@property

@property

@property

@property
try:
except AttributeError:

try:
except AttributeError:

Parameters
----------
node : int
Node ID

Returns
-------
ndarray :

Examples
--------
>>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4)
True
array([1, 3])
"""

Parameters
----------
node : int
Node ID

Returns
-------
ndarray :

Examples
--------
>>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4)
array([0, 2])
True
"""

[docs]    def iter_nodes(self):
"""Iterate of the nodes of the grid.

Returns
-------
ndarray :
Links entering and leaving each node

Examples
--------
>>> lgrid = LinkGrid([(0, 1, 0, 2), (2, 3, 1, 3)], 4)
array([0, 2])
array([2, 1])
array([0, 3])
array([1, 3])
"""
for node in range(self.number_of_nodes):
yield np.concatenate(