Skip to content

Instantly share code, notes, and snippets.

View Jacob-Stevens-Haas's full-sized avatar
💭
🧟‍♂️

Jacob Stevens-Haas Jacob-Stevens-Haas

💭
🧟‍♂️
  • University of Washington
  • Seattle, Wa
View GitHub Profile
"""Utilities to convert a `dysts` dynamical system object's rhs to SymPy.
This module inspects the source of an object's RHS method (by default
named ``rhs``), parses the function using ``ast``, and converts the
returned expression(s) into SymPy expressions.
The conversion is intentionally conservative and aims to handle common
patterns used in simple rhs implementations, e.g. returning a tuple/list
of arithmetic expressions, using indexing into a state vector (``x[0]``),
and calls to common ``numpy``/``math`` functions (``np.sin``, ``math.exp``, ...).
@Jacob-Stevens-Haas
Jacob-Stevens-Haas / unpacky.py
Created June 25, 2020 16:19
Universal Unsafe Unpacker for Python
# import random
def unsafe_unpacker(obj):
"""A generator that traverses an arbitrarily nested iterable of iterables.
Parameters:
obj (iterable): the nested iterables, e.g. a numpy array of lists of tuples
Returns:
A generator whose items are the ordered collection of any non-iterable found