argoverse / argoverse-api

Official GitHub repository for Argoverse dataset
https://www.argoverse.org
Other
839 stars 240 forks source link

Throw exception if input to Sim(2)'s `transform_from()` is not 2d #238

Closed johnwlambert closed 3 years ago

johnwlambert commented 3 years ago

Input must be (N,2) not (2,) in shape.

Using the previous code, a (2,) array vs. (1,2) array would yield different results:

import numpy as np

from argoverse.utils.sim2 import Sim2

def rotmat2d(theta_deg: float) -> np.ndarray:
    """ """
    theta_rad = np.deg2rad(theta_deg)
    c = np.cos(theta_rad)
    s = np.sin(theta_rad)

    R = np.array([[c,-s],[s,c]])

    return R

R = rotmat2d(-13)
t = np.array([-5,1])
s = 1.5
aSb = Sim2(R, t, s)

pt_b = np.array([1,0])
pt_a = aSb.transform_from(pt_b)
print(pt_a)

pt_b = np.array([1,0]).reshape(1,2)
pt_a = aSb.transform_from(pt_b)
print(pt_a)

used to print:

[[-6.03844491  2.96155509]
 [-7.83742659  1.16257341]]
[[-6.03844491  1.16257341]]

Instead, there should be the same (1,2) array as output.

Now, fixed via broadcasting.

johnwlambert commented 3 years ago

Hi @tagarwal-argoai, would you mind taking a brief look at this? Thanks!

johnwlambert commented 3 years ago

@benjaminrwilson I made a change so that the broadcasting works now.

But the docstring says the input has to be (N,2) to get (N,2) back out. So I think the ndim check is still important.