15
15
# And a random vector to be orth. to V.
16
16
w_original = rand (T, n)
17
17
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
18
32
@testset " Using $method " for method = (DGKS, ClassicalGramSchmidt, ModifiedGramSchmidt)
19
33
20
34
# Projection size
@@ -24,14 +38,21 @@ m = 3
24
38
w = copy (w_original)
25
39
nrm = orthogonalize_and_normalize! (V, w, h, method)
26
40
27
- # Normality
28
- @test norm (w) ≈ one ( real (T))
41
+ is_orthonormalized (w, h, nrm)
42
+ end
29
43
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]
32
47
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)
35
56
end
36
57
end
37
58
end
0 commit comments