Skip to main content

src/TransformsV2/algorithms/Temporal/RegisteredTemporalTransforms.cpp

src/TransformsV2/algorithms/Temporal/RegisteredTemporalTransforms.cpp

Namespaces

Name
Neuralyzer
Neuralyzer::Transforms
Neuralyzer::Transforms::V2
Neuralyzer::Transforms::V2::Temporal

Source code

#include "algorithms/Temporal/RegisteredTemporalTransforms.hpp"

#include "AnalogTimeSeries/Analog_Time_Series.hpp"
#include "DigitalTimeSeries/Digital_Event_Series.hpp"
#include "DigitalTimeSeries/EventWithId.hpp"
#include "TimeFrame/ClockTicks.hpp"
#include "algorithms/Temporal/NormalizeTime.hpp"
#include "core/ElementRegistry.hpp"
#include "extension/ParameterBinding.hpp"
#include "io/PipelineLoader.hpp"

namespace Neuralyzer::Transforms::V2::Temporal {

// Use the registration helper from Examples namespace
using Neuralyzer::Transforms::V2::Examples::registerPipelineStepFactoryFor;

// ============================================================================
// Static Initialization
// ============================================================================

namespace {

static RegisterBindingApplicator<NormalizeTimeParamsV2> const register_binding_applicator_v2;

bool const init_pipeline_factories = []() {
    registerPipelineStepFactoryFor<NormalizeTimeParamsV2>();
    registerPipelineStepFactoryFor<ShiftDigitalEventSeriesParams>();
    return true;
}();

template<typename In, typename Out, typename Params>
struct RegisterTransform {
    RegisterTransform(
            std::string name,
            Out (*func)(In const &, Params const &),
            TransformMetadata metadata) {
        metadata.name = name;
        metadata.input_type = typeid(In);
        metadata.output_type = typeid(Out);
        metadata.params_type = typeid(Params);

        ElementRegistry::instance().registerTransform<In, Out, Params>(
                name,
                func,
                std::move(metadata));
    }
};

// ============================================================================
// V2 Value Projection Registrations (Using param bindings)
// ============================================================================

auto const register_normalize_time_value_v2 = RegisterTransform<
        TimeFrameIndex,
        float,
        NormalizeTimeParamsV2>(
        "NormalizeTimeValueV2",
        normalizeTimeValueV2,
        TransformMetadata{
                .name = "NormalizeTimeValueV2",
                .description = "Compute normalized time offset as float (V2 - uses param bindings)",
                .category = "Temporal",
                .input_type = typeid(TimeFrameIndex),
                .output_type = typeid(float),
                .params_type = typeid(NormalizeTimeParamsV2),
                .lineage_type = TransformLineageType::None,
                .input_type_name = "TimeFrameIndex",
                .output_type_name = "float",
                .params_type_name = "NormalizeTimeParamsV2",
                .is_expensive = false,
                .is_deterministic = true,
                .supports_cancellation = false});

auto const register_normalize_event_time_value_v2 = RegisterTransform<
        EventWithId,
        float,
        NormalizeTimeParamsV2>(
        "NormalizeEventTimeValueV2",
        normalizeEventTimeValueV2,
        TransformMetadata{
                .name = "NormalizeEventTimeValueV2",
                .description = "Compute normalized event time as float (V2 - uses param bindings)",
                .category = "Temporal",
                .input_type = typeid(EventWithId),
                .output_type = typeid(float),
                .params_type = typeid(NormalizeTimeParamsV2),
                .lineage_type = TransformLineageType::None,
                .input_type_name = "EventWithId",
                .output_type_name = "float",
                .params_type_name = "NormalizeTimeParamsV2",
                .is_expensive = false,
                .is_deterministic = true,
                .supports_cancellation = false});

auto const register_normalize_clock_ticks_value_v2 = RegisterTransform<
        ClockTicks,
        ClockTicks,
        NormalizeTimeParamsV2>(
        "NormalizeClockTicksValueV2",
        normalizeClockTicksValueV2,
        TransformMetadata{
                .name = "NormalizeClockTicksValueV2",
                .description = "Compute normalized clock-tick time offset (V2 - uses param bindings)",
                .category = "Temporal",
                .input_type = typeid(ClockTicks),
                .output_type = typeid(ClockTicks),
                .params_type = typeid(NormalizeTimeParamsV2),
                .lineage_type = TransformLineageType::None,
                .input_type_name = "ClockTicks",
                .output_type_name = "ClockTicks",
                .params_type_name = "NormalizeTimeParamsV2",
                .is_expensive = false,
                .is_deterministic = true,
                .supports_cancellation = false});

// ClockTicksWithId is intentionally not registered as an Element transform.
// ElementVariant contains ClockTicks, not ClockTicksWithId; bindValueProjectionV2
// extracts .time() from ClockTicksWithId view elements before running the
// TransformPipeline. This preserves EntityId access outside the pipeline while
// keeping the pipeline's temporal normalize transform focused on ClockTicks.

auto const register_normalize_sample_time_value_v2 = RegisterTransform<
        AnalogTimeSeries::TimeValuePoint,
        float,
        NormalizeTimeParamsV2>(
        "NormalizeSampleTimeValueV2",
        normalizeSampleTimeValueV2,
        TransformMetadata{
                .name = "NormalizeSampleTimeValueV2",
                .description = "Compute normalized sample time as float (V2 - uses param bindings)",
                .category = "Temporal",
                .input_type = typeid(AnalogTimeSeries::TimeValuePoint),
                .output_type = typeid(float),
                .params_type = typeid(NormalizeTimeParamsV2),
                .lineage_type = TransformLineageType::None,
                .input_type_name = "TimeValuePoint",
                .output_type_name = "float",
                .params_type_name = "NormalizeTimeParamsV2",
                .is_expensive = false,
                .is_deterministic = true,
                .supports_cancellation = false});

auto const register_normalize_digital_event_series_relative = RegisterContainerTransform<
        DigitalEventSeries,
        DigitalEventSeries,
        NormalizeTimeParamsV2>(
        "NormalizeDigitalEventSeriesRelative",
        normalizeDigitalEventSeriesRelative,
        ContainerTransformMetadata{
                .name = "NormalizeDigitalEventSeriesRelative",
                .description = "Normalize a DigitalEventSeries to relative clock-tick event times",
                .category = "Temporal",
                .input_container_type = typeid(DigitalEventSeries),
                .output_container_type = typeid(DigitalEventSeries),
                .params_type = typeid(NormalizeTimeParamsV2),
                .input_type_name = "DigitalEventSeries",
                .output_type_name = "DigitalEventSeries",
                .params_type_name = "NormalizeTimeParamsV2",
                .is_expensive = false,
                .is_deterministic = true,
                .supports_cancellation = true});

auto const register_shift_digital_event_series = RegisterContainerTransform<
        DigitalEventSeries,
        DigitalEventSeries,
        ShiftDigitalEventSeriesParams>(
        "ShiftDigitalEventSeries",
        shiftDigitalEventSeries,
        ContainerTransformMetadata{
                .name = "ShiftDigitalEventSeries",
                .description = "Shift every DigitalEventSeries event by a fixed clock-tick offset",
                .category = "Temporal",
                .input_container_type = typeid(DigitalEventSeries),
                .output_container_type = typeid(DigitalEventSeries),
                .params_type = typeid(ShiftDigitalEventSeriesParams),
                .input_type_name = "DigitalEventSeries",
                .output_type_name = "DigitalEventSeries",
                .params_type_name = "ShiftDigitalEventSeriesParams",
                .is_expensive = false,
                .is_deterministic = true,
                .supports_cancellation = true});

}// anonymous namespace

// ============================================================================
// Public Registration Function
// ============================================================================

void registerTemporalTransforms() {
    // Transforms are already registered via static initialization above.
    // This function exists for:
    // 1. Explicit registration timing control in tests
    // 2. Documentation of what gets registered
    // 3. Forcing the translation unit to be linked

    // Force instantiation of static registrations (V1)
    (void) init_pipeline_factories;

    // Force instantiation of V2 registrations (param bindings)
    (void) register_normalize_time_value_v2;
    (void) register_normalize_event_time_value_v2;
    (void) register_normalize_clock_ticks_value_v2;
    (void) register_normalize_sample_time_value_v2;
    (void) register_normalize_digital_event_series_relative;
    (void) register_shift_digital_event_series;
    (void) register_binding_applicator_v2;
}

}// namespace Neuralyzer::Transforms::V2::Temporal

Updated on 2026-11-13 at 20:25:44 +0000