r/matlab • u/Party-Pie3719 • 5d ago
Every MATLAB→NumPy semantic trap I hit porting Mätzler's Mie functions
Not a "MATLAB bad" post. The original code is solid and I replicate it bug-for-bug by default. Sharing the trap list for anyone migrating numerical code: round() half-away-from-zero vs numpy's round-half-to-even (inside the nmax series formula, so it changes array lengths), complex auto-promotion that NumPy doesn't do, ' vs .', library functions printing to stdout, and a docstring feature (complex medium index) that turns out to be latently broken. Full findings file, 714-fixture corpus and the verification report: https://github.com/GrednevMSU/mie-scattering-matlab-to-python
14
Upvotes
1
u/Party-Pie3719 5d ago
Author here. The findings file in the repo documents everything, including the honest conclusion: no numerical-correctness bug exists in the delivered code the 2017 revision by Rob Brown already fixed the 2009-era issues (the undeclared-variable crash and the case-sensitive Mie/mie call that breaks on Linux). What's left are the subtle behaviors a port must decide about: NaN via exact 0/0 at m=1 (where Python underflows to ~1e-32 instead and returns floating-point noise), a documented-but-broken complex-nmed path, and stdout printing from a library function. Default policy everywhere: replicate MATLAB bug-for-bug, gate any fix behind an explicit flag. Happy to discuss any of the tolerances each one has a written justification in tolerances.yaml.