(self)
| 1559 | assert_array_equal(expected, actual) |
| 1560 | |
| 1561 | def test_transpose(self): |
| 1562 | v = Variable(["time", "x"], self.d) |
| 1563 | v2 = Variable(["x", "time"], self.d.T) |
| 1564 | assert_identical(v, v2.transpose()) |
| 1565 | assert_identical(v.transpose(), v.T) |
| 1566 | x = np.random.randn(2, 3, 4, 5) |
| 1567 | w = Variable(["a", "b", "c", "d"], x) |
| 1568 | w2 = Variable(["d", "b", "c", "a"], np.einsum("abcd->dbca", x)) |
| 1569 | assert w2.shape == (5, 3, 4, 2) |
| 1570 | assert_identical(w2, w.transpose("d", "b", "c", "a")) |
| 1571 | assert_identical(w2, w.transpose("d", ..., "a")) |
| 1572 | assert_identical(w2, w.transpose("d", "b", "c", ...)) |
| 1573 | assert_identical(w2, w.transpose(..., "b", "c", "a")) |
| 1574 | assert_identical(w, w2.transpose("a", "b", "c", "d")) |
| 1575 | w3 = Variable(["b", "c", "d", "a"], np.einsum("abcd->bcda", x)) |
| 1576 | assert_identical(w, w3.transpose("a", "b", "c", "d")) |
| 1577 | |
| 1578 | # test missing dimension, raise error |
| 1579 | with pytest.raises(ValueError): |
| 1580 | v.transpose(..., "not_a_dim") |
| 1581 | |
| 1582 | # test missing dimension, ignore error |
| 1583 | actual = v.transpose(..., "not_a_dim", missing_dims="ignore") |
| 1584 | expected_ell = v.transpose(...) |
| 1585 | assert_identical(expected_ell, actual) |
| 1586 | |
| 1587 | # test missing dimension, raise warning |
| 1588 | with pytest.warns(UserWarning): |
| 1589 | v.transpose(..., "not_a_dim", missing_dims="warn") |
| 1590 | assert_identical(expected_ell, actual) |
| 1591 | |
| 1592 | def test_transpose_0d(self): |
| 1593 | for value in [ |
nothing calls this directly
no test coverage detected