def to_strictly_upper_triangular(cls, mat): """Make a matrix stritcly upper triangular. Make a matrix strictly upper triangular by zeroing out lower and diagonal elements. Parameters ---------- mat : array-like, shape=[..., n, n] Matrix. Returns ------- triu : array-like, shape=[..., n, n] """ return gs.triu(mat, k=1)
def to_upper_triangular(cls, mat): """Make a matrix upper triangular. Make a matrix upper triangular by zeroing out lower elements. Parameters ---------- mat : array-like, shape=[..., n, n] Matrix. Returns ------- triu : array-like, shape=[..., n, n] """ return gs.triu(mat)
def is_strictly_upper_triangular(cls, mat, atol=gs.atol): """Check if a matrix is strictly upper triangular. Parameters ---------- mat : array-like, shape=[..., n, n] Matrix. atol : float Absolute tolerance. Optional, default : backend atol. Returns ------- is_strictly_triu : array-like, shape=[...,] Boolean evaluating if the matrix is strictly upper triangular """ is_square = cls.is_square(mat) if not is_square: is_vectorized = gs.ndim(gs.array(mat)) == 3 return gs.array([False] * len(mat)) if is_vectorized else False return cls.equal(mat, gs.triu(mat, k=1))
def upper_triangular_matrix_from_vector(point): """Compute the upper triangular matrix representation of the vector. The 3D Heisenberg group can also be represented as 3x3 upper triangular matrices. This function computes this representation of the vector 'point'. Parameters ---------- point : array-like, shape=[..., 3] Point in the vector-represention. Returns ------- upper_triangular_mat : array-like, shape=[..., 3, 3] Upper triangular matrix. """ n_points = gs.ndim(point) element_02 = point[..., 2] + 1 / 2 * point[..., 0] * point[..., 1] if n_points == 1: modified_point = gs.array( [1, point[0], element_02, 1, point[1], 1]) else: modified_point = gs.stack( ( gs.ones(n_points), point[..., 0], element_02, gs.ones(n_points), point[..., 1], gs.ones(n_points), ), axis=1, ) return gs.triu(SymmetricMatrices.from_vector(modified_point))
def test_triu(self): mat = gs.array([[2.0, 1.0, 1.0], [1.0, -1.5, 2.0], [-1.0, 10.0, 2.0]]) result = gs.triu(mat) expected = gs.array([[2.0, 1.0, 1.0], [0.0, -1.5, 2.0], [0.0, 0.0, 2.0]]) self.assertAllClose(result, expected)