1#ifndef DEPENDENT_PARAMETER_H
2#define DEPENDENT_PARAMETER_H
6#include <unordered_map>
191 return this->sources_raw;
249 void rebind(std::unordered_map<
ParamId, std::shared_ptr<Parameter>> new_sources,
303 std::weak_ptr<DependentParameter> self;
304 std::unordered_map<ParamId, std::shared_ptr<Parameter>> sources_raw;
305 std::unique_ptr<ParamSrc> sources;
308 bool update_at_unfreeze {
false};
316 std::unordered_map<ParamId, std::shared_ptr<Parameter>> saved_sources_raw;
326 bool dependency_detached =
false;
345inline std::shared_ptr<Parameter>&
operator+=(std::shared_ptr<Parameter>& lhs,
const std::shared_ptr<Parameter>& rhs) {
347 if (lhs && lhs->get_id() == rhs->get_id()) {
351 lhs = std::make_shared<Parameter>(*rhs);
371inline std::shared_ptr<Parameter>&
operator*(std::shared_ptr<Parameter>& lhs,
const scalar_t& rhs) {
std::shared_ptr< Parameter > & operator*(std::shared_ptr< Parameter > &lhs, const scalar_t &rhs)
Scales a shared parameter in place.
std::shared_ptr< Parameter > & operator+=(std::shared_ptr< Parameter > &lhs, const std::shared_ptr< Parameter > &rhs)
Adds the payload of one shared parameter into another.
std::function< void(const ParamSrc &, std::shared_ptr< DependentParameter >)> DepParamUpdateFunc
Function signature used to recompute a DependentParameter.
Defines the Parameter class used to store individual physical/model parameters.
Parameter whose value is computed from other parameters and cached lazily.
std::unordered_map< ParamId, std::shared_ptr< Parameter > > get_source_parameters() const override
Returns the source parameters this dependent parameter currently uses.
void rebind(std::unordered_map< ParamId, std::shared_ptr< Parameter > > new_sources, DepParamUpdateFunc new_lambda)
Replaces the dependency set and recomputation rule at runtime.
void clear_above() override
Detaches this parameter from all upstream source parameters.
scalar_t get_val() const override
Returns the current cached value, recomputing it on demand if needed.
void unfreeze() override
Unfreezes the dependent parameter.
void update() override
Marks the parameter as dirty and propagates the update downstream.
void freeze() override
Freezes the dependent parameter.
void clear_below() override
Clears this parameter and all downstream dependent parameters.
void ensure_up_to_date()
Recomputes the parameter if its cached value is stale.
~DependentParameter()
Destructor.
bool dependsOn(const ParamId &pid)
Checks whether this parameter depends on a given source parameter.
void reattach()
Restores previously detached dependencies and recomputation rule.
void mark_dirty()
Marks the cached value as dirty.
void init()
Initializes observer registration on all source parameters.
void detach()
Temporarily detaches all dependencies while keeping the current cached value.
Lightweight view over a set of source parameters keyed by ParamId.
Represents a single parameter with value, uncertainties, and dependency links.
Composite identifier for a single parameter.