ramhiser / sparsediscrim

Sparse and Regularized Discriminant Analysis in R

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Write helper function to test if a matrix is diagonal.

ramhiser opened this issue · comments

Here is an example, where we test if the Frobenius norm of the difference between the matrix consisting of the diagonal elements of x and x itself is less than some tolerance.

is_diagonal <- function(x, tol = 1e-8) {
  norm(diag(diag(x)) - x, "F") < tol
}