fridom.framework.utils.numpy_utils.to_numpy#
- fridom.framework.utils.numpy_utils.to_numpy(obj: object, memo: dict | None = None, _nil: list = None) object[source]#
Creates a deep copy of an object with all arrays converted to numpy.
Description#
Some functions require numpy arrays as input, as for example plotting with matplotlib. This function creates a deep copy of an object where all arrays are converted to numpy arrays. This is computationally expensive and should be used with care. Objects that should only be converted once, as for example the grid variables which are usually static, i.e. they do not change during the simulation, should have a _cpu attribute. If the _cpu attribute is None, the object is converted to numpy and cached in the _cpu attribute. If the _cpu attribute is not None, the cached numpy array is returned. Objects that require a custom conversion should implement a __to_numpy__ method that returns the converted object.
Parameters#
- objAny
The object to convert to numpy.
- memodict (default=None)
A dictionary to store the converted objects (used for recursion).
Returns#
- Any
The object with all arrays converted to numpy.