Skip to content

Commit a7c0fb9

Browse files
authored
Merge pull request #175 from haampie/fix-orthogonalization-tests
Add orthogonalization test for V being a vector
2 parents 4899d21 + e1a158b commit a7c0fb9

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

test/orthogonalize.jl

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ m = 3
1515
# And a random vector to be orth. to V.
1616
w_original = rand(T, n)
1717

18+
# Test whether w is w_original orthonormalized w.r.t. V,
19+
# given the projection h = V' * h and the norm of V * V' * h
20+
is_orthonormalized = (w, h, nrm) -> begin
21+
# Normality
22+
@test norm(w) one(real(T))
23+
24+
# Orthogonality
25+
@test norm(V'w) zero(real(T)) atol = 10eps(real(T))
26+
27+
# Denormalizing and adding the components in V should give back the original
28+
@test nrm * w + V * h w_original
29+
end
30+
31+
# Assuming V is a matrix
1832
@testset "Using $method" for method = (DGKS, ClassicalGramSchmidt, ModifiedGramSchmidt)
1933

2034
# Projection size
@@ -24,14 +38,21 @@ m = 3
2438
w = copy(w_original)
2539
nrm = orthogonalize_and_normalize!(V, w, h, method)
2640

27-
# Normality
28-
@test norm(w) one(real(T))
41+
is_orthonormalized(w, h, nrm)
42+
end
2943

30-
# Orthogonality
31-
@test norm(V'w) zero(real(T)) atol = 10eps(real(T))
44+
# Assuming V is a vector.
45+
@testset "ModifiedGramSchmidt with vectors" begin
46+
V_vec = [V[:, i] for i = 1 : m]
3247

33-
# Denormalizing and adding the components in V should give back the original
34-
@test nrm * w + V * h w_original
48+
# Projection size
49+
h = zeros(T, m)
50+
51+
# Orthogonalize w in-place
52+
w = copy(w_original)
53+
nrm = orthogonalize_and_normalize!(V_vec, w, h, ModifiedGramSchmidt)
54+
55+
is_orthonormalized(w, h, nrm)
3556
end
3657
end
3758
end

0 commit comments

Comments
 (0)