Template Struct AdditiveModel

Nested Relationships

Nested Types

Struct Documentation

template<typename CostFn, typename FootprintFn>
struct AdditiveModel

Additive single-term cost model (FLOPs or operand storage size).

Implements the additive single-term DP, factored into the CostModel hooks driven by run_single_term_opt. The per-contraction cost is supplied by CostFn (e.g. flops_counter or memsize_counter); a per-intermediate footprint penalty, volatile replay weighting, and subnet common-subexpression elimination (CSE) are all handled by the hooks.

Template Parameters:
  • CostFn – A callable (lhs, rhs, result) -> double.

  • FootprintFn – A callable (result) -> double.

Public Functions

template<typename TIdxs>
inline Context build_context(TensorNetwork const &network, TIdxs const &tidxs) const
inline State leaf(Context const&, size_t) const
inline State init(Context const&, size_t) const
inline void relax(Context &ctx, size_t n, size_t lp, size_t rp, State const &lp_st, State const &rp_st, State &acc) const
inline void finalize(Context &ctx, size_t n, container::vector<State> &st) const
inline EvalSequence reconstruct(Context const&, container::vector<State> const &st) const

Public Members

CostFn cost_fn
FootprintFn footprint_fn
size_t volatile_mask
double volatile_weight
double footprint_weight
bool subnet_cse
bool prune_outer_products = true

Prune disconnected (outer-product) subsets from the DP (see OptimizeOptions::prune_outer_products). Default true.

struct Context

Precomputed tables AND mutable DP scratch, built once by build_context.

Public Members

container::vector<OptRes> results

Per-subset open indices (and scratch) from init_results.

container::vector<size_t> meta_ids

Canonical-subnet ids per subset (CSE only).

container::vector<double> unique_meta_costs

Optimal cost per canonical subnet id, populated during the DP (CSE only).

struct State

Per-subset DP cell: the relevant OptRes fields the additive DP mutates.

Public Members

double ops = std::numeric_limits<double>::max()
size_t lp = 0
size_t rp = 0
container::vector<size_t> subnets