Skip to content

Unify the three evaluate() overloads via a descriptor template #6

Description

@MoonFlowww

Motivation

Nott's public API promise is a clean, safe surface. Right now core.hpp exposes three structurally identical evaluate() overloads that differ only in descriptor type. Adding a fourth evaluation mode (e.g., regression, ranking) requires copy-pasting the same boilerplate again. The /// TODO: do it cleaner comment at line 2398 acknowledges this debt.

Current State

src/core.hpp:2385–2423 has three overloads:

auto evaluate(..., Evaluation::ClassificationDescriptor, ...)      -> ClassificationReport;
auto evaluate(..., Evaluation::MultiClassificationDescriptor, ...)  -> ClassificationReport; // TODO: do it cleaner
auto evaluate(..., Evaluation::SegmentationDescriptor, ...)         -> ClassificationReport;

All three bodies are identical:

return Evaluation::Evaluate(*this, inputs, targets, descriptor, metrics, options);

~30 lines of pure duplication with no behavioural difference at this layer.

Proposed Change

Collapse to a single constrained template:

template<Evaluation::EvaluationDescriptor DescriptorT>
auto evaluate(torch::Tensor inputs,
              torch::Tensor targets,
              DescriptorT   descriptor,
              std::vector<Metric::Classification::Descriptor> metrics,
              Evaluation::Options options = {}) -> Evaluation::ClassificationReport
{
    return Evaluation::Evaluate(*this,
        std::move(inputs), std::move(targets),
        descriptor, std::move(metrics), options);
}

Where Evaluation::EvaluationDescriptor is a concept:

template<typename T>
concept EvaluationDescriptor =
    std::same_as<T, Evaluation::ClassificationDescriptor>      ||
    std::same_as<T, Evaluation::MultiClassificationDescriptor> ||
    std::same_as<T, Evaluation::SegmentationDescriptor>;

Acceptance Criteria

  • Single evaluate() template replaces the three overloads
  • EvaluationDescriptor concept defined and constrains the template
  • Passing an unsupported descriptor type produces a clear compile-time error
  • /// TODO: do it cleaner comment removed
  • All existing call sites compile without changes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions