From 64b86cfcca88f66914a797f9eb65cbcba2cf857e Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni <15399010+kaushikcfd@users.noreply.github.com> Date: Sun, 13 Jun 2021 23:18:17 -0500 Subject: [PATCH] cl.array.Array.ravel: takes order as an argument (#485) * cl.array.ravel: take order as an argument * adds test ravel --- pyopencl/array.py | 4 ++-- test/test_array.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pyopencl/array.py b/pyopencl/array.py index 402426a8..3a1f1090 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -1759,9 +1759,9 @@ class Array: data=self.base_data, offset=self.offset, shape=shape, strides=tuple(newstrides)) - def ravel(self): + def ravel(self, order="C"): """Returns flattened array containing the same data.""" - return self.reshape(self.size) + return self.reshape(self.size, order=order) def view(self, dtype=None): """Returns view of array with the same data. If *dtype* is different diff --git a/test/test_array.py b/test/test_array.py index f03640f6..9ff806e3 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -1583,6 +1583,26 @@ def test_slice_copy(ctx_factory): y.copy() +@pytest.mark.parametrize("order", ("C", "F")) +def test_ravel(ctx_factory, order): + ctx = ctx_factory() + cq = cl.CommandQueue(ctx) + + x = np.random.randn(10, 4) + + if order == "F": + x = np.asfortranarray(x) + elif order == "C": + pass + else: + raise AssertionError + + x_cl = cl.array.to_device(cq, x) + + np.testing.assert_allclose(x_cl.ravel(order=order).get(), + x.ravel(order=order)) + + if __name__ == "__main__": if len(sys.argv) > 1: exec(sys.argv[1]) -- GitLab