Skip to contents

check_tril() and check_is_tril() are functions that check if an input is a valid lower triangular matrix. A lower triangular matrix is a square matrix where all elements above the main diagonal are zero. The check_tril() function raises an error if the input is not a lower triangular matrix, while check_is_tril() returns TRUE if the input is a lower triangular matrix and FALSE otherwise.

Usage

check_tril(mat, par_name = "mat")

check_is_tril(mat)

Arguments

mat

The matrix to check.

par_name

The name of the parameter to display in error messages.

Value

  • check_tril(): Returns the original mat if it is a valid lower triangular matrix. Raises an error message if mat is not a valid lower triangular matrix.

  • check_is_tril(): Logical value, TRUE if the matrix is a valid lower triangular matrix, and FALSE otherwise.

Examples

# Examples for check_tril()
# -------------------------
A <- matrix(c(1, 2, 3, 0, 4, 5, 0, 0, 6), 3, 3)
print(A)
#>      [,1] [,2] [,3]
#> [1,]    1    0    0
#> [2,]    2    4    0
#> [3,]    3    5    6
check_tril(A)
#>      [,1] [,2] [,3]
#> [1,]    1    0    0
#> [2,]    2    4    0
#> [3,]    3    5    6

B <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), 3, 3)
try(check_tril(B))
#> Error in check_tril(B) : Expected 'mat' to be a lower triangular matrix

# Examples for check_is_tril()
# ----------------------------

check_is_tril(A)
#> [1] TRUE

check_is_tril(B)
#> [1] FALSE