sym_mat_index
stdlib/sym_mat_index.nbv
sym_mat_index(static i, static j, diag, triag)
access an element in a symmetric matrix input matrix must be square
takes diagonal, triangle, and element indices row, col
- Precompiles
assert_eq!,assert_lt!,div_exact!,if_eq!,if_lt!,len!
Source
# access an element in a symmetric matrix
# input matrix must be square
#
# takes diagonal, triangle, and element indices
# row, col
(static i, static j, diag, triag)
static size = len! diag
assert_lt! 0, size
assert_eq! (div_exact! (size - 1) * size, 2), len! triag
let mut out[1]
if_eq! i, j {
out = diag[i]
}
if_lt! j, i {
static triag_row_start = div_exact! (i - 1) * i, 2
out = triag[triag_row_start + j]
}
if_lt! i, j {
static triag_row_start = div_exact! (j - 1) * j, 2
out = triag[triag_row_start + i]
}
out