matthew-brett / transforms3d

3 dimensional spatial transformations
http://matthew-brett.github.io/transforms3d/
Other
467 stars 83 forks source link

Update euler.py #48

Closed Jiayuan-Gu closed 2 years ago

Jiayuan-Gu commented 2 years ago

Remove in-place modification.

If a NumPy array is passed into euler2quat, then it will lead to unexpected behaviors.

matthew-brett commented 2 years ago

Good point. But - would you consider adding a test?

Jiayuan-Gu commented 2 years ago

I can add one. But do you mean adding a fully new test in https://github.com/matthew-brett/transforms3d/blob/master/transforms3d/tests/test_euler.py? My fix looks too simple to add a test.

matthew-brett commented 2 years ago

The test would just be passing an array, checking the result is correct, and checking the initial array had not been modified ...

Jiayuan-Gu commented 2 years ago
import numpy as np
from transforms3d.euler import euler2quat

def test_euler2quat_inplace():
    angle = np.array(1.0)
    euler2quat(0, 0, angle)
    np.testing.assert_allclose(angle, 1.0)

test_euler2quat_inplace()
matthew-brett commented 2 years ago

Thanks - yes - although it would be good to test all three input arguments. Would you mind adding this to the tests?

Jiayuan-Gu commented 2 years ago

I've added the unit test. I find the issue happens especially for the case np.array(1.0) (which is a np.ndarray), but not for the case like np.random.rand(3)[0] (which is a np.float64).