Open gareth-cross opened 1 year ago
This is a weird one - we had similar issues in the past when SymEngine was built with different implementations of std::unordered_map. I'm a little surprised we haven't seen this, we should definitely fix
NOTE: In this particular case, there may additionally be a bug in Rot3.from_rotation_matrix - the epsilon value is unused. This example just highlights how unpredictable behavior emerges from this issue.
Yep, good callout - this is not a bug but is definitely surprising - our current implementation of from_rotation_matrix doesn't require an epsilon, but we still have the argument mostly to not break the API. In general we aim for our generated code to be identical everywhere, and treat it as a bug if it's not, regardless of whether evaluated numerical results are meaningfully different
Describe the bug Operations are placed in a different order on different platforms. This can result in unexpected numerical issues in some cases.
Testing details:
Ubuntu 22.04, Python 3.8.16, x86
OSX Ventura 13.3.1, Python 3.8.16, Apple M2/ARM
v0.8.0
, installed from pipTo Reproduce
import symforce symforce.set_symbolic_api('symengine') symforce.set_epsilon_to_number(1.0e-16)
from symforce import geo from symforce import symbolic as sm from symforce.codegen import Codegen, CppConfig from symforce import typing as T
def test_function(time: T.Scalar) -> geo.V4: rate = sm.pi / 6 angle = rate * time x_axis = geo.V3([-sm.cos(angle), -sm.sin(angle), 0.0]) z_axis = geo.V3([0, 0, 1]) y_axis = z_axis.cross(x_axis)
if name == 'main': cg = Codegen.function(func=test_function, config=CppConfig()) path = Path(file).parent.absolute() cg.generate_function(output_dir=path / 'output')
[0.00523596383141919, 0.999986292247427, 0.0] [-0.999986292247427, 0.00523596383141919, 0.0] [0.0, 0.0, 1.0]
[0.0] [0.0] [-0.705253158861618] [0.708955557080773]
time=3.01
:include "output/cpp/symforce/sym/test_function.h"
int main() { const double time = 3.01; auto v = sym::TestFunction(time); fmt::print("time = {:>6}, v = {:>6}, {:>6}, {:>6}, {:>6}\n", time, v[0], v[1], v[2], v[3]); return 0; }
Mac version (resultant quaternion has zero norm): time = 3.01, v = 0, 0, 0, 0 Linux version (resultant quaternion matches python code): time = 3.01, v = 0, 0, -0.7052531588616179, 0.7089555570807733