1% @brief MATLAB Coder script to generate MEX functions
for cache_
module.
3% This script generates MEX (MATLAB Executable) versions of cache_ functions
4% for improved performance. Cache functions compute hit/miss probabilities
5% and normalizing constants for cache replacement models.
7% Skipped functions (Coder-incompatible):
8% cache_mva - State.cartesian() OOP dependency
9% cache_t_hlru - nested bisection helper (function handles)
10% cache_ttl_lrua - fsolve() + rng() + function handles
11% cache_rrm_meanfield - ode23s() script (not a function)
13% See also CODER, CODER.CONFIG, CODER.TYPEOF, CODEGEN.
15%% Create configuration object of class 'coder.CodeConfig'.
16cfg = coder.config('mex','ecoder',false);
17cfg.GenerateReport =
false;
18cfg.ReportPotentialDifferences =
false;
19cfg.GenCodeOnly =
false;
22scal_type = coder.typeof(0);
23vec_type = coder.typeof(0,[1 Inf],[0 1]);
24mat_type = coder.typeof(0,[Inf Inf],[1 1]);
26%% ===== Group: Normalizing constant computations =====
28% cache_erec(gamma, m) -> E
29codegen -config cfg cache_erec -args {vec_type, scal_type}
31% cache_is(gamma, m, samples) -> [E, lE]
32codegen -config cfg cache_is -args {vec_type, scal_type, scal_type}
34% cache_spm(gamma, m, xi0) -> [Z, lZ, xi]
35codegen -config cfg cache_spm -args {vec_type, scal_type, vec_type}
37%% ===== Group: Hit probability computations =====
39% cache_prob_erec - Skipped (cache_erec compile-time recursion exceeds codegen limit)
40% codegen -config cfg cache_prob_erec -args {vec_type, scal_type}
42% cache_prob_fpi(gamma, m) -> prob
43codegen -config cfg cache_prob_fpi -args {vec_type, scal_type}
45% cache_prob_spm - Skipped (calls cache_spm with reduced gamma, triggers cache_erec recursion limit)
46% codegen -config cfg cache_prob_spm -args {vec_type, scal_type, vec_type}
48% cache_prob_is - Skipped (calls cache_is which uses randperm, not codegen-compatible)
49% codegen -config cfg cache_prob_is -args {vec_type, scal_type, scal_type}
51%% ===== Group: Miss rate computations =====
53% cache_miss - Skipped (calls cache_erec directly, recursion limit)
54% codegen -config cfg cache_miss -args {vec_type, scal_type, vec_type}
56% cache_miss_fpi - Skipped (calls cache_miss -> cache_erec)
57% codegen -config cfg cache_miss_fpi -args {vec_type, scal_type, vec_type}
59% cache_miss_spm - Skipped (calls cache_miss -> cache_erec)
60% codegen -config cfg cache_miss_spm -args {vec_type, scal_type, vec_type}
62% cache_miss_is - Skipped (calls cache_miss -> cache_erec)
63% codegen -config cfg cache_miss_is -args {vec_type, scal_type, vec_type, scal_type}
65%% ===== Group: MVA miss computation =====
67% cache_mva_miss(p, m, R) -> [M, Mk]
68codegen -config cfg cache_mva_miss -args {vec_type, scal_type, mat_type}
70%% ===== Group: Parameter computation =====
72% cache_gamma_lp(lambda, R) -> [gamma, u, n, h]
73codegen -config cfg cache_gamma_lp -args {vec_type, mat_type}
75%% ===== Group: Fixed-point iterations =====
77% cache_xi_fp(gamma, m, xi) -> [xi, pi0, pij, it]
78codegen -config cfg cache_xi_fp -args {vec_type, scal_type, vec_type}
80% cache_xi_iter(gamma, m, tmax) -> z
81codegen -config cfg cache_xi_iter -args {vec_type, scal_type, scal_type}
83%% ===== Group: TTL approximations =====
85% cache_ttl_hlru - Skipped (nested bisection helper, not codegen-compatible)
86% codegen -config cfg cache_ttl_hlru -args {vec_type, scal_type}
88%% ===== Group: ODE helper =====
90% cache_rrm_meanfield_ode(t, x, lambda, m, n, h) -> dxdt
91codegen -config cfg cache_rrm_meanfield_ode -args {scal_type, vec_type, vec_type, scal_type, scal_type, scal_type}