Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding bounds check for advanced indexing #397

Merged
merged 6 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
1 change: 1 addition & 0 deletions cunumeric/deferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def _zip_indices(self, start_index, arrays):

# call ZIP function to combine index arrays into a singe array
task = self.context.create_task(CuNumericOpCode.ZIP)
task.throws_exception(IndexError)
task.add_output(output_arr.base)
task.add_scalar_arg(self.ndim, ty.int64) # N of points in Point<N>
task.add_scalar_arg(key_dim, ty.int64) # key_dim
Expand Down
3 changes: 3 additions & 0 deletions src/cunumeric/index/zip.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class ZipTask : public CuNumericTask<ZipTask> {

constexpr coord_t compute_idx(coord_t index, coord_t dim)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the variable name dim is very confusing. I believe you meant extent, right? dim seems synonymous with axis in other contexts, so let's change this.

{
// bounds checking
if ((index < 0 && index + dim < 0) || (index >= 0 && index >= dim))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually rewrite this function to something like this:

coord_t sanitized_index = index < 0 ? index + dim : index;
if (sanitized_index < 0 || sanitized_index >= extent) throw ...
return sanitized_index;

throw legate::TaskException("index is out of bounds in index array");
return index < 0 ? index + dim : index;
}

Expand Down