| 1705 | |
| 1706 | |
| 1707 | def test_cross(): |
| 1708 | shape1 = 3 |
| 1709 | shape2 = 3 |
| 1710 | shape3 = (4, 2, 3) |
| 1711 | shape4 = (4, 2, 3) |
| 1712 | data1 = np.random.random(shape1).astype("float32") |
| 1713 | data2 = np.random.random(shape2).astype("float32") |
| 1714 | data3 = np.random.random(shape3).astype("float32") |
| 1715 | data4 = np.random.random(shape4).astype("float32") |
| 1716 | |
| 1717 | cases = [ |
| 1718 | {"input": [data1, data2]}, |
| 1719 | {"input": [data3, data4]}, |
| 1720 | ] |
| 1721 | opr_test( |
| 1722 | cases, |
| 1723 | F.cross, |
| 1724 | compare_fn=lambda x, y: np.testing.assert_allclose(x, y, rtol=1e-4), |
| 1725 | ref_fn=np.cross, |
| 1726 | ) |
| 1727 | |
| 1728 | data5 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) |
| 1729 | data6 = np.array([[7, 8, 9], [4, 5, 6], [1, 2, 3]]) |
| 1730 | res = F.cross(mge.tensor(data5), mge.tensor(data6), axisa=0, axisb=0) |
| 1731 | dst = np.cross(data5, data6, axisa=0, axisb=0) |
| 1732 | np.testing.assert_allclose(res.numpy(), dst, rtol=1e-4) |
| 1733 | |
| 1734 | data7 = np.array([1, 2, 3]) |
| 1735 | data8 = np.array([4, 5, 6]) |
| 1736 | res = F.cross(mge.tensor(data7), mge.tensor(data8), axisa=0, axisb=0) |
| 1737 | dst = np.cross(data7, data8, axisa=0, axisb=0) |
| 1738 | np.testing.assert_allclose(res.numpy(), dst, rtol=1e-4) |
| 1739 | |
| 1740 | data9 = np.array([[6, 7, 4], [15, 2, 8], [9, 40, 39]]) |
| 1741 | data10 = np.array([[5, 8, 9], [14, 21, 17], [10, 3, 47]]) |
| 1742 | res = F.cross(mge.tensor(data9), mge.tensor(data10), axisa=1, axisb=-1) |
| 1743 | dst = np.cross(data9, data10, axisa=1, axisb=-1) |
| 1744 | np.testing.assert_allclose(res.numpy(), dst, rtol=1e-4) |
| 1745 | |
| 1746 | data11 = np.array([1, 2]) |
| 1747 | data12 = np.array([4, 5, 6]) |
| 1748 | res = F.cross(mge.tensor(data11), mge.tensor(data12)) |
| 1749 | dst = np.cross(data11, data12) |
| 1750 | np.testing.assert_allclose(res.numpy(), dst, rtol=1e-4) |