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 = 10 eps (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 = 10 eps (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
3657end
3758end
0 commit comments