pub struct CodegenOptions {
pub math_backend: MathBackend,
pub precision: Precision,
pub inline: bool,
pub must_use: bool,
pub cse: bool,
pub unit_annotation: UnitAnnotation,
pub param_units: Vec<(String, String)>,
pub return_unit: Option<String>,
pub use_mul_add: bool,
pub checked_domain: bool,
pub emit_runtime: bool,
}Expand description
Configuration for Rust code generation.
Fields§
§math_backend: MathBackendMath function dispatch strategy.
precision: PrecisionFloating-point precision.
inline: boolAdd #[inline] annotation to generated functions.
must_use: boolAdd #[must_use] annotation.
cse: boolRun CSE before code generation.
unit_annotation: UnitAnnotationUnit annotations for generated function signatures.
param_units: Vec<(String, String)>Map from parameter names to uom type names (e.g., “theta1” → “Angle”).
Only used when unit_annotation is UnitAnnotation::Uom.
return_unit: Option<String>The uom type name for the return value (e.g., “Length”).
Only used when unit_annotation is UnitAnnotation::Uom.
use_mul_add: boolFuse a*b + c patterns into mul_add / fma calls (default true).
Fused multiply-add rounds once instead of twice, so results can differ
from a plain a*b + c in the last bit; disable for bit-exact
reproduction of unfused arithmetic.
checked_domain: boolEmit debug_assert! domain checks (e.g. ln(x) requires x > 0,
sqrt(x) requires x >= 0, lambertw(x) requires x >= -1/e).
Default false. Checks compile away in release builds.
emit_runtime: boolEmit the mod symplex_rt { … } special-function runtime preamble when
the generated function needs it (default true).
Set to false when concatenating many generated functions into one
file and emit the runtime once via CodegenOptions::runtime_module.
Implementations§
Source§impl CodegenOptions
impl CodegenOptions
Sourcepub fn runtime_module(&self) -> String
pub fn runtime_module(&self) -> String
The complete special-function runtime module (mod symplex_rt { … })
for this configuration’s math backend, containing every helper.
Generated functions only embed the helpers they use. When many
functions are concatenated into one file, set
emit_runtime to false and place the output
of this method once at the top of the file instead.
use symplex::matrix::CodegenOptions;
let rt = CodegenOptions::default().runtime_module();
assert!(rt.starts_with("#[allow(dead_code, clippy::all)]\nmod symplex_rt {"));
assert!(rt.contains("pub fn gamma("));
assert!(rt.contains("pub fn bessel_k("));Sourcepub fn runtime_module_for(&self, generated_code: &str) -> Option<String>
pub fn runtime_module_for(&self, generated_code: &str) -> Option<String>
The mod symplex_rt { … } block containing exactly the helpers that
generated_code references as symplex_rt::name(…) (plus their
transitive dependencies), or None when the code uses none.
This is what a single Ex::to_rust_fn
embeds when emit_runtime is set; use it to
emit one shared runtime for a file assembled from several functions
generated with emit_runtime: false.
use symplex::matrix::CodegenOptions;
use symplex::prelude::*;
let ctx = Context::new();
let x = ctx.symbol("x");
let opts = CodegenOptions { emit_runtime: false, ..Default::default() };
let g = x.gamma().to_rust_fn_with_options("g", &["x"], &opts).unwrap();
let e = x.erf().to_rust_fn_with_options("e", &["x"], &opts).unwrap();
let body = format!("{g}\n{e}");
let rt = opts.runtime_module_for(&body).expect("gamma/erf need the runtime");
assert!(rt.contains("pub fn gamma(") && rt.contains("pub fn erf("));
assert!(!rt.contains("pub fn bessel_k("));
assert!(opts.runtime_module_for("fn f(x: f64) -> f64 { x }").is_none());Sourcepub fn c_runtime(&self) -> String
pub fn c_runtime(&self) -> String
The complete C99 helper library (static inline symplex_* functions)
used by Ex::to_c_fn, with its
#include <math.h>.
Generated C functions only embed the helpers they use; when several
functions share one translation unit, set
emit_runtime to false and paste this once.
use symplex::matrix::CodegenOptions;
let rt = CodegenOptions::default().c_runtime();
assert!(rt.contains("#include <math.h>"));
assert!(rt.contains("static inline double symplex_lambert_w0(double x)"));Sourcepub fn no_std() -> Self
pub fn no_std() -> Self
Configuration for no_std embedded targets.
Uses cfg-gated math backend and adds #[inline].
Sourcepub fn embedded_f32() -> Self
pub fn embedded_f32() -> Self
Configuration for embedded f32 targets (e.g., Cortex-M4F).
Uses cfg-gated math backend, f32 precision, and #[inline].
Sourcepub fn param_unit(self, name: &str, uom_type: &str) -> Self
pub fn param_unit(self, name: &str, uom_type: &str) -> Self
Set the uom type for a parameter.
Sourcepub fn return_unit_type(self, uom_type: &str) -> Self
pub fn return_unit_type(self, uom_type: &str) -> Self
Set the uom type for the return value.
Trait Implementations§
Source§impl Clone for CodegenOptions
impl Clone for CodegenOptions
Source§impl Debug for CodegenOptions
impl Debug for CodegenOptions
Auto Trait Implementations§
impl Freeze for CodegenOptions
impl RefUnwindSafe for CodegenOptions
impl Send for CodegenOptions
impl Sync for CodegenOptions
impl Unpin for CodegenOptions
impl UnsafeUnpin for CodegenOptions
impl UnwindSafe for CodegenOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more