gtopt::ScaledView class

Zero-copy lazy view that applies a per-element scale factor.

Models a random-access range: view[i] returns data[i] * scales[i] (or data[i] / scales[i] when constructed with divides). When scales are empty, returns raw data unchanged.

Optional physical-space clamp: when lower_ and upper_ spans are both non-empty, operator[](i) additionally clamps the result to [lower_[i] * scales_[i], upper_[i] * scales_[i]] — i.e., the clamp is applied after descaling, in the same physical space the caller sees. Used by LinearInterface::get_col_sol() to scrub solver noise (value returned slightly outside its bound-box on an optimal solve) so downstream SDDP state propagation can pin clean values without causing next-phase infeasibility.

Accepts any integer-like index type (int, size_t, ColIndex, RowIndex).

Public types

class iterator
Iterator support for range-for loops.
enum class Op: uint8_t { multiply, divide }

Constructors, destructors, conversion operators

ScaledView() defaulted constexpr noexcept
ScaledView(const double* data, Index n, const double* scales, size_t ns, const double* lower, Index nlo, const double* upper, Index nup, Op op = Op::multiply, double global_factor = 1.0) constexpr noexcept
ScaledView(const double* data, Index n, const double* scales, size_t ns, Op op = Op::multiply, double global_factor = 1.0) constexpr noexcept
ScaledView(std::span<const double> raw) explicit constexpr noexcept
Construct from a raw span (no scaling).

Public functions

auto begin() const -> iterator noexcept
auto empty() const -> bool noexcept
auto end() const -> iterator noexcept
template<typename T>
auto operator[](T idx) const -> double noexcept
Accepts any integer-like type (int, size_t, ColIndex, RowIndex, …).
auto size() const -> size_t noexcept

Function documentation

gtopt::ScaledView::ScaledView(const double* data, Index n, const double* scales, size_t ns, const double* lower, Index nlo, const double* upper, Index nup, Op op = Op::multiply, double global_factor = 1.0) constexpr noexcept

Construct with physical-space clamp bounds (lower/upper in the same raw-LP space as data; each element is descaled by scales before clamping). When either span is empty, clamping is skipped.