jorisvandenbossche commented on code in PR #14696:
URL: https://github.com/apache/arrow/pull/14696#discussion_r1035980132
##########
cpp/src/arrow/compute/kernels/scalar_nested.cc:
##########
@@ -96,6 +97,22 @@ std::string ToString(const std::optional<T>& o) {
return o.has_value() ? ToChars(*o) : "(nullopt)";
}
+int64_t MaxSliceLength(const int64_t start, const int64_t stop, const int64_t
step) {
+ const auto startf = static_cast<float>(start);
+ const auto stopf = static_cast<float>(stop);
+ const auto stepf = static_cast<float>(step);
+
+ if (stopf - startf <= stepf) {
+ return 1;
+ }
+
+ auto length = static_cast<int64_t>(std::floor((stopf - startf) / stepf));
+ if (fmod(static_cast<float>(length), stepf) > 0.0) {
+ ++length;
+ }
+ return length;
Review Comment:
> More tests added, let me know if you see any specific combinations you'd
like to see.
I think you will need to add a longer test list to cover all cases. For
example the (1, 3, 2) and (0, 2, 3) cases you added both already shortcut in
the `if (stopf - startf <= stepf) { return 1; }` case, and so don't actually
cover the floor/fmod logic.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]