MCPcopy Create free account
hub / github.com/apache/arrow / MinMax

Method MinMax

r/src/altrep.cpp:341–377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

339
340 template <bool Min>
341 static SEXP MinMax(SEXP alt, Rboolean narm) {
342 if (IsMaterialized(alt)) {
343 return nullptr;
344 }
345
346 using data_type = typename std::conditional<sexp_type == REALSXP, double, int>::type;
347 using scalar_type =
348 typename std::conditional<sexp_type == INTSXP, Int32Scalar, DoubleScalar>::type;
349
350 const auto& chunked_array = GetChunkedArray(alt);
351 bool na_rm = narm == TRUE;
352 auto n = chunked_array->length();
353 auto null_count = chunked_array->null_count();
354 if ((na_rm || n == 0) && null_count == n) {
355 if (Min) {
356 Rf_warning("no non-missing arguments to min; returning Inf");
357 return Rf_ScalarReal(R_PosInf);
358 } else {
359 Rf_warning("no non-missing arguments to max; returning -Inf");
360 return Rf_ScalarReal(R_NegInf);
361 }
362 }
363 if (!na_rm && null_count > 0) {
364 return cpp11::as_sexp(cpp11::na<data_type>());
365 }
366
367 auto options = NaRmOptions(na_rm);
368
369 const auto& minmax = ValueOrStop(
370 arrow::compute::CallFunction("min_max", {chunked_array}, options.get()));
371 const auto& minmax_scalar =
372 internal::checked_cast<const StructScalar&>(*minmax.scalar());
373
374 const auto& result_scalar = internal::checked_cast<const scalar_type&>(
375 *ValueOrStop(minmax_scalar.field(Min ? "min" : "max")));
376 return cpp11::as_sexp(result_scalar.value);
377 }
378
379 static SEXP Min(SEXP alt, Rboolean narm) { return MinMax<true>(alt, narm); }
380

Callers

nothing calls this directly

Calls 8

as_sexpFunction · 0.85
ValueOrStopFunction · 0.85
CallFunctionFunction · 0.85
lengthMethod · 0.45
null_countMethod · 0.45
getMethod · 0.45
scalarMethod · 0.45
fieldMethod · 0.45

Tested by

no test coverage detected