Utility functions that cannot be categorised anywhere else.

Class | `multidict` |
A dictionary-like object that is customized to deal with multiple values for the same key. |

Function | `consecutive` |
Returns consecutive pairs of items from the given iterable. |

Function | `dbl` |
Approximates the machine epsilon value for doubles. |

Function | `named` |
Context manager that creates a named temporary file and returns its name. |

Function | `numpy` |
Converts a NumPy array or matrix into a contiguous memoryview object that is suitable to be forwarded to the Graph constructor. |

Function | `rescale` |
Rescales a list of numbers into a given range. |

Function | `safemax` |
Safer variant of max() that returns a default value if the iterable is empty. |

Function | `safemin` |
Safer variant of min() that returns a default value if the iterable is empty. |

Function | `_is` |
Internal function that determines whether igraph is running inside IPython or not. |

Returns consecutive pairs of items from the given iterable.

When `circular` is `True`, the pair consisting of the last
and first elements is also returned.

Example:

>>> list(consecutive_pairs(range(5))) [(0, 1), (1, 2), (2, 3), (3, 4)] >>> list(consecutive_pairs(range(5), circular=True)) [(0, 1), (1, 2), (2, 3), (3, 4), (4, 0)] >>> list(consecutive_pairs([])) [] >>> list(consecutive_pairs([], circular=True)) [] >>> list(consecutive_pairs([0])) [] >>> list(consecutive_pairs([0], circular=True)) [(0, 0)]

def named_temporary_file(*args, **kwds):

Context manager that creates a named temporary file and returns its name.

All parameters are passed on to `tempfile.mkstemp`, see
its documentation for more info.

Converts a NumPy array or matrix into a contiguous memoryview object that is suitable to be forwarded to the Graph constructor.

This is used internally to allow us to use a NumPy array or matrix directly when constructing a Graph.

Rescales a list of numbers into a given range.

`out_range` gives the range of the output values; by default, the minimum
of the original numbers in the list will be mapped to the first element
in the output range and the maximum will be mapped to the second element.
Elements between the minimum and maximum values in the input list will be
interpolated linearly between the first and second values of the output
range.

`in_range` may be used to override which numbers are mapped to the first
and second values of the output range. This must also be a tuple, where
the first element will be mapped to the first element of the output range
and the second element to the second.

If `clamp` is `True`, elements which are outside the given `out_range`
after rescaling are clamped to the output range to ensure that no number
will be outside `out_range` in the result.

If `scale` is not `None`, it will be called for every element of `values`
and the rescaling will take place on the results instead. This can be used,
for instance, to transform the logarithm of the original values instead of
the actual values. A typical use-case is to map a range of values to color
identifiers on a logarithmic scale. Scaling also applies to the `in_range`
parameter if present.

Examples:

>>> rescale(range(5), (0, 8)) [0.0, 2.0, 4.0, 6.0, 8.0] >>> rescale(range(5), (2, 10)) [2.0, 4.0, 6.0, 8.0, 10.0] >>> rescale(range(5), (0, 4), (1, 3)) [-2.0, 0.0, 2.0, 4.0, 6.0] >>> rescale(range(5), (0, 4), (1, 3), clamp=True) [0.0, 0.0, 2.0, 4.0, 4.0] >>> rescale([0]*5, (1, 3)) [2.0, 2.0, 2.0, 2.0, 2.0] >>> from math import log10 >>> rescale([1, 10, 100, 1000, 10000], (0, 8), scale=log10) [0.0, 2.0, 4.0, 6.0, 8.0] >>> rescale([1, 10, 100, 1000, 10000], (0, 4), (10, 1000), scale=log10) [-2.0, 0.0, 2.0, 4.0, 6.0]

Parameters | |

values | Undocumented |

out | the range of output values |

in | the range of the input values; this is the range that is mapped
to out_range. None means to use the minimum and maximum of
the input, respectively. |

clamp | specifies what to do when an input value falls outside in_range.
True means to clamp the value to the bounds of in_range,
False means not to clamp. |

scale | an optional transformation to perform on the input values before mapping them to the output range. |

Safer variant of `max()` that returns a default value if the iterable
is empty.

Example:

>>> safemax([-5, 6, 4]) 6 >>> safemax([]) 0 >>> safemax((), 2) 2