Skip to main content

AnalogTimeSeries

AnalogTimeSeries

The AnalogTimeSeries class. More…

#include <Analog_Time_Series.hpp>

Inherits from ObserverData

Public Classes

Name
struct DataTraits
Type traits for AnalogTimeSeries.
struct TimeValuePoint
Data structure representing a single time-value point.
class TimeIndexRange
Time index range abstraction that handles both dense and sparse storage.
struct TimeValueSpanPair
Paired span and time iterator for zero-copy time-value access.

Public Functions

Name
AnalogTimeSeries()
Default constructor.
AnalogTimeSeries(std::vector< float > analog_vector, std::vector< TimeFrameIndex > time_vector)
Constructor for AnalogTimeSeries from a vector of floats and a vector of TimeFrameIndex values.
AnalogTimeSeries(std::map< int, float > analog_map)
Constructor for AnalogTimeSeries from a map of int to float.
AnalogTimeSeries(std::vector< float > analog_vector, size_t num_samples)
Constructor for AnalogTimeSeries from a vector of floats and a number of samples.
template <std::ranges::input_range R>
AnalogTimeSeries(R && time_value_pairs)
size_t getNumSamples() const
std::span< float const > getAnalogTimeSeries() const
Get a span over the analog data values.
std::span< float const > getDataInTimeFrameIndexRange(TimeFrameIndex start_time, TimeFrameIndex end_time) const
Get a span (view) of data values within a TimeFrameIndex range.
std::span< float const > getDataInTimeFrameIndexRange(TimeFrameIndex start_time, TimeFrameIndex end_time, TimeFrame const * source_timeFrame) const
Get a span (view) of data values within a TimeFrameIndex range, with timeframe conversion.
auto view() const
Get a std::ranges compatible view of all samples as TimeValuePoint.
auto viewValues() const
Get a std::ranges compatible view of just the values (no time info).
auto viewTimeValueRange(DataArrayIndex start_index, DataArrayIndex end_index) const
Get time-value pairs in a TimeFrameIndex range as a view.
auto getTimeValueRangeInTimeFrameIndexRange(TimeFrameIndex start_time, TimeFrameIndex end_time) const
Get time-value pairs as a range for convenient iteration.
auto getTimeValueRangeInTimeFrameIndexRange(TimeFrameIndex start_time, TimeFrameIndex end_time, TimeFrame const & source_timeFrame) const
Get time-value pairs as a range with timeframe conversion.
TimeValueSpanPair getTimeValueSpanInTimeFrameIndexRange(TimeFrameIndex start_time, TimeFrameIndex end_time) const
Get time-value pairs as span and time iterator for zero-copy access.
TimeValueSpanPair getTimeValueSpanInTimeFrameIndexRange(TimeFrameIndex start_time, TimeFrameIndex end_time, TimeFrame const * source_timeFrame) const
Get time-value pairs with timeframe conversion.
auto getAllSamples() const
std::vector< TimeFrameIndex > getTimeSeries() const
Get the time indices as a vector.
std::shared_ptr< TimeIndexStorage > const & getTimeStorage() const
Get a const reference to the time index storage.
void setTimeFrame(std::shared_ptr< TimeFrame > time_frame)
Set the time frame.
std::shared_ptr< TimeFrame > getTimeFrame() const
Get the time frame.
auto elements() const
Get a view of (TimeFrameIndex, float) pairs.
auto elementsView() const
Get a view of TimeValuePoint objects (concept-compliant).
std::optional< float > getAtTime(TimeFrameIndex time) const
Get value at specific time.
std::shared_ptr< AnalogTimeSeries > materialize() const
std::shared_ptr< AnalogTimeSeries > createMemoryMapped(MmapStorageConfig config, std::vector< TimeFrameIndex > time_vector)
template <std::ranges::random_access_range ViewType>
std::shared_ptr< AnalogTimeSeries >
createFromView(ViewType view, std::shared_ptr< TimeIndexStorage > time_storage)
Create AnalogTimeSeries from a lazy view.
std::shared_ptr< AnalogTimeSeries > createView(std::shared_ptr< AnalogTimeSeries const > const & source, TimeFrameIndex start_time, TimeFrameIndex end_time)
std::shared_ptr< AnalogTimeSeries > createFromStorage(AnalogDataStorageWrapper storage, std::shared_ptr< TimeIndexStorage > time_storage)
Create an AnalogTimeSeries from a custom storage backend.

Additional inherited members

Public Classes inherited from ObserverData

Name
struct ObserverEntry
Entry in the observer map.

Public Types inherited from ObserverData

Name
using std::function< void()> ObserverCallback
Type alias for observer callback functions.
using int CallbackID
Type alias for callback identifiers.

Public Functions inherited from ObserverData

Name
ObserverData(std::string name =“UnnamedObservable”)
CallbackID addObserver(ObserverCallback callback, std::string name =“Anonymous”)
Register a new observer callback.
void notifyObservers()
Notify all registered observers.
void removeObserver(CallbackID id)
Remove a previously registered observer.

Detailed Description

class AnalogTimeSeries;

The AnalogTimeSeries class.

Analog time series is used for storing continuous data The data may be sampled at irregular intervals as long as the time vector is provided

Public Functions Documentation

function AnalogTimeSeries

AnalogTimeSeries()

Default constructor.

This constructor creates an empty AnalogTimeSeries with no data

function AnalogTimeSeries

explicit AnalogTimeSeries(
    std::vector< float > analog_vector,
    std::vector< TimeFrameIndex > time_vector
)

Constructor for AnalogTimeSeries from a vector of floats and a vector of TimeFrameIndex values.

Parameters:

  • analog_vector Vector of floats
  • time_vector Vector of TimeFrameIndex values

See:

Use this constructor when the data is sampled at irregular intervals

function AnalogTimeSeries

explicit AnalogTimeSeries(
    std::map< int, float > analog_map
)

Constructor for AnalogTimeSeries from a map of int to float.

Parameters:

  • analog_map Map of int to float

See:

The key in the map is assumed to the be TimeFrameIndex for each sample

function AnalogTimeSeries

explicit AnalogTimeSeries(
    std::vector< float > analog_vector,
    size_t num_samples
)

Constructor for AnalogTimeSeries from a vector of floats and a number of samples.

Parameters:

  • analog_vector Vector of floats
  • num_samples Number of samples

See: AnalogTimeSeries(std::vector analog_vector, std::vector time_vector) for constructors that support irregular sampling

Use this constructor when the data is sampled at regular intervals increasing by 1

function AnalogTimeSeries

template <std::ranges::input_range R>
inline explicit AnalogTimeSeries(
    R && time_value_pairs
)

function getNumSamples

inline size_t getNumSamples() const

function getAnalogTimeSeries

inline std::span< float const > getAnalogTimeSeries() const

Get a span over the analog data values.

See:

Return: std::span view over the analog data values, or empty span if not contiguous

Note: For contiguous storage (vector), this provides zero-copy access. For non-contiguous storage, use getAllSamples() iterator instead.

Returns a span providing a view over the analog time series data values. This method provides efficient read-only access to contiguous data without copying. For non-contiguous storage (e.g., memory-mapped with stride), returns empty span.

function getDataInTimeFrameIndexRange

std::span< float const > getDataInTimeFrameIndexRange(
    TimeFrameIndex start_time,
    TimeFrameIndex end_time
) const

Get a span (view) of data values within a TimeFrameIndex range.

Parameters:

  • start_time The start time (inclusive boundary)
  • end_time The end time (inclusive boundary)

See: findDataArrayIndexGreaterOrEqual() and findDataArrayIndexLessOrEqual() for the underlying boundary logic

Return: std::span view over the data in the specified range

Note:

  • Returns an empty span if no data points fall within the specified range
  • The span is valid as long as the AnalogTimeSeries object exists and is not modified

This function returns a std::span over the data array for all points where TimeFrameIndex >= start_time and TimeFrameIndex <= end_time. The span provides a zero-copy view into the underlying data.

If the exact start_time or end_time don’t exist in the series, it finds the closest available times:

function getDataInTimeFrameIndexRange

std::span< float const > getDataInTimeFrameIndexRange(
    TimeFrameIndex start_time,
    TimeFrameIndex end_time,
    TimeFrame const * source_timeFrame
) const

Get a span (view) of data values within a TimeFrameIndex range, with timeframe conversion.

Parameters:

  • start_time The start time (inclusive boundary)
  • end_time The end time (inclusive boundary)
  • source_timeFrame The timeframe that the start and end times are expressed in

See: findDataArrayIndexGreaterOrEqual() and findDataArrayIndexLessOrEqual() for the underlying boundary logic

Return: std::span view over the data in the specified range

Note:

  • Returns an empty span if no data points fall within the specified range
  • The span is valid as long as the AnalogTimeSeries object exists and is not modified

This function returns a std::span over the data array for all points where TimeFrameIndex >= start_time and TimeFrameIndex <= end_time. The span provides a zero-copy view into the underlying data.

If the exact start_time or end_time don’t exist in the series, it finds the closest available times:

function view

inline auto view() const

Get a std::ranges compatible view of all samples as TimeValuePoint.

Returns a random-access view that synthesizes TimeValuePoint objects on demand. Uses cached pointers for fast-path iteration when storage is contiguous.

function viewValues

inline auto viewValues() const

Get a std::ranges compatible view of just the values (no time info).

Returns a random-access view of float values only, without time frame indices.

function viewTimeValueRange

inline auto viewTimeValueRange(
    DataArrayIndex start_index,
    DataArrayIndex end_index
) const

Get time-value pairs in a TimeFrameIndex range as a view.

Parameters:

Returns a view over the time-value pairs within the specified range. Uses internal index lookup to find the range boundaries.

function getTimeValueRangeInTimeFrameIndexRange

inline auto getTimeValueRangeInTimeFrameIndexRange(
    TimeFrameIndex start_time,
    TimeFrameIndex end_time
) const

Get time-value pairs as a range for convenient iteration.

Parameters:

See: getTimeValueSpanInTimeFrameIndexRange() for zero-copy alternative

Return: Range view that supports range-based for loops

Note: Uses the same boundary logic as getDataInTimeFrameIndexRange()

Returns a range view that can be used with range-based for loops to iterate over time-value pairs within the specified TimeFrameIndex range. This is the high-level, convenient interface.

function getTimeValueRangeInTimeFrameIndexRange

inline auto getTimeValueRangeInTimeFrameIndexRange(
    TimeFrameIndex start_time,
    TimeFrameIndex end_time,
    TimeFrame const & source_timeFrame
) const

Get time-value pairs as a range with timeframe conversion.

Parameters:

  • start_time The start TimeFrameIndex in source timeframe coordinates
  • end_time The end TimeFrameIndex in source timeframe coordinates
  • source_timeFrame The timeframe that start_time and end_time are expressed in

Return: Range view that supports range-based for loops

Note: If source_timeFrame equals the analog series’ timeframe, or if either is null, falls back to the non-converting version

Similar to getTimeValueRangeInTimeFrameIndexRange, but accepts a source timeframe to convert the start and end time indices from the source coordinate system to the analog time series coordinate system.

function getTimeValueSpanInTimeFrameIndexRange

TimeValueSpanPair getTimeValueSpanInTimeFrameIndexRange(
    TimeFrameIndex start_time,
    TimeFrameIndex end_time
) const

Get time-value pairs as span and time iterator for zero-copy access.

Parameters:

See: getTimeValueRangeInTimeFrameIndexRange() for convenient range-based alternative

Return: TimeValueSpanPair with zero-copy data access

Note: Uses the same boundary logic as getDataInTimeFrameIndexRange()

Returns a structure containing a zero-copy span over the data values and a time iterator for the corresponding TimeFrameIndex values. This is the performance-optimized interface.

function getTimeValueSpanInTimeFrameIndexRange

TimeValueSpanPair getTimeValueSpanInTimeFrameIndexRange(
    TimeFrameIndex start_time,
    TimeFrameIndex end_time,
    TimeFrame const * source_timeFrame
) const

Get time-value pairs with timeframe conversion.

Parameters:

  • start_time The start TimeFrameIndex in source timeframe coordinates
  • end_time The end TimeFrameIndex in source timeframe coordinates
  • source_timeFrame The timeframe that start_time and end_time are expressed in

Return: TimeValueSpanPair with zero-copy data access

Note: If source_timeFrame equals the analog series’ timeframe, or if either is null, falls back to the non-converting version

Similar to getTimeValueSpanInTimeFrameIndexRange, but accepts a source timeframe to convert the start and end time indices from the source coordinate system to the analog time series coordinate system.

function getAllSamples

inline auto getAllSamples() const

function getTimeSeries

inline std::vector< TimeFrameIndex > getTimeSeries() const

Get the time indices as a vector.

See:

  • getAnalogTimeSeries() for accessing the corresponding data values
  • getDataInRange() for accessing time-value pairs within a specific range
  • getTimeAtIndex() for single index lookups

Return: std::vector containing the time indices

Note: For dense storage, this method has O(n) time complexity as it generates the vector. Consider using getTimeAtIndex() for single lookups or iterating with getNumSamples(). For sparse storage, this returns a copy of the internal vector.

Returns a vector containing the time indices corresponding to each analog data sample. For dense time storage, this generates the indices on-demand. For sparse time storage, this returns a copy of the stored indices.

function getTimeStorage

inline std::shared_ptr< TimeIndexStorage > const & getTimeStorage() const

Get a const reference to the time index storage.

Return: const shared_ptr to TimeIndexStorage

This allows efficient access to the underlying time mapping without copying.

function setTimeFrame

inline void setTimeFrame(
    std::shared_ptr< TimeFrame > time_frame
)

Set the time frame.

Parameters:

  • time_frame The time frame to set

function getTimeFrame

inline std::shared_ptr< TimeFrame > getTimeFrame() const

Get the time frame.

Return: std::shared_ptr The time frame

function elements

inline auto elements() const

Get a view of (TimeFrameIndex, float) pairs.

See: elementsView() for concept-compliant iteration with TimeValuePoint

Return: A lazy range view of (TimeFrameIndex, float) pairs

Enables iterating over the time series as a sequence of (time, value) pairs. Compatible with TransformPipeline.

Returns std::pair<[TimeFrameIndex](/api_generated/Classes/structTimeFrameIndex.md), float> for backward compatibility with existing code that uses .first, .second, and structured bindings.

function elementsView

inline auto elementsView() const

Get a view of TimeValuePoint objects (concept-compliant).

See:

Return: A lazy range view of TimeValuePoint objects

Enables iterating over the time series as a sequence of TimeValuePoint objects. Each element satisfies the TimeSeriesElement and ValueElement concepts, enabling use with generic time series algorithms.

Use this method when you need concept-compliant elements for generic algorithms. Use elements() when you need backward-compatible pair iteration.

function getAtTime

inline std::optional< float > getAtTime(
    TimeFrameIndex time
) const

Get value at specific time.

Parameters:

  • time The time to get value for

Return: Optional float value if time exists

function materialize

inline std::shared_ptr< AnalogTimeSeries > materialize() const

function createMemoryMapped

static std::shared_ptr< AnalogTimeSeries > createMemoryMapped(
    MmapStorageConfig config,
    std::vector< TimeFrameIndex > time_vector
)

function createFromView

template <std::ranges::random_access_range ViewType>
static inline std::shared_ptr< AnalogTimeSeries > createFromView(
    ViewType view,
    std::shared_ptr< TimeIndexStorage > time_storage
)

Create AnalogTimeSeries from a lazy view.

Parameters:

  • view Random-access range view yielding (TimeFrameIndex, float) pairs or TimeValuePoint
  • time_storage Shared time index storage (reuse from base series for efficiency)

Exceptions:

  • std::runtime_error if view size doesn’t match time storage size

Template Parameters:

  • ViewType Random-access range type

See:

Return: std::shared_ptr Lazy analog time series

Note:

  • The view must remain valid for the lifetime of the returned AnalogTimeSeries. Capture by value in lambdas or ensure base series outlives the lazy series.
  • For materialized (eager) storage, call .materialize() on the result

Creates an AnalogTimeSeries that computes values on-demand from a ranges view. The view must be a random-access range that yields elements compatible with (TimeFrameIndex, float) pairs or TimeValuePoint. No intermediate data is materialized - values are computed when accessed.

This enables efficient transform pipelines without intermediate allocations:

// Z-score normalization without materializing intermediate results
auto base_series = ;
float mean =;
float std = ;

auto normalized_view = base_series->view()
    | std::views::transform([mean, std](auto tv) {
        float z_score = (tv.value() - mean) / std;
        return AnalogTimeSeries::TimeValuePoint{tv.time_frame_index, z_score};
    });

auto normalized_series = AnalogTimeSeries::createFromView(
    normalized_view, 
    base_series->getTimeStorage()
);

// Access computes z-score on-demand
float value = normalized_series->getAtTime(TimeFrameIndex(100)).value();

function createView

static std::shared_ptr< AnalogTimeSeries > createView(
    std::shared_ptr< AnalogTimeSeries const > const & source,
    TimeFrameIndex start_time,
    TimeFrameIndex end_time
)

function createFromStorage

static std::shared_ptr< AnalogTimeSeries > createFromStorage(
    AnalogDataStorageWrapper storage,
    std::shared_ptr< TimeIndexStorage > time_storage
)

Create an AnalogTimeSeries from a custom storage backend.

Parameters:

  • storage Type-erased analog data storage wrapper
  • time_storage Shared time index storage

Return: std::shared_ptr with the given storage backend

Precondition:

  • time_storage != nullptr
  • storage.size() == time_storage->size()

General-purpose factory that accepts a type-erased storage wrapper and shared time index storage. Used by zero-copy backends (e.g., TensorColumnAnalogStorage) that construct the wrapper externally and pass it in.


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