xdl_matlab/
function_map.rs1use once_cell::sync::Lazy;
4use std::collections::HashMap;
5
6pub static MATLAB_FUNCTION_MAP: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
8 let mut map = HashMap::new();
9
10 map.insert("zeros", "FLTARR"); map.insert("ones", "FLTARR"); map.insert("eye", "IDENTITY"); map.insert("rand", "RANDOMU"); map.insert("randn", "RANDOMN"); map.insert("size", "SIZE");
19 map.insert("length", "N_ELEMENTS");
20 map.insert("numel", "N_ELEMENTS");
21
22 map.insert("sin", "SIN");
24 map.insert("cos", "COS");
25 map.insert("tan", "TAN");
26 map.insert("asin", "ASIN");
27 map.insert("acos", "ACOS");
28 map.insert("atan", "ATAN");
29 map.insert("atan2", "ATAN");
30 map.insert("exp", "EXP");
31 map.insert("log", "ALOG");
32 map.insert("log10", "ALOG10");
33 map.insert("sqrt", "SQRT");
34 map.insert("abs", "ABS");
35 map.insert("floor", "FLOOR");
36 map.insert("ceil", "CEIL");
37 map.insert("round", "ROUND");
38 map.insert("mod", "MOD");
39
40 map.insert("mean", "MEAN");
42 map.insert("median", "MEDIAN");
43 map.insert("std", "STDDEV");
44 map.insert("var", "VARIANCE");
45 map.insert("min", "MIN");
46 map.insert("max", "MAX");
47 map.insert("sum", "TOTAL");
48
49 map.insert("transpose", "TRANSPOSE");
51 map.insert("inv", "INVERT");
52 map.insert("det", "DETERM");
53
54 map.insert("plot", "PLOT");
56 map.insert("xlabel", "XTITLE");
57 map.insert("ylabel", "YTITLE");
58 map.insert("zlabel", "ZTITLE"); map.insert("title", "TITLE");
60 map.insert("legend", "LEGEND"); map.insert("figure", "WINDOW");
62 map.insert("hold", "OPLOT"); map.insert("clf", "ERASE");
64 map.insert("close", "WDELETE");
65
66 map.insert("linspace", "LINSPACE");
68 map.insert("logspace", "LOGSPACE");
69 map.insert("meshgrid", "MESHGRID");
70 map.insert("ndgrid", "NDGRID");
71 map.insert("repmat", "REPMAT");
72 map.insert("squeeze", "SQUEEZE");
73 map.insert("interp1", "INTERP1");
74
75 map.insert("reshape", "REFORM");
77 map.insert("sort", "SORT");
78 map.insert("find", "WHERE");
79
80 map.insert("disp", "PRINT");
82 map.insert("fprintf", "PRINTF");
83 map.insert("sprintf", "STRING");
84
85 map.insert("all", "MIN"); map.insert("any", "MAX"); map.insert("double", "DOUBLE");
91 map.insert("single", "FLOAT");
92 map.insert("int32", "LONG");
93 map.insert("uint32", "ULONG");
94
95 map
96});
97
98pub fn get_xdl_function(matlab_func: &str) -> Option<&'static str> {
100 MATLAB_FUNCTION_MAP.get(matlab_func).copied()
101}
102
103pub fn needs_special_handling(matlab_func: &str) -> bool {
105 matches!(matlab_func, "ones" | "rand" | "randn" | "eye")
106}
107
108#[cfg(test)]
109mod tests {
110 use super::*;
111
112 #[test]
113 fn test_function_mapping() {
114 assert_eq!(get_xdl_function("zeros"), Some("FLTARR"));
115 assert_eq!(get_xdl_function("sin"), Some("SIN"));
116 assert_eq!(get_xdl_function("plot"), Some("PLOT"));
117 assert_eq!(get_xdl_function("nonexistent"), None);
118 }
119}