LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
moment_apply.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_API_MOMENT_MOMENT_APPLY_H
6#define LINE_API_MOMENT_MOMENT_APPLY_H
7
8/**
9 * @file
10 * @ingroup api_moment
11 * Shared helper applying a triangular moment-transform table.
12 *
13 * Templated port of matlab/src/api/moment/moment_apply.m. Every operation is integer
14 * or rational, so the exact instantiation returns the transform with no
15 * rounding at all. That matters more here than almost anywhere else in the API:
16 * the alternating binomial sums of the moment conversions cancel
17 * catastrophically in double arithmetic once the order grows.
18 */
19
20#include <vector>
21
22#include "line/num/number.h"
23#include "line/util/error.h"
24#include "line/util/matrix.h"
26
27namespace line {
28namespace moment {
29
30/** Apply a lower-triangular transform table to a moment vector. */
31template <class T>
32std::vector<T> apply_table(const Matrix<T>& A, const std::vector<T>& v) {
33 std::vector<T> r(v.size(), num_traits<T>::from_int(0));
34 for (std::size_t i = 0; i < v.size(); ++i)
35 for (std::size_t j = 0; j <= i; ++j) r[i] += A(i, j) * v[j];
36 return r;
37}
38
39} // namespace moment
40} // namespace line
41
42#endif
The exception types the port throws.
Dense matrix and non-owning view.
std::vector< T > apply_table(const Matrix< T > &A, const std::vector< T > &v)
Apply a lower-triangular transform table to a moment vector.
Number-type abstraction for the templated API port.
Population-vector enumeration and combinatorics.