Skip to content

Commit

Permalink
Fix reorder to avoid eval on copied array instead of input array
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
umar456 committed Aug 19, 2023
1 parent b2f1840 commit 23ee065
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/api/c/reorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ using std::swap;

template<typename T>
static inline af_array reorder(const af_array in, const af::dim4 &rdims0) {
Array<T> In = getArray<T>(in);
Array<T> In = detail::createEmptyArray<T>(af::dim4(0));
dim4 rdims = rdims0;

if (rdims[0] == 1 && rdims[1] == 0) {
In = transpose(In, false);
In = transpose(getArray<T>(in), false);
std::swap(rdims[0], rdims[1]);
} else {
In = getArray<T>(in);
}
const dim4 idims = In.dims();
const dim4 istrides = In.strides();
Expand All @@ -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<T> &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);
Expand Down

0 comments on commit 23ee065

Please sign in to comment.