MCPcopy Create free account
hub / github.com/KDE/labplot / rsample

Function rsample

src/backend/gsl/ExpressionParser.cpp:611–631  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

609}
610
611double rsample(const std::string_view& variable, const std::weak_ptr<Payload> payload) {
612 const auto p = std::dynamic_pointer_cast<PayloadExpressionParser>(payload.lock());
613 if (!p) {
614 assert(p); // Debug build
615 return NAN;
616 }
617
618 // random value of all rows
619 auto size = p->xVectors->at(0)->size();
620
621 std::random_device rd;
622 std::mt19937 gen(rd());
623 std::uniform_int_distribution<> dist(0, size - 1);
624 double value;
625 do { // loop until valid index generated
626 int randomIndex = dist(gen);
627 value = cell(randomIndex + 1, variable, payload);
628 } while (std::isnan(value));
629
630 return value;
631}
632
633void ExpressionParser::setSpecialFunctionValuePayload(const char* function_name, func_tValuePayload funct, std::shared_ptr<Payload> payload) {
634 Parser::set_specialfunctionValuePayload(function_name, funct, payload);

Callers

nothing calls this directly

Calls 2

cellFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected