diff --git a/arraycontext/impl/pytato.py b/arraycontext/impl/pytato.py index 76a1143680146ae89b2529545b42e19d472b1b8d..43138ea1022fd57c2f5db64a02eb2b50d01c42f8 100644 --- a/arraycontext/impl/pytato.py +++ b/arraycontext/impl/pytato.py @@ -148,6 +148,28 @@ class _PytatoFakeNumpyNamespace(BaseFakeNumpyNamespace): import pytato as pt return rec_multimap_array_container(pt.arctan2, y, x) + def ravel(self, a, order="C"): + def _rec_ravel(a): + import pytato as pt + if order in "FC": + return pt.reshape(a, (-1,), order=order) + elif order == "A": + if a.flags.f_contiguous: + return pt.reshape(a, (-1,), order="F") + elif a.flags.c_contiguous: + return pt.reshape(a, (-1,), order="C") + else: + raise ValueError("For `order='A'`, array should be either" + " F-contiguous or C-contiguous.") + elif order == "K": + raise NotImplementedError("PytatoArrayContext.np.ravel not " + "implemented for 'order=K'") + else: + raise ValueError("`order` can be one of 'F', 'C', 'A' or 'K'. " + f"(got {order})") + + return rec_map_array_container(_rec_ravel, a) + # }}}