Skip to content

Commit 3d79018

Browse files
committed
Partition range descriptors for vector based slicing
1 parent 8f4ca06 commit 3d79018

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

mdio/dataset.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,14 @@ class Dataset {
626626
}
627627

628628
if (slices.size() > internal::kMaxNumSlices) {
629-
return absl::InvalidArgumentError(
630-
absl::StrCat("Too many slices provided or implicitly generated. "
631-
"Maximum number of slices is ",
632-
internal::kMaxNumSlices, " but ", slices.size(),
633-
" were provided.\n\tUse -DMAX_NUM_SLICES cmake flag to "
634-
"increase the maximum number of slices."));
629+
std::size_t halfElements = slices.size() / 2;
630+
if (halfElements % 2 != 0) {
631+
halfElements += 1;
632+
}
633+
std::vector<RangeDescriptor<Index>> firstHalf(slices.begin(), slices.begin() + halfElements);
634+
std::vector<RangeDescriptor<Index>> secondHalf(slices.begin() + halfElements, slices.end());
635+
MDIO_ASSIGN_OR_RETURN(auto ds, isel(firstHalf));
636+
return ds.isel(secondHalf);
635637
}
636638

637639
std::vector<RangeDescriptor<Index>> slicesCopy = slices;
@@ -1044,9 +1046,11 @@ class Dataset {
10441046
std::string(coord_desc.label.label()) + "'");
10451047
}
10461048

1049+
// TODO(BrianMichell): Coalesce the slices into fewer descriptors.
1050+
10471051
MDIO_ASSIGN_OR_RETURN(auto ds, isel(elementwiseSlices));
1052+
// TODO(BrianMichell): Make this method more async friendly.
10481053
return tensorstore::ReadyFuture<Dataset>(std::move(ds));
1049-
// return isel(elementwiseSlices);
10501054
}
10511055

10521056
/**

mdio/variable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,8 @@ class Variable {
10021002
}
10031003

10041004
if (slices.size() > internal::kMaxNumSlices) {
1005+
// We are expecting the only entry point for this method to be from the Dataset::isel method.
1006+
// That method should handle the partitioning of the slices.
10051007
return absl::InvalidArgumentError(
10061008
absl::StrCat("Too many slices provided or implicitly generated. "
10071009
"Maximum number of slices is ",

0 commit comments

Comments
 (0)