-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathManifoldsTestExt.jl
More file actions
2422 lines (2293 loc) · 103 KB
/
Copy pathManifoldsTestExt.jl
File metadata and controls
2422 lines (2293 loc) · 103 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module ManifoldsTestExt
using Manifolds
using ManifoldsBase
using Test
using Manifolds.Test: AbstractExpectation, Expect, NoExpectation, isexpected, expect
get_expectation(g::Dict, key, default = NoExpectation()) = Expect(get(g, key, default))
"""
test_manifold(G::AbstractManifold, properties::Dict, expectations::Dict)
Test the [`AbstractManifold`](@extref `ManifoldsBase.AbstractManifold`) ``\\mathcal M``
based on a `Dict` of properties and a `Dict` of `expectations`.
Three functions are expected to be defined (without explicitly being passed in the `properties`):
`is_point(M, p)`, `is_vector(M, p, X)`, and `isapprox(M, p, q)` / `isapprox(M, p, X, Y)`,
since these are essential for verifying results.
From the following properties, the two often expected to be defined are `:Points` and `:Vectors`,
which should contain at least two points and two tangent vectors, respectively.
Possible properties are
* `:Aliased` is a boolean (same as `:Mutating` by default) whether to test the mutating variants with aliased input
* `:Bases` is a vector of bases, which can be used to test basis related functions, one basis for each entry in `:Coordinates`
* `:Covectors` is a vector of covectors, which should be in the cotangent space of the correspondinig point entry in `:Points`
* `:Coordinates` is a vector of coordinates, which can be used to test coordinate related functions, one coordinate vector for each entry in `:Bases`
* `:EmbeddedPoints` is a vector of points in the embedding space of `M`, to test `project`
* `:EmbeddedVectors` is a vector of tangent vectors in the embedding space of `M`, to test `project`
* `:Functions` is a vector of all defined functions for `M`
note a test is activated by the function (like `exp`), adding the mutating function (like `exp!`) overwrites the
global default (see `:Mutating`) to true.
* `:GeodesicMaxTime` is a real number indicating the time parameter to use when testing `geodesic`
* `:GeodesicSamples` is an integer indicating the number of samples to use when testing `geodesic` (defaults to 10)
* `:InvalidPoints` is a vector of points that are not on `M`, e.g. to test `is_point`
* `:InvalidVectors` is a vector of tangent vectors that are not in the tangent space of the first point from `:Points`
* `:InverseRetractionMethods` is a vector of inverse retraction methods to test on `M`
these should have the same order as `:RetractionMethods` (use `missing` for skipping one)
* `:Mutating` is a boolean (`true` by default) whether to test the mutating variants of functions or not.
when setting this to false, you can still activate single functions mutation checks by
adding the mutating function to `:Functions`
* `:Name` is a name of the test. If not provided, defaults to `"\$M"`
* `:NormalVectors` is a vector of normal vectors, where each should be in the normal space of the corresponding point entries in `:Points`
* `:Points` is a vector of at least 2 points on `M`, which should not be the same point
* `:RetractionMethods` is a vector of retraction methods to test on `M`
these should have the same order as `:InverseRetractionMethods` (use `missing` for skipping one)
* `:Rng` is a random number generator to use for generating random points/vectors if needed
* `:Seed` is a seed to use for generating random points/vectors if needed
* `:Vectors` is a vector of at least 2 tangent vectors, which should be in the tangent space of the correspondinig point entries in `:Points`
* `:SecondVector` is a single second vector in the tangent space of the first entry of `:Points`, for example to test [`inner`](@ref)
* `:VectorTransportMethods` is a vector of vector transport methods to test on `M`
* `:TestMidpointSymmetry` is a boolean (`true` by default) whether to test the symmetry property of the midpoint function
* `:TestInfo` is a boolean (`true` by default) whether to test that whether `error=:info` in verification functions issues info messages.
* `:TestWarn` is a boolean (`true` by default) whether to test that whether `error=:warn` in verification functions issues warning.
Possible entries of the `expectations` dictionary are
* any function tested to provide their expected resulting value, e.g. `exp => p` for the result of `exp(M, p, X)`
* for retractions, inverse retractions, and vector transports, the key is a tuple of the function and the method, e.g. `(retract, method) => q`
* for `embed`, and `project`, the key is a tuple of the function and `:Point` or `:Vector`, e.g. `(embed, :Point) of expected (embedded) points or vectors,
omitting that symbol is interpreted as the expected point.
* for `injectivity_radius`
- you can provide the global test for just the function,
- you can provide the radius for a specific point with `(injectivity_radius, p)`
- you can provide a global or local one for retractions as well using `(injectivity_radius, rm)` and `injectivity_radius, p, rm`, respectively
* for `get_basis`, the key is a tuple of the function and the basis, e.g. `(get_basis, B) => ...` to the expected basis
* for `get_coordinates` the key is a tuple of the function and the basis, e.g. `(get_coordinates, B) => c`
* for `get_vector` the key is a tuple of the function, the coordinate vector, and the basis, e.g. `(get_vector, c, B) => X`
* for `get_vectors` the key is a tuple of the function and the basis, e.g. `(get_vectors, B) => :Symbol` where
* `:Orthogonal` tests for orthogonality
* `:Orthonormal` tests additionally to the previous for unit length
For any basis this test calls `get_basis` on any provided basis, if that function is available.
* for `is_default_metric`, the value is the default metric
* `:atol => 0.0` a global absolute tolerance
* `:atols -> Dict()` a dictionary `function -> atol` for tolerances of specific function tested.
* `:Types` -> Dict() a dictionary `function -> Type` for specifying expected types of results of specific functions, for example `manifold_dimension => Int`.
* `:IsPointErrors` is a vector of expected error types for each invalid point provided in `:InvalidPoints`, use `missing` to skip testing for errors for a specific point.
* `:IsVectorErrors` is a vector of expected error types for each invalid vector provided in `:InvalidVectors`, use `missing` to skip testing for errors for a specific vector.
* `:IsVectorBasepointError` is an expected error type when the base point is invalid e.g. for `is_vector`
"""
function Manifolds.Test.test_manifold(M::AbstractManifold, properties::Dict, expectations::Dict = Dict())
atol = get(expectations, :atol, 0.0)
mutating = get(properties, :Mutating, true)
aliased = get(properties, :Aliased, mutating)
functions = get(properties, :Functions, Function[])
points = get(properties, :Points, [])
vectors = get(properties, :Vectors, [])
vector = get(properties, :SecondVector, missing)
covectors = get(properties, :Covectors, [])
normals = get(properties, :NormalVectors, [])
bases = get(properties, :Bases, [])
coordinates = get(properties, :Coordinates, [])
test_name = get(properties, :Name, "Manifolds.Test suite for $M")
test_warn = get(properties, :TestWarn, true)
test_info = get(properties, :TestInfo, true)
function_atols = get(expectations, :atols, Dict())
result_types = get(expectations, :Types, Dict())
retraction_methods = get(properties, :RetractionMethods, [])
inverse_retraction_methods = get(properties, :InverseRetractionMethods, [])
vector_transport_methods = get(properties, :VectorTransportMethods, [])
t = Test.@testset "$test_name" begin # COV_EXCL_LINE
n_points = length(points)
n_vectors = length(vectors)
if (copy in functions)
Manifolds.Test.test_copy(
M, points[1], vectors[1];
name = "copy(M, p) & copy(M, p, X)",
)
end
if (copyto! in functions)
Manifolds.Test.test_copyto(
M, points[1], vectors[1];
name = "copyto!(M, q, p) & copyto!(M, Y, p, X)",
)
end
if (default_inverse_retraction_method in functions)
Manifolds.Test.test_default_inverse_retraction(
M;
expected_value = get_expectation(expectations, default_inverse_retraction_method),
name = "default_inverse_retraction_method(M)",
)
Manifolds.Test.test_default_inverse_retraction(
M, typeof(points[1]);
expected_value = get_expectation(expectations, default_inverse_retraction_method),
name = "default_inverse_retraction_method(M, P)",
)
end
if (default_retraction_method in functions)
Manifolds.Test.test_default_retraction(
M;
expected_value = get_expectation(expectations, default_retraction_method),
name = "default_retraction_method(M)",
)
Manifolds.Test.test_default_retraction(
M, typeof(points[1]);
expected_value = get_expectation(expectations, default_retraction_method),
name = "default_retraction_method(M, P)",
)
end
if (default_vector_transport_method in functions)
Manifolds.Test.test_default_vector_transport_method(
M;
expected_value = get_expectation(expectations, default_vector_transport_method),
name = "default_vector_transport_method(M)",
)
Manifolds.Test.test_default_vector_transport_method(
M, typeof(points[1]);
expected_value = get_expectation(expectations, default_vector_transport_method),
name = "default_vector_transport_method(M, P)",
)
end
if (distance in functions)
Manifolds.Test.test_distance(
M, points[1], points[2];
available_functions = functions,
expected_value = get_expectation(expectations, distance),
name = "distance(M, p, q)", # shorten name within large suite
atol = get(function_atols, distance, atol),
)
end
if (embed in functions)
ep = get_expectation(expectations, embed)
ep = isexpected(ep) ? ep : get_expectation(expectations, (embed, :Point))
Manifolds.Test.test_embed(
M, points[1], n_vectors ≥ 1 ? vectors[1] : NoExpectation();
available_functions = functions,
expected_point = ep,
expected_vector = get_expectation(expectations, (embed, :Vector)),
test_aliased = aliased,
test_mutating = (embed! in functions) ? true : mutating,
name = "embed(M, p) & embed(M, p, X)", # shorten name within large suite
atol = get(function_atols, embed, atol),
)
end
if (embed_project in functions)
approx_p = get(properties, :EmbeddedPoints, [points[1]])[1]
approx_X = get(properties, :EmbeddedVectors, [vectors[1]])[1]
Manifolds.Test.test_embed_project(
M, approx_p, approx_X;
available_functions = functions,
expected_point = points[1],
expected_vector = vectors[1],
test_aliased = aliased,
test_mutating = (embed_project! in functions) ? true : mutating,
atol = get(function_atols, embed_project, atol),
name = "embed_project(M, q) & embed_project(M, q, Y)", # shorten name within large suite
)
end
if (exp in functions)
Manifolds.Test.test_exp(
M, points[1], vectors[1];
available_functions = functions,
expected_value = get_expectation(expectations, exp),
test_aliased = aliased,
test_mutating = (exp! in functions) ? true : mutating,
atol = get(function_atols, exp, atol),
name = "exp(M, p, X)", # shorten name within large suite
)
end
if (flat in functions)
expected_flat = get_expectation(expectations, flat)
Manifolds.Test.test_flat(
M, points[1], vectors[1];
available_functions = functions,
expected_value = expected_flat,
name = "flat(M, p, X)", # shorten name within large suite
atol = get(function_atols, flat, atol),
)
end
if (get_basis in functions)
for B in bases
expected_basis = get_expectation(expectations, (get_basis, B))
Manifolds.Test.test_get_basis(
M, points[1], B;
available_functions = functions,
expected_value = expected_basis,
name = "get_basis(M, p, $B)", # shorten name within large suite
)
end
end
if (get_coordinates in functions)
expected_coordinates = get_expectation(expectations, get_coordinates)
for B in bases
expected_coordinates_B = get_expectation(expectations, (get_coordinates, B), expected_coordinates)
Manifolds.Test.test_get_coordinates(
M, points[1], vectors[1], B;
available_functions = functions,
expected_value = expected_coordinates_B,
test_mutating = (get_coordinates! in functions) ? true : mutating,
name = "get_coordinates(M, p, X, $B)", # shorten name within large suite
)
end
end
if (get_embedding in functions)
expected_embed = get_expectation(expectations, get_embedding)
Manifolds.Test.test_get_embedding(
# check the global one if this point type does not have an expected embedding
M, missing;
expected_value = expected_embed,
name = "get_embedding(M)", # shorten name within large suite
)
if length(points) >= 1
expected_embed_P = get_expectation(expectations, (get_embedding, typeof(points[1])))
Manifolds.Test.test_get_embedding(
# check the global one if this point type does not have an expected embedding
M, typeof(points[1]);
expected_value = expected_embed,
expected_type = expected_embed_P,
name = "get_embedding(M, p)", # shorten name within large suite
)
end
end
if (get_vector in functions)
for (c, B) in zip(coordinates, bases)
expected_vector = get_expectation(expectations, (get_vector, c, B))
Manifolds.Test.test_get_vector(
M, points[1], c, B;
available_functions = functions,
expected_value = expected_vector,
test_mutating = (get_vector! in functions) ? true : mutating,
name = "get_vector(M, p, c, $B)", # shorten name within large suite
atol = get(function_atols, get_vector, atol),
)
end
end
if (get_vectors in functions)
for B in bases
expected_vectors_symbol = expect(get_expectation(expectations, (get_vectors, B), :default))
Manifolds.Test.test_get_vectors(
M, points[1], (get_basis in functions) ? get_basis(M, points[1], B) : B;
available_functions = functions,
test_orthogonality = expected_vectors_symbol in (:Orthogonal, :Orthonormal),
test_normality = (expected_vectors_symbol === :Orthonormal),
name = "get_vectors(M, p, $B)", # shorten name within large suite
atol = get(function_atols, get_vectors, atol),
)
end
end
if (geodesic in functions)
expected_geod = get_expectation(expectations, geodesic)
t = get(properties, :GeodesicMaxTime, 1.0)
Manifolds.Test.test_geodesic(
M, points[1], vectors[1], t;
available_functions = functions,
atol = get(function_atols, geodesic, atol),
expected_value = expected_geod,
N = get(properties, :GeodesicSamples, 100),
name = "geodesic(M, p, X, $t)", # shorten name within large suite
)
end
if (injectivity_radius in functions)
expected = get_expectation(expectations, (injectivity_radius, points[1]))
expected_global = get_expectation(expectations, injectivity_radius)
Manifolds.Test.test_injectivity_radius(
M, missing;
expected_value = expected_global,
name = "injectivity_radius(M, p)", # shorten name within large suite
)
Manifolds.Test.test_injectivity_radius(
M, points[1];
expected_value = expected,
expected_global_value = expected_global,
name = "injectivity_radius(M, p)", # shorten name within large suite
)
for rm in retraction_methods
ismissing(rm) && continue
expected_rm = get_expectation(expectations, (injectivity_radius, points[1], rm))
expected_rm_global = get_expectation(expectations, (injectivity_radius, rm))
Manifolds.Test.test_injectivity_radius(
M, points[1];
expected_value = expected_rm,
expected_global_value = expected_rm_global,
retraction_method = rm,
name = "injectivity_radius(M, p, $rm)", # shorten name within large suite
)
end
for irm in inverse_retraction_methods
ismissing(irm) && continue
expected_irm = get_expectation(expectations, (injectivity_radius, points[1], irm))
expected_irm_global = get_expectation(expectations, (injectivity_radius, irm))
Manifolds.Test.test_injectivity_radius(
M, points[1];
expected_value = expected_irm,
expected_global_value = expected_irm_global,
retraction_method = irm,
name = "injectivity_radius(M, p, $irm)",
)
end
end
if (inner in functions) && !ismissing(vector)
expected_inner = get_expectation(expectations, inner)
Manifolds.Test.test_inner(
M, points[1], vectors[1], vector;
available_functions = functions,
expected_value = expected_inner,
name = "inner(M, p, X, Y)", # shorten name within large suite
atol = get(function_atols, inner, atol),
)
end
if (inverse_retract in functions)
for (irm, rm) in zip(inverse_retraction_methods, retraction_methods)
ismissing(irm) && continue
expected_inv_retract = get_expectation(expectations, (inverse_retract, irm))
Manifolds.Test.test_inverse_retract(
M, points[1], points[2], irm;
available_functions = functions,
expected_value = expected_inv_retract,
retraction_method = rm,
test_mutating = (inverse_retract! in functions) ? true : mutating,
atol = get(function_atols, inverse_retract, atol),
name = "inverse_retract(M, p, q, $irm)", # shorten name within large suite
)
end
end
if (is_default_metric in functions)
m = get_expectation(expectations, is_default_metric, NoExpectation())
Manifolds.Test.test_is_default_metric(
M, m;
name = "is_default_metric(M$(isexpected(m) ? ", $(expect(m))" : ""))",
)
end
if (is_flat in functions)
Manifolds.Test.test_is_flat(
M; expected_value = get_expectation(expectations, is_flat), name = "is_flat(M)",
)
end
if (is_point in functions)
qs = get(properties, :InvalidPoints, [])
# lets not wrap these in expectations
errs = get(expectations, :IsPointErrors, [])
Manifolds.Test.test_is_point(
M, points[1], qs...;
errors = errs,
name = "is_point on M for $(typeof(points[1])) points",
test_warn = test_warn,
test_info = test_info,
atol = get(function_atols, is_point, atol),
)
end
if (is_vector in functions)
Ys = get(properties, :InvalidVectors, [])
# lets not wrap these in expectations
errs = get(expectations, :IsVectorErrors, [])
Manifolds.Test.test_is_vector(
M, points[1], vectors[1], Ys...;
basepoint_error = get_expectation(expectations, :IsVectorBasepointError),
errors = errs,
name = "is_vector(M, p, X)",
test_warn = test_warn,
test_info = test_info,
q = get(properties, :InvalidPoints, [NoExpectation()])[1],
atol = get(function_atols, is_vector, atol),
)
end
if (log in functions)
expected_log = get_expectation(expectations, :log)
Manifolds.Test.test_log(
M, points[1], points[2];
available_functions = functions,
expected_value = expected_log,
test_mutating = (log! in functions) ? true : mutating,
atol = get(function_atols, log, atol),
name = "log(M, p, q)", # shorten name within large suite
)
end
if (manifold_dimension in functions)
expected_dim = get_expectation(expectations, manifold_dimension)
Manifolds.Test.test_manifold_dimension(
M; expected_value = expected_dim, expected_type = get(result_types, manifold_dimension, Int),
name = "manifold_dimension(M)",
)
end
if (manifold_volume in functions)
expected_vol = get_expectation(expectations, manifold_volume)
Manifolds.Test.test_manifold_volume(
M;
expected_value = expected_vol,
name = "manifold_volume(M)",
)
end
if (mid_point in functions)
expected_mid = get_expectation(expectations, mid_point)
Manifolds.Test.test_mid_point(
M, points[1], points[2];
available_functions = functions,
expected_value = expected_mid,
test_aliased = aliased,
test_mutating = (mid_point! in functions) ? true : mutating,
test_symmetry = get(properties, :TestMidpointSymmetry, true),
atol = get(function_atols, mid_point, atol),
name = "mid_point(M, p, q)", # shorten name within large suite
)
end
if (norm in functions)
expected_norm = get_expectation(expectations, norm)
Manifolds.Test.test_norm(
M, points[1], vectors[1];
available_functions = functions,
expected_value = expected_norm,
name = "norm(M, p, X)", # shorten name within large suite
atol = get(function_atols, norm, atol),
)
end
if (parallel_transport_to in functions)
expected_pt = get_expectation(expectations, parallel_transport_to)
expected_pt_d = get_expectation(expectations, parallel_transport_direction)
Manifolds.Test.test_parallel_transport(
M, points[1], vectors[1], points[2];
available_functions = functions,
expected_value = expected_pt,
expected_value_direction = expected_pt_d,
test_aliased = aliased,
test_mutating = (parallel_transport_to! in functions) ? true : mutating,
atol = get(function_atols, parallel_transport_to, atol),
name = "parallel_transport_to(M, p, X, q)", # shorten name within large suite
)
end
if (project in functions)
Q = get(properties, :EmbeddedPoints, missing)
q = ismissing(Q) ? missing : Q[1]
Ys = get(properties, :EmbeddedVectors, missing)
Y = ismissing(Ys) ? missing : Ys[1]
ep = get_expectation(expectations, project)
ep = isexpected(ep) ? ep : get_expectation(expectations, (project, :Point))
eX = get_expectation(expectations, (project, :Vector))
ismissing(q) && error("To test `project`, at least one `:EmbeddedPoints` must be provided.")
Manifolds.Test.test_project(
M, q, Y;
available_functions = functions,
expected_point = ep,
expected_vector = eX,
test_aliased = aliased,
test_mutating = (project! in functions) ? true : mutating,
atol = get(function_atols, project, atol),
name = "project(M, q) & project(M, q, Y)", # shorten name within large suite
)
end
if (rand in functions)
rng = get(properties, :Rng, missing)
seed = get(properties, :Seed, missing)
Manifolds.Test.test_rand(
M;
seed = seed,
rng = rng,
vector_at = points[1],
test_mutating = (rand! in functions) ? true : mutating,
name = "rand(M)",
atol = get(function_atols, rand, atol),
)
end
if (repr in functions)
expected_repr = get_expectation(expectations, repr)
Manifolds.Test.test_repr(
M;
expected_value = expected_repr,
name = "repr(M)",
)
end
if (representation_size in functions)
expected_repr_size = get_expectation(expectations, representation_size)
Manifolds.Test.test_representation_size(
M;
expected_value = expected_repr_size,
name = "representation_size(M)", # shorten name within large suite
)
end
if (retract in functions)
for (rm, irm) in zip(retraction_methods, inverse_retraction_methods)
ismissing(rm) && continue
expected_retract = get_expectation(expectations, (retract, rm))
Manifolds.Test.test_retract(
M, points[1], vectors[1], rm;
available_functions = functions,
expected_value = expected_retract,
inverse_retraction_method = irm,
test_aliased = aliased,
test_mutating = (retract! in functions) ? true : mutating,
atol = get(function_atols, retract, atol),
name = "retract(M, p, X, $rm)", # shorten name within large suite
)
end
end
if (sectional_curvature in functions) && !ismissing(vector)
expected_sec_curv = get_expectation(expectations, sectional_curvature)
expected_sec_curv_min = get_expectation(expectations, sectional_curvature_min)
expected_sec_curv_max = get_expectation(expectations, sectional_curvature_max)
Manifolds.Test.test_sectional_curvature(
M, points[1], vectors[1], vector;
available_functions = functions,
expected_value = expected_sec_curv,
expected_value_min = expected_sec_curv_min,
expected_value_max = expected_sec_curv_max,
name = "sectional_curvature(M, p, X, Y)", # shorten name within large suite
atol = get(function_atols, sectional_curvature, atol),
)
end
if (sharp in functions)
expected_sharp = get_expectation(expectations, sharp)
Manifolds.Test.test_sharp(
M, points[1], covectors[1];
available_functions = functions,
expected_value = expected_sharp,
name = "sharp(M, p, ξ)", # shorten name within large suite
atol = get(function_atols, sharp, atol),
)
end
if (shortest_geodesic in functions)
expected_geod = get_expectation(expectations, shortest_geodesic)
t = get(properties, :ShortestGeodesicTime, 1.0)
Manifolds.Test.test_shortest_geodesic(
M, points[1], points[2], t;
available_functions = functions,
atol = get(function_atols, shortest_geodesic, atol),
expected_value = expected_geod,
N = get(properties, :GeodesicSamples, 100),
name = "shortest_geodesic(M, p, X, $t)", # shorten name within large suite
)
end
if (vector_transport_to in functions)
for vtm in vector_transport_methods
expected_vt = get_expectation(expectations, (vector_transport_to, vtm))
expected_vtd = get_expectation(expectations, (vector_transport_direction, vtm))
Manifolds.Test.test_vector_transport(
M, points[1], vectors[1], points[2], vtm;
available_functions = functions,
expected_value = expected_vt,
expected_value_direction = expected_vtd,
test_aliased = aliased,
test_mutating = (vector_transport_to! in functions) ? true : mutating,
atol = get(function_atols, vector_transport_to, atol),
name = "vector_transport_to(M, p, X, q, $vtm)", # shorten name within large suite
)
end
end
if (volume_density in functions)
expected_vol_density = get_expectation(expectations, volume_density)
Manifolds.Test.test_volume_density(
M, points[1], vectors[1];
expected_value = expected_vol_density,
name = "volume_density(M, p, X)", # shorten name within large suite
atol = get(function_atols, volume_density, atol),
)
end
if (Weingarten in functions)
Manifolds.Test.test_Weingarten(
M, points[1], vectors[1], normals[1];
available_functions = functions,
expected_value = get_expectation(expectations, Weingarten),
test_mutating = (Weingarten! in functions) ? true : mutating,
atol = get(function_atols, Weingarten, atol),
name = "Weingarten(M, p, X, N)", # shorten name within large suite
)
end
if (zero_vector in functions)
Manifolds.Test.test_zero_vector(
M, points[1];
available_functions = functions,
test_mutating = (zero_vector! in functions) ? true : mutating,
atol = get(function_atols, zero_vector, atol),
name = "zero_vector(M, p)", # shorten name within large suite
)
end
end # end of test_manifold testset
return t
end
# Single function tests
#
# ------------------------------------------------------------------------------------------
"""
Manifolds.Test.test_copy(M, p, X;
name = "copying on \$M for \$(typeof(p)) points",
kwargs...
)
Test `copy(M, p)` and `copy(M, p, X)` on a manifold `M`.
* that the copied point/vector is a valid point/vector on the manifold / tangent space
* that the copied point/vector matches the original point/vector but is new memory
"""
function Manifolds.Test.test_copy(
M::AbstractManifold, p, X;
name = "copying on $M for $(typeof(p)) points",
kwargs...
)
Test.@testset "$(name)" begin
q = copy(M, p)
Test.@test is_point(M, q; error = :error, kwargs...)
Test.@test q == p
Test.@test q !== p
Y = copy(M, p, X)
Test.@test is_vector(M, p, Y; error = :error, kwargs...)
Test.@test Y == X
Test.@test Y !== X
end
return nothing
end # end of Manifolds.Test.test_copy
"""
Manifolds.Test.test_copyto(M, p, X;
name = "copying on \$M for \$(typeof(p)) points",
kwargs...
)
Test `copyto!(M, q, p)` and `copyto!(M, Y, p, X)` on a manifold `M`.
* that the copied point/vector is a valid point/vector on the manifold / tangent space
* that the copied point/vector matches the original point/vector and is the same memory
Note that since this function does not modify its input, is is called `test_copyto`.
"""
function Manifolds.Test.test_copyto(
M::AbstractManifold, p, X;
name = "copyto! on $M for $(typeof(p)) points",
kwargs...
)
Test.@testset "$(name)" begin
# Allocate memory for copyto!
q = allocate_result(M, exp, p, X)
q2 = copyto!(M, q, p)
Test.@test q == p
Test.@test q2 === q
Y = allocate_result(M, exp, p, X)
Y2 = copyto!(M, Y, p, X)
Test.@test Y == X
Test.@test Y2 === Y
end
return nothing
end
"""
Manifolds.Test.test_default_inverse_retraction_method(
M, T=missing;
expected_value = NoExpectation(),
expected_type = !isexpected(expected_value) ? NoExpectation() : typeof(expected_value),
name = "default_inverse_retraction_method on \$M \$(ismissing(T) ? "" : "for type \$T")",
)
Test the [`default_inverse_retraction_method`](@extref `ManifoldsBase.default_inverse_retraction_method-Tuple{AbstractManifold}`) on manifold `M`.
* that it returns an [`AbstractInverseRetractionMethod`](@extref `ManifoldsBase.AbstractInverseRetractionMethod`)
* that the result matches `expected_value`, if given
* that the result is of type `expected_type`, if given, defaults to the type of the value
"""
function Manifolds.Test.test_default_inverse_retraction(
M::AbstractManifold, T = missing;
expected_value = NoExpectation(),
expected_type = !isexpected(expected_value) ? NoExpectation() : Expect(typeof(expect(expected_value))),
name = "default_inverse_retraction_method on $M $(ismissing(T) ? "" : "for type $T")",
)
Test.@testset "$(name)" begin
m = ismissing(T) ? default_inverse_retraction_method(M) : default_inverse_retraction_method(M, T)
Test.@test m isa AbstractInverseRetractionMethod
!isexpected(expected_value) || Test.@test m == expect(expected_value)
!isexpected(expected_type) || Test.@test m isa expect(expected_type)
end
return nothing
end # Manifolds.Test.test_default_inverse_retraction
"""
Manifolds.Test.test_default_retraction_method(
M, T=missing;
expected_value = NoExpectation(),
expected_type = isexpected(expected_value) ? Expect(typeof(expect(expected_value))) : NoExpectation(),
name = "default_retraction_method on \$M \$(ismissing(T) ? "" : "for type \$T")",
)
Test the [`default_retraction_method`](@extref `ManifoldsBase.default_retraction_method-Tuple{AbstractManifold}`) on manifold `M`.
* that it returns an [`AbstractRetractionMethod`](@extref `ManifoldsBase.AbstractRetractionMethod`)
* that the result matches `expected_value`, if given
* that the result is of type `expected_type`, if given, defaults to the type of the value
"""
function Manifolds.Test.test_default_retraction(
M::AbstractManifold, T = missing;
expected_value = NoExpectation(),
expected_type = isexpected(expected_value) ? Expect(typeof(expect(expected_value))) : NoExpectation(),
name = "default_retraction_method on $M $(ismissing(T) ? "" : "for type $T")",
)
Test.@testset "$(name)" begin
m = ismissing(T) ? default_retraction_method(M) : default_retraction_method(M, T)
Test.@test m isa AbstractRetractionMethod
ismissing(expected_value) || Test.@test m == expect(expected_value)
ismissing(expected_type) || Test.@test m isa expect(expected_type)
end
return nothing
end # Manifolds.Test.test_default_retraction
"""
Manifolds.Test.test_default_vector_transport_method(
M, T=missing;
expected_value = NoExpectation(),
expected_type = isexpected(expected_value) ? Expect(typeof(expect(expected_value))) : NoExpectation(),
name = "default_vector_transport_method on \$M \$(ismissing(T) ? "" : "for type \$T")",
)
Test the [`default_vector_transport_method`](@extref `ManifoldsBase.default_vector_transport_method-Tuple{AbstractManifold}`) on manifold `M`.
* that it returns an [`AbstractVectorTransportMethod`](@extref `ManifoldsBase.default_vector_transport_method-Tuple{AbstractManifold}`)
* that the result matches `expected_value`, if given
* that the result is of type `expected_type`, if given, defaults to the type of the value
"""
function Manifolds.Test.test_default_vector_transport_method(
M::AbstractManifold, T = missing;
expected_value = NoExpectation(),
expected_type = isexpected(expected_value) ? Expect(typeof(expect(expected_value))) : NoExpectation(),
name = "default_vector_transport_method on $M $(ismissing(T) ? "" : "for type $T")",
)
Test.@testset "$(name)" begin
m = ismissing(T) ? default_vector_transport_method(M) : default_vector_transport_method(M, T)
Test.@test m isa AbstractVectorTransportMethod
ismissing(expected_value) || Test.@test m == expect(expected_value)
ismissing(expected_type) || Test.@test m isa expect(expected_type)
end
return nothing
end # Manifolds.Test.test_default_vector_transport
"""
Manifolds.Test.test_distance(
M, p, q;
available_functions=[], expected_value=NoExpectation(),
name = "Distance on \$M between \$(typeof(p)) points",
kwargs...
)
Test the distance function on manifold `M` between points `p` and `q`.
* that the result is a nonnegative number
* that the distance from `p` to `p` is zero
* that the distance is symmetric
* that the result matches `expected_value`, if given
* that the distance is equal to the norm of the logarithmic map (if `log` and `norm` are available)
(only performed if either `injectivity_radius` is not available or the points are within)
"""
function Manifolds.Test.test_distance(
M::AbstractManifold, p, q;
available_functions = Function[], expected_value = NoExpectation(),
name = "Distance on $M between $(typeof(p)) points",
kwargs...
)
Test.@testset "$(name)" begin
d = distance(M, p, q)
Test.@test d ≥ 0.0
d_pp = distance(M, p, p)
Test.@test isapprox(d_pp, 0.0; kwargs...)
d_qp = distance(M, q, p)
Test.@test isapprox(d, d_qp; kwargs...)
!isexpected(expected_value) || Test.@test isapprox(d, expect(expected_value); kwargs...)
if (log in available_functions) && (norm in available_functions)
# Test only if inj is not available of points are within inj radius
run_test = !((injectivity_radius in available_functions)) || (d ≤ injectivity_radius(M, p))
run_test || (@warn("Skipping distance-norm-log test since norm of X ($(norm(M, p, X))) is outside injectivity radius ($(injectivity_radius(M, p)))"))
Y = log(M, p, q)
n = norm(M, p, Y)
Test.@test isapprox(d, n; kwargs...) skip = !run_test
end
end
return nothing
end # Manifolds.Test.test_distance
"""
Manifolds.Test.test_embed(
M, p, X=missing;
available_functions=[],
expected_point=NoExpectation(),
expected_vector=NoExpectation(),
test_aliased=true,
test_mutating=true,
name = "Embedding on \$M for \$(typeof(p)) points",
kwargs...
)
Test the [`embed`](@extref `ManifoldsBase.embed-Tuple{AbstractManifold, Any}`)`(M, p)` and [`embed`](@extref `ManifoldsBase.embed-Tuple{AbstractManifold, Any, Any}`)`(M, p, X)`
to embed points and tangent vectors (if not `missing`).
Besides a simple call of `embed` (for both variants) the following ones are prefoemd if [`get_embedding`](@extref `ManifoldsBase.get_embedding-Tuple{AbstractManifold}`) is available:
* that the embedded point is a valid point on the embedding manifold
* that the embedded vector is a valid tangent vector on the embedding manifold (if [`get_embedding`](@extref `ManifoldsBase.get_embedding-Tuple{AbstractManifold}`) is available and `X` is not `missing`)
* that the result matches `expected_point` and `expected_vector`, respectively, if given
* that the projection inverts the embedding (if `project` is available)
* that the mutating version `embed!` produces the same result(s) (if activated _and_ [`get_embedding`](@extref `ManifoldsBase.get_embedding-Tuple{AbstractManifold}`) is available)
* that `embed!` works on aliased input (`p=q` or `X=Y`) (if activated _and_ p/q or X/Y are of same type)
"""
function Manifolds.Test.test_embed(
M::AbstractManifold, p, X = missing;
available_functions = Function[],
expected_point = NoExpectation(),
expected_vector = NoExpectation(),
test_aliased = true,
test_mutating = true,
name = "Embedding on $M for $(typeof(p)) points",
kwargs...
)
Test.@testset "$(name)" begin
E = get_embedding(M) isa AbstractManifold ? get_embedding(M) : missing
# Test point embedding
q = embed(M, p)
if !ismissing(E)
Test.@test is_point(E, q; error = :error, kwargs...)
!isexpected(expected_point) || Test.@test isapprox(E, q, expect(expected_point); error = :error, kwargs...)
if project in available_functions
p2 = project(M, q)
Test.@test isapprox(M, p, p2; error = :error, kwargs...)
end
if test_mutating
q2 = copy(E, q)
embed!(M, q2, p)
Test.@test isapprox(E, q2, q; error = :error, kwargs...)
if test_aliased && (typeof(p) == typeof(q))
q3 = copy(E, p)
embed!(M, q3, q3) # aliased
Test.@test isapprox(E, q3, q; error = :error, kwargs...)
end
if project in available_functions
p3 = copy(M, p)
project!(M, p3, q2)
Test.@test isapprox(M, p, p3; error = :error, kwargs...)
end
end
end
# Test vector embedding
if !ismissing(X)
Y = embed(M, p, X)
if !ismissing(E)
Test.@test is_vector(E, q, Y; error = :error, kwargs...)
!isexpected(expected_vector) || Test.@test isapprox(E, q, Y, expect(expected_vector); error = :error, kwargs...)
if project in available_functions
X2 = project(M, q, Y)
Test.@test isapprox(M, p, X, X2; error = :error, kwargs...)
end
if test_mutating
Y2 = copy(E, q, Y)
embed!(M, Y2, p, X)
Test.@test isapprox(E, q, Y2, Y; error = :error, kwargs...)
if test_aliased
Y3 = copy(E, q, Y)
embed!(M, Y3, q, Y3) # aliased
Test.@test isapprox(E, q, Y3, Y; error = :error, kwargs...)
end
if project in available_functions
X3 = copy(M, p, X)
project!(M, X3, q, Y2)
Test.@test isapprox(M, p, X, X3; error = :error, kwargs...)
end
end
end
end
end
return nothing
end # Manifolds.Test.test_embed
"""
Manifolds.Test.test_embed_project(
M, ap, aX = missing;
available_functions=[],
expected_point=NoExpectation(),
expected_vector=NoExpectation(),
test_aliased=true,
test_mutating=true,
name = "Projection on \$M for \$(typeof(q)) points",
kwargs...
)
Test the `p=`[`embed_project`](@extref `ManifoldsBase.embed_project-Tuple{AbstractManifold, Any}`)`(M, ap)` and [`embed_project`](@extref `ManifoldsBase.embed_project-Tuple{AbstractManifold, Any, Any}`)`(M, p, aX)`
to project points and tangent vectors (if not `aX` is not `missing`) after embedding them.
Besides a simple call of `embed_project` (for both variants) the following tests are performed
* that the projected point is a valid point on the manifold
* that the projected vector is a valid tangent vector on the manifold
* that the result matches `expected_point` and `expected_vector`, respectively, if given
* that the mutating version `embed_project!` produces the same result(s) (if activated)
* that `embed_project!` works on aliased input (`p=q` or `X=Y`) (if activated _and_ p/q or X/Y are of same type)
"""
function Manifolds.Test.test_embed_project(
M::AbstractManifold, ap, aX = missing;
available_functions = Function[],
expected_point = NoExpectation(),
expected_vector = NoExpectation(),
test_aliased = true,
test_mutating = true,
name = "Embed-then-project on $M for $(typeof(ap)) points",
kwargs...
)
Test.@testset "$(name)" begin
# Test point projection
p = embed_project(M, ap)
Test.@test is_point(M, p; error = :error, kwargs...)
!isexpected(expected_point) || Test.@test isapprox(M, p, expect(expected_point); error = :error, kwargs...)
if test_mutating
p2 = copy(M, p)
embed_project!(M, p2, ap)
Test.@test isapprox(M, p2, p; error = :error, kwargs...)
if test_aliased && (typeof(p) == typeof(ap))
p3 = copy(M, ap)
embed_project!(M, p3, p3) # aliased
Test.@test isapprox(M, p3, p; error = :error, kwargs...)
end
end
# Test vector projection
if !ismissing(aX)
X = project(M, p, aX)
Test.@test is_vector(M, p, X; error = :error, kwargs...)
!isexpected(expected_vector) || Test.@test isapprox(M, p, X, expect(expected_vector); error = :error, kwargs...)
if test_mutating
X2 = copy(M, p, aX)
project!(M, X2, p, aX)
Test.@test isapprox(M, p, X2, X; error = :error, kwargs...)
if test_aliased
X3 = copy(M, p, aX)
project!(M, X3, p, X3) # aliased
Test.@test isapprox(M, p, X3, X; error = :error, kwargs...)
end
end
end
end
return nothing
end # Manifolds.Test.test_embed_project
"""
Manifolds.Test.test_exp(
M, p, X, t=1.0;
available_functions=[], expected_value=NoExpectation(), test_mutating=true,
test_log = (log in available_functions),
test_fused = true,
test_injectivity_radius = (injectivity_radius in available_functions),
name = "Exponential map on \$M for \$(typeof(p)) points",
kwargs...
)
Test the exponential map on manifold `M` at point `p` with tangent vector `X`.
* that the result is a valid point on the manifold
* that the result matches `expected_value`, if given
* that the mutating version `exp!` matches the non-mutating version, (if activated)
* that `exp!` works on aliased in put (`p=q`) (if activated for mutating)
* that the logarithmic map inverts the exponential map (if activated)
(only performed if either `injectivity_radius` is not available or `X` is within)
* that the fused version `exp_fused(M, p, t, X)` matches the non-fused version (if activated)
"""
function Manifolds.Test.test_exp(
M::AbstractManifold, p, X, t = 1.0;
available_functions = Function[],
expected_value = NoExpectation(),
test_aliased = true,
test_fused = true,
test_log = (log in available_functions),
test_injectivity_radius = (injectivity_radius in available_functions),
test_mutating = true,
name = "Exponential map on $M for $(typeof(p)) points",
kwargs...
)
Test.@testset "$(name)" begin
q = exp(M, p, X)
Test.@test is_point(M, q; error = :error, kwargs...)
!isexpected(expected_value) || Test.@test isapprox(M, q, expect(expected_value); error = :error, kwargs...)
if test_mutating
q2 = copy(M, p)
exp!(M, q2, p, X)
Test.@test isapprox(M, q2, q; error = :error, kwargs...)
if test_aliased