Network Utilities¶
Header: fiction/networks/network_utils.hpp
-
template<typename Ntk>
struct edge¶ Representation of an edge between two network nodes.
- Template Parameters:
Ntk –
mockturtlenetwork type.
-
template<typename Ntk>
using fiction::networks::edge_path = std::vector<mockturtle::edge<Ntk>>¶ Represents a path in a network as a walk of edges.
-
template<typename Ntk, typename Fn>
void fiction::networks::foreach_edge(const Ntk &ntk, Fn &&fn)¶ Applies a function to all edges in a
mockturtlenetwork.- Template Parameters:
Ntk –
mockturtlenetwork type.Fn – Unary function type that takes a
mockturtle::edge<Ntk>object as parameter.
- Parameters:
ntk – Network to iterate over.
fn – Function object to apply to each edge in
ntk.
-
template<typename Ntk, typename Fn>
void fiction::networks::foreach_outgoing_edge(const Ntk &ntk, const mockturtle::node<Ntk> &n, Fn &&fn)¶ Applies a function to all outgoing edges in a
mockturtlenetwork.- Template Parameters:
Ntk –
mockturtlenetwork type.Fn – Unary function type that takes a
mockturtle::edge<Ntk>object as parameter.
- Parameters:
ntk – Network to iterate over.
n – Node of
ntkwhose outgoing edges are to be considered.fn – Function object to apply to each outgoing edge of
ninntk.
-
template<typename Ntk, typename Fn>
void fiction::networks::foreach_incoming_edge(const Ntk &ntk, const mockturtle::node<Ntk> &n, Fn &&fn)¶ Applies a function to all incoming edges in a
mockturtlenetwork.- Template Parameters:
Ntk –
mockturtlenetwork type.Fn – Unary function type that takes a
mockturtle::edge<Ntk>object as parameter.
- Parameters:
ntk – Network to iterate over.
n – Node of
ntkwhose incoming edges are to be considered.fn – Function object to apply to each incoming edge of
ninntk.
-
template<typename Ntk>
std::vector<mockturtle::node<Ntk>> fiction::networks::fanouts(const Ntk &ntk, const mockturtle::node<Ntk> &n) noexcept¶ Returns a vector of all fanout nodes of some given network node.
- Template Parameters:
Ntk –
mockturtlenetwork type.- Parameters:
ntk – Network in which the fanouts are to be gathered.
n – Node whose fanouts are desired.
- Returns:
A vector of all outgoing nodes directly adjacent to
ninntk.
-
template<typename Ntk>
struct fanin_container¶ Container that stores fanins of a node in a network, including whether one of them is a constant.
Note that this container assumes that each node has a maximum of one constant fanin.
- Template Parameters:
Ntk –
mockturtlenetwork type.
-
template<typename Ntk>
fanin_container<Ntk> fiction::networks::fanins(const Ntk &ntk, const mockturtle::node<Ntk> &n) noexcept¶ Returns a fanin container filled with all fanin nodes of some given network node.
Note that this function assumes that each node has a maximum of one constant fanin.
- Template Parameters:
Ntk –
mockturtlenetwork type.- Parameters:
ntk – Network in which the fanins are to be gathered.
n – Node whose fanins are desired.
- Returns:
A container of all incoming nodes directly adjacent to
ninntk.
-
template<typename Ntk>
uint32_t fiction::networks::num_constant_fanins(const Ntk &ntk, const mockturtle::node<Ntk> &n) noexcept¶ Computes the number of constant fanin nodes of some network node
n.- Template Parameters:
Ntk –
mockturtlenetwork type.- Parameters:
ntk – Network in which the constant fanins are to be counted.
n – Node whose constant fanins are to be counted.
- Returns:
Number of constant fanins to
ninntk.
-
class high_degree_fanin_exception : public std::invalid_argument¶
Exception class that can be thrown if some network exceeds a legal number of fanins.
Public Functions
-
inline high_degree_fanin_exception()¶
-
inline high_degree_fanin_exception()¶
-
template<typename Ntk>
bool fiction::networks::has_high_degree_fanin_nodes(const Ntk &ntk, const uint32_t threshold = 2) noexcept¶ Checks if a given network exceeds a given fanin threshold in any of its nodes.
- Template Parameters:
Ntk –
mockturtlenetwork type.- Parameters:
ntk – Network to check.
threshold – Maximum number of legal fanins.
- Returns:
trueiff any node inntkexceedsthresholdfanins.
-
template<typename Ntk>
struct fanin_edge_container¶ Container that stores fanin edges of a node in a network, including whether one of them is a constant.
- Template Parameters:
Ntk –
mockturtlenetwork type.
-
template<typename Ntk>
fanin_edge_container<Ntk> fiction::networks::fanin_edges(const Ntk &ntk, const mockturtle::node<Ntk> &n) noexcept¶ Returns a fanin edge container filled with all fanin edges
(fanin, node)of some given network node.- Template Parameters:
Ntk –
mockturtlenetwork type.- Parameters:
ntk – Network in which the fanin edges are to be gathered.
n – Node whose fanins are desired.
- Returns:
A container of all incoming edges
(fanin, n)inntk.
-
template<typename Ntk>
bool fiction::networks::has_incoming_primary_input(const Ntk &ntk, const mockturtle::node<Ntk> &n) noexcept¶ Checks if a given node in a given network has fanins that are primary inputs.
- Template Parameters:
Ntk –
mockturtlenetwork type.- Parameters:
ntk – Network to check in.
n – Node to check.
- Returns:
trueiff any ofn’s fanins are primary inputs.
-
template<typename Ntk>
std::vector<edge_path<Ntk>> fiction::networks::all_incoming_edge_paths(const Ntk &ntk, const mockturtle::node<Ntk> &n) noexcept¶ Returns a vector of all possible paths to reach the given node from the primary inputs within the given network.
Each node without predecessors is considered a terminal and a path is defined as a sequence of edges.
- Parameters:
ntk – Network containing the node.
n – Node whose paths are desired.
- Returns:
A vector of all possible edge paths leading from terminals to
n.
-
template<typename Ntk>
std::vector<uint32_t> fiction::networks::inverse_levels(const Ntk &ntk) noexcept¶ A clumsy implementation that returns the inverse level of each node in a given network. Its behavior is similar to
mockturtle::depth_viewbut starting from the primary outputs instead of the primary inputs. An implementation along the lines ofinv_depth_viewwould be a lot more sophisticated and desirable, but this quick hack does the job well so far. If anyone wants to build aninv_depth_view, please be my guest.- Template Parameters:
Ntk –
mockturtlenetwork type.- Parameters:
ntk – The network whose inverse levels are desired.
- Returns:
A vector of inverse levels for each node where
ntk.node_to_index(n)is the position wheren’s inverse level is stored.
- class high_degree_fanin_exception¶
- has_high_degree_fanin_nodes(ntk: technology_network, threshold: int = 2) bool¶
Checks if a given network exceeds a given fanin threshold in any of its nodes.
- Parameters:
ntk – Network to check.
threshold – Maximum number of legal fanins.
- Template Args:
Ntk –
mockturtlenetwork type.- Returns:
trueiff any node inntkexceedsthresholdfanins.