use once_cell::sync::Lazy;
use std::collections::HashMap;
pub static MATLAB_FUNCTION_MAP: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
let mut map = HashMap::new();
map.insert("zeros", "FLTARR"); map.insert("ones", "FLTARR"); map.insert("eye", "IDENTITY"); map.insert("rand", "RANDOMU"); map.insert("randn", "RANDOMN");
map.insert("size", "SIZE");
map.insert("length", "N_ELEMENTS");
map.insert("numel", "N_ELEMENTS");
map.insert("sin", "SIN");
map.insert("cos", "COS");
map.insert("tan", "TAN");
map.insert("asin", "ASIN");
map.insert("acos", "ACOS");
map.insert("atan", "ATAN");
map.insert("atan2", "ATAN");
map.insert("exp", "EXP");
map.insert("log", "ALOG");
map.insert("log10", "ALOG10");
map.insert("sqrt", "SQRT");
map.insert("abs", "ABS");
map.insert("floor", "FLOOR");
map.insert("ceil", "CEIL");
map.insert("round", "ROUND");
map.insert("mod", "MOD");
map.insert("mean", "MEAN");
map.insert("median", "MEDIAN");
map.insert("std", "STDDEV");
map.insert("var", "VARIANCE");
map.insert("min", "MIN");
map.insert("max", "MAX");
map.insert("sum", "TOTAL");
map.insert("transpose", "TRANSPOSE");
map.insert("inv", "INVERT");
map.insert("det", "DETERM");
map.insert("plot", "PLOT");
map.insert("xlabel", "XTITLE");
map.insert("ylabel", "YTITLE");
map.insert("zlabel", "ZTITLE"); map.insert("title", "TITLE");
map.insert("legend", "LEGEND"); map.insert("figure", "WINDOW");
map.insert("hold", "OPLOT"); map.insert("clf", "ERASE");
map.insert("close", "WDELETE");
map.insert("linspace", "LINSPACE");
map.insert("logspace", "LOGSPACE");
map.insert("meshgrid", "MESHGRID");
map.insert("ndgrid", "NDGRID");
map.insert("repmat", "REPMAT");
map.insert("squeeze", "SQUEEZE");
map.insert("interp1", "INTERP1");
map.insert("reshape", "REFORM");
map.insert("sort", "SORT");
map.insert("find", "WHERE");
map.insert("disp", "PRINT");
map.insert("fprintf", "PRINTF");
map.insert("sprintf", "STRING");
map.insert("all", "MIN"); map.insert("any", "MAX");
map.insert("double", "DOUBLE");
map.insert("single", "FLOAT");
map.insert("int32", "LONG");
map.insert("uint32", "ULONG");
map
});
pub fn get_xdl_function(matlab_func: &str) -> Option<&'static str> {
MATLAB_FUNCTION_MAP.get(matlab_func).copied()
}
pub fn needs_special_handling(matlab_func: &str) -> bool {
matches!(matlab_func, "ones" | "rand" | "randn" | "eye")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_function_mapping() {
assert_eq!(get_xdl_function("zeros"), Some("FLTARR"));
assert_eq!(get_xdl_function("sin"), Some("SIN"));
assert_eq!(get_xdl_function("plot"), Some("PLOT"));
assert_eq!(get_xdl_function("nonexistent"), None);
}
}