Skip to content

Commit ebed5c5

Browse files
committed
simplify elimination_matrix()
1 parent 2e41bfd commit ebed5c5

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

src/additional_functions/helper.jl

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,17 @@ function duplication_matrix(nobs)
126126
return D
127127
end
128128

129-
function elimination_matrix(nobs)
130-
nobs = Int(nobs)
131-
n1 = Int(nobs * (nobs + 1) * 0.5)
132-
n2 = Int(nobs^2)
133-
L = zeros(n1, n2)
134-
135-
for j in 1:nobs
136-
for i in j:nobs
137-
u = zeros(n1)
138-
u[Int((j - 1) * nobs + i - 0.5 * j * (j - 1))] = 1
139-
T = zeros(nobs, nobs)
140-
T[i, j] = 1
141-
L += u * transpose(vec(T))
129+
# (n(n+1)/2)×n² matrix to transform a
130+
# vectorized form of a n×n symmetric matrix
131+
# into vector of its lower triangular entries,
132+
# opposite of duplication_matrix()
133+
function elimination_matrix(n::Integer)
134+
ntri = div(n * (n + 1), 2)
135+
L = zeros(ntri, n^2)
136+
for j in 1:n
137+
for i in j:n
138+
tri_ix = (j - 1) * n + i - div(j * (j - 1), 2)
139+
L[tri_ix, i+n*(j-1)] = 1
142140
end
143141
end
144142
return L

0 commit comments

Comments
 (0)