Skip to content

Commit

Permalink
Fixes Bears-R-Us#3682: repeat incorrect results with multi-locale (Be…
Browse files Browse the repository at this point in the history
…ars-R-Us#3683)

This PR fixes Bears-R-Us#3682. It was only using values and repeats from locale 0, which was a pretty good hint to the problem. I added the `localsubdom.low` when indexing into the flat arrays to account for the the indices handled by previous locales

Co-authored-by: Tess Hayes <stress-tess@users.noreply.github.com>
  • Loading branch information
stress-tess and stress-tess authored Aug 20, 2024
1 parent c452ea3 commit 76cde6c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/ManipulationMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -933,11 +933,11 @@ module ManipulationMsg {
const lsd = aFlat.localSubdomain(),
indicesPerTask = lsd.size / nTasksPerLoc;
coforall tid in 0..<nTasksPerLoc with (ref nRepsPerTask) {
const startIdx = tid * indicesPerTask,
stopIdx = if tid == nTasksPerLoc - 1 then lsd.size else (tid + 1) * indicesPerTask;
const startIdx = tid * indicesPerTask + lsd.low,
stopIdx = if tid == nTasksPerLoc - 1 then lsd.high else indicesPerTask + startIdx - 1;

var sum = 0;
for i in startIdx..<stopIdx do
for i in startIdx..stopIdx do
sum += eRepeats.a[i];
nRepsPerTask[loc.id][tid] = sum;
}
Expand All @@ -959,13 +959,12 @@ module ManipulationMsg {
// its repeated elements
const taskStarts = ((+ scan nRepsPerTask[loc.id]) - nRepsPerTask[loc.id]) + locStarts[loc.id];
coforall tid in 0..<nTasksPerLoc {
const startIdx = tid * indicesPerTask,
stopIdx = if tid == nTasksPerLoc - 1 then lsd.size else (tid + 1) * indicesPerTask;
const startIdx = tid * indicesPerTask + lsd.low,
stopIdx = if tid == nTasksPerLoc - 1 then lsd.high else indicesPerTask + startIdx - 1;

// copy this task's repeated elements into the output array
var outStart = taskStarts[tid];

for i in startIdx..<stopIdx {
for i in startIdx..stopIdx {
eOut.a[outStart..#eRepeats.a[i]] = aFlat[i];
outStart += eRepeats.a[i];
}
Expand Down
2 changes: 0 additions & 2 deletions tests/array_api/array_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,6 @@ def test_stack_unstack(self):
def test_tile(self):
a = randArr((2, 3))

print(a)

for reps in [(2, 1), (1, 2), (2, 2), (1, 1, 3), (3,)]:
at = xp.tile(a, reps)
npat = np.tile(np.asarray(a), reps)
Expand Down

0 comments on commit 76cde6c

Please sign in to comment.