LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
line::reg Namespace Reference

Classes

class  Args
 Named-argument reader over the parsed JSON object. More...
struct  ArithSpec
 The arithmetic a call runs at: Real also carries the precision tier. More...
struct  EncodeScalar
struct  EncodeScalar< double >
struct  EncodeScalar< Rational >
struct  EncodeScalar< Real< D > >
struct  NumFromDecimal
struct  NumFromDecimal< double >
struct  NumFromDecimal< Rational >
struct  NumFromDecimal< Real< D > >

Typedefs

using Json = nlohmann::json

Functions

ArithSpec parse_arith (const std::string &text)
 Parse –arith.
std::vector< std::string > api_exposed_functions ()
 Names exposed over this boundary, sorted; a subset of the registry.
bool api_is_exposed (const std::string &name)
 True when the named function has a dispatch entry.
Json api_invoke (const std::string &name, const std::string &arith, const Json &args)
 Invoke one API function.
std::string api_render_readable (const Json &result)
 Human-readable rendering of the object api_invoke returns, for -o readable.
std::string shortest_decimal (double v)
 The shortest decimal literal that round-trips to v.
BigInt pow10_bigint (unsigned e)
Rational rational_from_decimal (const std::string &text)
 Exact value of a decimal literal, with no rounding anywhere: sign, digits, optional fraction and optional exponent are read symbolically and assembled as numerator over a power of ten.
double double_from_decimal (const std::string &text)
 double value of a decimal literal, including the "a/b" fraction form.
std::string decimal_text (const Json &j, const std::string &where)
 The decimal literal behind a JSON scalar, per the policy in the file header.
template<class T>
number_from_json (const Json &j, const std::string &where)
template<class T>
Matrix< T > matrix_from_json (const Json &j, const std::string &where)
 A matrix from a JSON value: 2-D array as rows, 1-D array as a row vector, scalar as 1x1, empty array as the empty matrix.
template<class T>
std::vector< T > vector_from_json (const Json &j, const std::string &where)
 A flat numeric vector: 1-D array, or a 1-row / 1-column 2-D array.
std::vector< int > int_vector_from_json (const Json &j, const std::string &where)
 An integer vector; a non-integral entry is an error, never a truncation.
template<class T>
Json encode_scalar (const T &v)
template<class T>
Json encode_vector (const std::vector< T > &v)
template<class T>
Json encode_matrix (const Matrix< T > &m)
Json encode_ints (const std::vector< int > &v)
template<class T>
Json encode_matrices (const std::vector< Matrix< T > > &v)
 A list of matrices, the shape the MMAP/BMAP families return as {D0,D1,...}.
template<class T>
Json encode_vectors (const std::vector< std::vector< T > > &v)
 A list of vectors, the shape a per-class or per-segment result returns.
Json encode_count (std::size_t n)
 A count.

Typedef Documentation

◆ Json

using line::reg::Json = nlohmann::json

Definition at line 63 of file api_json.h.

Function Documentation

◆ api_exposed_functions()

std::vector< std::string > line::reg::api_exposed_functions ( )

Names exposed over this boundary, sorted; a subset of the registry.

Definition at line 2847 of file api_dispatch.cpp.

References api_exposed_functions().

Referenced by api_exposed_functions(), and api_invoke().

◆ api_invoke()

Json line::reg::api_invoke ( const std::string & name,
const std::string & arith,
const Json & args )

Invoke one API function.

Parameters
nameMATLAB function name, e.g. "pfqn_ca"
arithtext of –arith, e.g. "exact" or "real:50"
argsobject keyed by the MATLAB parameter names
Returns
{"function", "arith", "results"}, results keyed by the MATLAB output names and encoded per the policy in api_json.h
Exceptions
UnsupportedError,InputError,NumericError

Definition at line 2857 of file api_dispatch.cpp.

References api_exposed_functions(), api_invoke(), line::api_supports(), line::ApiEntry::arith, line::arith_name(), line::ApiEntry::domain, line::find_api(), line::reg::ArithSpec::mode, parse_arith(), line::reg::ArithSpec::str(), and line::UnsupportedError::UnsupportedError().

Referenced by api_invoke(), and run_invocation().

◆ api_is_exposed()

bool line::reg::api_is_exposed ( const std::string & name)

True when the named function has a dispatch entry.

Definition at line 2853 of file api_dispatch.cpp.

References api_is_exposed().

Referenced by api_is_exposed().

◆ api_render_readable()

std::string line::reg::api_render_readable ( const Json & result)

Human-readable rendering of the object api_invoke returns, for -o readable.

Definition at line 2950 of file api_dispatch.cpp.

References api_render_readable().

Referenced by api_render_readable(), and run_invocation().

◆ decimal_text()

std::string line::reg::decimal_text ( const Json & j,
const std::string & where )
inline

The decimal literal behind a JSON scalar, per the policy in the file header.

Definition at line 199 of file api_json.h.

References decimal_text(), line::InputError::InputError(), and shortest_decimal().

Referenced by decimal_text(), int_vector_from_json(), and number_from_json().

◆ double_from_decimal()

double line::reg::double_from_decimal ( const std::string & text)
inline

double value of a decimal literal, including the "a/b" fraction form.

Definition at line 154 of file api_json.h.

References double_from_decimal(), and line::InputError::InputError().

Referenced by double_from_decimal(), line::reg::NumFromDecimal< double >::parse(), and line::reg::NumFromDecimal< Real< D > >::parse().

◆ encode_count()

Json line::reg::encode_count ( std::size_t n)
inline

A count.

Written as a plain JSON integer at every arithmetic: an iteration count or a dimension is exact in all of them, so wrapping it in the {"double",...} envelope the scalars use would suggest a precision question that a cardinal number does not have.

Definition at line 378 of file api_json.h.

References encode_count().

Referenced by encode_count().

◆ encode_ints()

Json line::reg::encode_ints ( const std::vector< int > & v)
inline

Definition at line 350 of file api_json.h.

References encode_ints().

Referenced by encode_ints().

◆ encode_matrices()

template<class T>
Json line::reg::encode_matrices ( const std::vector< Matrix< T > > & v)

A list of matrices, the shape the MMAP/BMAP families return as {D0,D1,...}.

Definition at line 358 of file api_json.h.

References encode_matrices(), and encode_matrix().

Referenced by encode_matrices().

◆ encode_matrix()

template<class T>
Json line::reg::encode_matrix ( const Matrix< T > & m)

◆ encode_scalar()

template<class T>
Json line::reg::encode_scalar ( const T & v)

Definition at line 328 of file api_json.h.

References encode_scalar().

Referenced by encode_matrix(), encode_scalar(), and encode_vector().

◆ encode_vector()

template<class T>
Json line::reg::encode_vector ( const std::vector< T > & v)

Definition at line 333 of file api_json.h.

References encode_scalar(), and encode_vector().

Referenced by encode_vector(), and encode_vectors().

◆ encode_vectors()

template<class T>
Json line::reg::encode_vectors ( const std::vector< std::vector< T > > & v)

A list of vectors, the shape a per-class or per-segment result returns.

Definition at line 366 of file api_json.h.

References encode_vector(), and encode_vectors().

Referenced by encode_vectors().

◆ int_vector_from_json()

std::vector< int > line::reg::int_vector_from_json ( const Json & j,
const std::string & where )
inline

◆ matrix_from_json()

template<class T>
Matrix< T > line::reg::matrix_from_json ( const Json & j,
const std::string & where )

A matrix from a JSON value: 2-D array as rows, 1-D array as a row vector, scalar as 1x1, empty array as the empty matrix.

Ragged rows are an error.

Definition at line 223 of file api_json.h.

References line::InputError::InputError(), line::Matrix< T >::Matrix(), matrix_from_json(), and number_from_json().

Referenced by line::reg::Args::matrices(), line::reg::Args::matrix(), matrix_from_json(), line::reg::Args::matrix_or_empty(), and vector_from_json().

◆ number_from_json()

template<class T>
T line::reg::number_from_json ( const Json & j,
const std::string & where )

◆ parse_arith()

ArithSpec line::reg::parse_arith ( const std::string & text)

Parse –arith.

Accepts "double", "exact" and "real:<digits>"; anything else is an InputError listing the accepted forms. The port instantiates the high-precision backend at three fixed tiers (50, 100, 200 digits), so a request between tiers is rounded UP to the next one – never down, so a caller never silently receives less precision than asked – and str() reports the tier actually used. Above 200 digits the call is refused.

Definition at line 196 of file api_dispatch.cpp.

References line::reg::ArithSpec::digits, line::Double, line::Exact, line::InputError::InputError(), line::reg::ArithSpec::mode, parse_arith(), line::Real, and line::UnsupportedError::UnsupportedError().

Referenced by api_invoke(), parse_arith(), and run_invocation().

◆ pow10_bigint()

BigInt line::reg::pow10_bigint ( unsigned e)
inline

Definition at line 86 of file api_json.h.

References pow10_bigint().

Referenced by pow10_bigint(), and rational_from_decimal().

◆ rational_from_decimal()

Rational line::reg::rational_from_decimal ( const std::string & text)
inline

Exact value of a decimal literal, with no rounding anywhere: sign, digits, optional fraction and optional exponent are read symbolically and assembled as numerator over a power of ten.

Definition at line 97 of file api_json.h.

References line::InputError::InputError(), pow10_bigint(), and rational_from_decimal().

Referenced by int_vector_from_json(), line::reg::NumFromDecimal< Rational >::parse(), and rational_from_decimal().

◆ shortest_decimal()

std::string line::reg::shortest_decimal ( double v)
inline

The shortest decimal literal that round-trips to v.

nlohmann::json does not retain the text of a number, so this reconstructs the literal a human wrote: for every double that came from a short decimal in the file, the reconstruction IS that decimal, because a double has at most one shortest round-tripping representation.

Definition at line 76 of file api_json.h.

References shortest_decimal().

Referenced by decimal_text(), and shortest_decimal().

◆ vector_from_json()

template<class T>
std::vector< T > line::reg::vector_from_json ( const Json & j,
const std::string & where )