work with old linalg

Summary: solve and lstsq have moved around in torch. Cope with both.

Reviewed By: patricklabatut

Differential Revision: D29302316

fbshipit-source-id: b34f0b923e90a357f20df359635929241eba6e74
This commit is contained in:
Jeremy Reizenstein
2021-06-28 06:30:27 -07:00
committed by Facebook GitHub Bot
parent 5284de6e97
commit b8790474f1
7 changed files with 65 additions and 14 deletions

View File

@@ -10,6 +10,7 @@ import unittest
import numpy as np
import torch
from common_testing import TestCaseMixin
from pytorch3d.common.compat import lstsq
from pytorch3d.transforms import acos_linear_extrapolation
@@ -64,8 +65,7 @@ class TestAcosLinearExtrapolation(TestCaseMixin, unittest.TestCase):
bound_t = torch.tensor(bound, device=x.device, dtype=x.dtype)
# fit a line: slope * x + bias = y
x_1 = torch.stack([x, torch.ones_like(x)], dim=-1)
solution = torch.linalg.lstsq(x_1, y[:, None]).solution
slope, bias = solution.view(-1)[:2]
slope, bias = lstsq(x_1, y[:, None]).view(-1)[:2]
desired_slope = (-1.0) / torch.sqrt(1.0 - bound_t ** 2)
# test that the desired slope is the same as the fitted one
self.assertClose(desired_slope.view(1), slope.view(1), atol=1e-2)