From 203af1ea3eb1e5d537b0fdb48dc990b3c8bf9bc7 Mon Sep 17 00:00:00 2001 From: Umar Arshad Date: Fri, 18 Aug 2023 20:34:31 -0400 Subject: [PATCH] Fix reorder to avoid eval on copied array instead of input array The reorder funciton was copying the Array object internally and then the other operations were performed on the copy. This causes the eval to be performed on the copied array instead of the input array. --- src/api/c/reorder.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/api/c/reorder.cpp b/src/api/c/reorder.cpp index b283c800bf..556e1f0e20 100644 --- a/src/api/c/reorder.cpp +++ b/src/api/c/reorder.cpp @@ -33,12 +33,14 @@ using std::swap; template static inline af_array reorder(const af_array in, const af::dim4 &rdims0) { - Array In = getArray(in); + Array In = detail::createEmptyArray(af::dim4(0)); dim4 rdims = rdims0; if (rdims[0] == 1 && rdims[1] == 0) { - In = transpose(In, false); + In = transpose(getArray(in), false); std::swap(rdims[0], rdims[1]); + } else { + In = getArray(in); } const dim4 idims = In.dims(); const dim4 istrides = In.strides(); @@ -48,8 +50,7 @@ static inline af_array reorder(const af_array in, const af::dim4 &rdims0) { af_array out; if (rdims[0] == 0 && rdims[1] == 1 && rdims[2] == 2 && rdims[3] == 3) { - const Array &Out = In; - out = getHandle(Out); + out = getHandle(In); } else if (rdims[0] == 0) { dim4 odims = dim4(1, 1, 1, 1); dim4 ostrides = dim4(1, 1, 1, 1);