Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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.
  • Loading branch information
umar456 committed Aug 19, 2023
commit 6cedca94004319faeb14fa204a1d94f7ddf1fe35
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