check_triu() and check_is_triu() are functions that check if
an input is a valid upper triangular matrix. An upper triangular matrix is
a square matrix where all elements below the main diagonal are zero.
The check_triu() function raises an error if the input is not an
upper triangular matrix, while check_is_triu() returns TRUE if the
input is an upper triangular matrix and FALSE otherwise.
Value
check_triu(): Returns the originalmatif it is a valid upper triangular matrix. Raises an error message ifmatis not a valid upper triangular matrix.check_is_triu(): Logical value,TRUEif the matrix is a valid upper triangular matrix, andFALSEotherwise.
Examples
# Examples for check_triu()
# --------------------------
A <- matrix(c(1, 0, 0, 3, 4, 0, 5, 6, 7), 3, 3)
print(A)
#> [,1] [,2] [,3]
#> [1,] 1 3 5
#> [2,] 0 4 6
#> [3,] 0 0 7
check_triu(A)
#> [,1] [,2] [,3]
#> [1,] 1 3 5
#> [2,] 0 4 6
#> [3,] 0 0 7
B <- matrix(c(1, 2, 0, 3, 4, 0, 5, 6, 7), 3, 3)
try(check_triu(B))
#> Error in check_triu(B) : Expected 'mat' to be an upper triangular matrix.
# Examples for check_is_triu()
# ----------------------------
check_is_triu(A)
#> [1] TRUE
check_is_triu(B)
#> [1] FALSE