-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathStan_math_signatures.ml
2699 lines (2623 loc) · 105 KB
/
Stan_math_signatures.ml
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
(** The signatures of the Stan Math library, which are used for type checking *)
open Core
open Core.Poly
(** The "dimensionality" (bad name?) is supposed to help us represent the
vectorized nature of many Stan functions. It allows us to represent when
a function argument can be just a real or matrix, or some common forms of
vectorization over reals. This captures the most commonly used forms in our
previous signatures; there are a lot partially because we had a lot of
inconsistencies.
*)
type dimensionality =
| DInt
| DReal
| DVector
| DMatrix
| DIntArray
(* Vectorizable int *)
| DVInt
(* Vectorizable real *)
| DVReal
| DVComplex
(* DEPRECATED; vectorizable ints or reals *)
| DIntAndReals
(* Vectorizable vectors - for multivariate functions *)
| DVectors
| DDeepVectorized
| DComplexVectors
| DDeepComplexVectorized
[@@warning "-37"]
(* don't warn that some constructors are not yet used *)
(* all base types with up 8 levels of nested containers -
just used for element-wise vectorized unary functions now *)
let rec bare_array_type (t, i) =
match i with 0 -> t | j -> UnsizedType.UArray (bare_array_type (t, j - 1))
let bare_types =
[ UnsizedType.UInt; UReal; UComplex; UVector; URowVector; UMatrix
; UComplexVector; UComplexRowVector; UComplexMatrix ]
let vector_types = [UnsizedType.UReal; UArray UReal; UVector; URowVector]
let primitive_types = [UnsizedType.UInt; UReal]
let complex_types =
[UnsizedType.UComplex; UComplexVector; UComplexRowVector; UComplexMatrix]
let all_vector_types =
[UnsizedType.UReal; UArray UReal; UVector; URowVector; UInt; UArray UInt]
let rec expand_arg = function
| DInt -> [UnsizedType.UInt]
| DReal -> [UReal]
| DVector -> [UVector]
| DMatrix -> [UMatrix]
| DIntArray -> [UArray UInt]
| DVInt -> [UInt; UArray UInt]
| DVReal -> [UReal; UArray UReal; UVector; URowVector]
| DVComplex -> [UComplex; UArray UComplex; UComplexVector; UComplexRowVector]
| DIntAndReals -> expand_arg DVReal @ expand_arg DVInt
| DVectors -> [UVector; UArray UVector; URowVector; UArray URowVector]
| DComplexVectors ->
[ UComplexVector; UArray UComplexVector; UComplexRowVector
; UArray UComplexRowVector ]
| DDeepVectorized ->
let all_base = [UnsizedType.UInt; UReal; URowVector; UVector; UMatrix] in
List.(
concat_map all_base ~f:(fun a ->
map (range 0 8) ~f:(fun i -> bare_array_type (a, i))))
| DDeepComplexVectorized ->
List.(
concat_map complex_types ~f:(fun a ->
map (range 0 8) ~f:(fun i -> bare_array_type (a, i))))
type return_behavior = SameAsArg | IntsToReals | ComplexToReals
[@@deriving show {with_path= false}]
type fkind =
| Lpmf
| Lpdf
| Rng
| Cdf
| Ccdf
| UnaryVectorized of return_behavior
[@@deriving show {with_path= false}]
type fun_arg = UnsizedType.autodifftype * UnsizedType.t
type signature = UnsizedType.returntype * fun_arg list * Mem_pattern.t
type variadic_signature =
{ return_type: UnsizedType.t
; control_args: fun_arg list
; required_fn_rt: UnsizedType.t
; required_fn_args: fun_arg list }
[@@deriving create]
let is_primitive = function
| UnsizedType.UReal -> true
| UInt -> true
| _ -> false
(** The signatures hash table *)
let (stan_math_signatures : (string, signature list) Hashtbl.t) =
String.Table.create ()
(** All of the signatures that are added by hand, rather than the ones
added "declaratively" *)
let (manual_stan_math_signatures : (string, signature list) Hashtbl.t) =
String.Table.create ()
(** The variadic signatures hash table
These functions cannot be overloaded.
*)
let (stan_math_variadic_signatures : (string, variadic_signature) Hashtbl.t) =
String.Table.create ()
(* XXX The correct word here isn't combination - what is it? *)
let all_combinations xx =
List.fold_right xx ~init:[[]] ~f:(fun x accum ->
List.concat_map accum ~f:(fun acc ->
List.map ~f:(fun arg -> arg :: acc) x))
let%expect_test "combinations " =
let a = all_combinations [[1; 2]; [3; 4]; [5; 6]] in
[%sexp (a : int list list)] |> Sexp.to_string_hum |> print_endline;
[%expect
{| ((1 3 5) (2 3 5) (1 4 5) (2 4 5) (1 3 6) (2 3 6) (1 4 6) (2 4 6)) |}]
let missing_math_functions =
String.Set.of_list ["beta_proportion_cdf"; "loglogistic_lcdf"]
let rng_return_type t lt =
if List.for_all ~f:is_primitive lt then t else UnsizedType.UArray t
let add_unqualified (name, rt, uqargts, mem_pattern) =
Hashtbl.add_multi manual_stan_math_signatures ~key:name
~data:
( rt
, List.map ~f:(fun x -> (UnsizedType.AutoDiffable, x)) uqargts
, mem_pattern )
let rec ints_to_real unsized =
match unsized with
| UnsizedType.UInt -> UnsizedType.UReal
| UArray t -> UArray (ints_to_real t)
| x -> x
let rec complex_to_real = function
| UnsizedType.UComplex -> UnsizedType.UReal
| UComplexVector -> UVector
| UComplexRowVector -> URowVector
| UComplexMatrix -> UMatrix
| UArray t -> UArray (complex_to_real t)
| x -> x
let rec real_to_complex = function
| UnsizedType.UReal -> UnsizedType.UComplex
| UVector -> UComplexVector
| URowVector -> UComplexRowVector
| UMatrix -> UComplexMatrix
| UArray t -> UArray (real_to_complex t)
| x -> x
let mk_declarative_sig (fnkinds, name, args, mem_pattern) =
let sfxes = function
| Lpmf -> ["_lpmf"]
| Lpdf -> ["_lpdf"]
| Rng -> ["_rng"]
| Cdf -> ["_cdf"; "_lcdf"]
| Ccdf -> ["_lccdf"]
| UnaryVectorized _ -> [""] in
let add_ints = function DVReal -> DIntAndReals | x -> x in
let all_expanded args = all_combinations (List.map ~f:expand_arg args) in
let promoted_dim = function
| DInt | DIntArray | DVInt -> UnsizedType.UInt
(* XXX fix this up to work with more RNGs *)
| _ -> UReal in
let find_rt rt args = function
| Rng -> UnsizedType.ReturnType (rng_return_type rt args)
| UnaryVectorized SameAsArg -> ReturnType (List.hd_exn args)
| UnaryVectorized IntsToReals ->
ReturnType (ints_to_real (List.hd_exn args))
| UnaryVectorized ComplexToReals ->
ReturnType (complex_to_real (List.hd_exn args))
| _ -> ReturnType UReal in
let create_from_fk_args fk arglists =
List.concat_map arglists ~f:(fun args ->
List.map (sfxes fk) ~f:(fun sfx ->
(name ^ sfx, find_rt UReal args fk, args, mem_pattern))) in
let add_fnkind = function
| Rng ->
let rt, args = (List.hd_exn args, List.tl_exn args) in
let args = List.map ~f:add_ints args in
let rt = promoted_dim rt in
let name = name ^ "_rng" in
List.map (all_expanded args) ~f:(fun args ->
(name, find_rt rt args Rng, args, mem_pattern))
| fk -> create_from_fk_args fk (all_expanded args) in
List.concat_map fnkinds ~f:add_fnkind
|> List.filter ~f:(fun (n, _, _, _) -> not (Set.mem missing_math_functions n))
|> List.map ~f:(fun (n, rt, args, support_soa) ->
( n
, rt
, List.map ~f:(fun x -> (UnsizedType.AutoDiffable, x)) args
, support_soa ))
let full_lpdf = [Lpdf; Rng; Ccdf; Cdf]
let full_lpmf = [Lpmf; Rng; Ccdf; Cdf]
let distributions =
[ (full_lpmf, "beta_binomial", [DVInt; DVInt; DVReal; DVReal], Mem_pattern.SoA)
; ( [Lpmf; Ccdf; Cdf; Rng]
, "beta_neg_binomial"
, [DVInt; DVReal; DVReal; DVReal]
, SoA ); (full_lpdf, "beta", [DVReal; DVReal; DVReal], SoA)
; ([Lpdf; Ccdf; Cdf], "beta_proportion", [DVReal; DVReal; DIntAndReals], SoA)
; (full_lpmf, "bernoulli", [DVInt; DVReal], SoA)
; ([Lpmf; Rng], "bernoulli_logit", [DVInt; DVReal], SoA)
; ([Lpmf], "bernoulli_logit_glm", [DVInt; DMatrix; DReal; DVector], SoA)
; (full_lpmf, "binomial", [DVInt; DVInt; DVReal], SoA)
; ([Lpmf], "binomial_logit", [DVInt; DVInt; DVReal], SoA)
; ([Lpmf], "binomial_logit_glm", [DVInt; DVInt; DMatrix; DReal; DVector], SoA)
; ([Lpmf], "categorical", [DVInt; DVector], AoS)
; ([Lpmf], "categorical_logit", [DVInt; DVector], AoS)
; ([Lpmf], "categorical_logit_glm", [DVInt; DMatrix; DVector; DMatrix], SoA)
; (full_lpdf, "cauchy", [DVReal; DVReal; DVReal], SoA)
; (full_lpdf, "chi_square", [DVReal; DVReal], SoA)
; ([Lpdf], "dirichlet", [DVectors; DVectors], SoA)
; ([Lpmf], "dirichlet_multinomial", [DIntArray; DVector], AoS)
; (full_lpmf, "discrete_range", [DVInt; DVInt; DVInt], SoA)
; (full_lpdf, "double_exponential", [DVReal; DVReal; DVReal], SoA)
; (full_lpdf, "exp_mod_normal", [DVReal; DVReal; DVReal; DVReal], SoA)
; (full_lpdf, "exponential", [DVReal; DVReal], SoA)
; (full_lpdf, "frechet", [DVReal; DVReal; DVReal], SoA)
; (full_lpdf, "gamma", [DVReal; DVReal; DVReal], SoA)
; ( [Lpdf]
, "gaussian_dlm_obs"
, [DMatrix; DMatrix; DMatrix; DMatrix; DMatrix; DVector; DMatrix]
, AoS ); (full_lpdf, "gumbel", [DVReal; DVReal; DVReal], SoA)
; ([Rng], "hmm_latent", [DIntArray; DMatrix; DMatrix; DVector], AoS)
; ([Lpmf; Rng], "hypergeometric", [DInt; DInt; DInt; DInt], SoA)
; (full_lpdf, "inv_chi_square", [DVReal; DVReal], SoA)
; (full_lpdf, "inv_gamma", [DVReal; DVReal; DVReal], SoA)
; ([Lpdf], "inv_wishart_cholesky", [DMatrix; DReal; DMatrix], SoA)
; ([Lpdf], "inv_wishart", [DMatrix; DReal; DMatrix], SoA)
; ([Lpdf], "lkj_corr", [DMatrix; DReal], AoS)
; ([Lpdf], "lkj_corr_cholesky", [DMatrix; DReal], AoS)
; ([Lpdf], "lkj_cov", [DMatrix; DVector; DVector; DReal], AoS)
; (full_lpdf, "logistic", [DVReal; DVReal; DVReal], SoA)
; ([Lpdf; Rng; Cdf], "loglogistic", [DVReal; DVReal; DVReal], SoA)
; (full_lpdf, "lognormal", [DVReal; DVReal; DVReal], SoA)
; ([Lpdf], "multi_gp", [DMatrix; DMatrix; DVector], AoS)
; ([Lpdf], "multi_gp_cholesky", [DMatrix; DMatrix; DVector], AoS)
; ([Lpmf], "multinomial", [DIntArray; DVector], AoS)
; ([Lpmf], "multinomial_logit", [DIntArray; DVector], AoS)
; ([Lpdf], "multi_normal", [DVectors; DVectors; DMatrix], AoS)
; ([Lpdf], "multi_normal_cholesky", [DVectors; DVectors; DMatrix], AoS)
; ([Lpdf], "multi_normal_prec", [DVectors; DVectors; DMatrix], AoS)
; ([Lpdf], "multi_student_t", [DVectors; DReal; DVectors; DMatrix], AoS)
; ( [Lpdf]
, "multi_student_t_cholesky"
, [DVectors; DReal; DVectors; DMatrix]
, SoA ); (full_lpmf, "neg_binomial", [DVInt; DVReal; DVReal], SoA)
; (full_lpmf, "neg_binomial_2", [DVInt; DVReal; DVReal], SoA)
; ([Lpmf; Rng], "neg_binomial_2_log", [DVInt; DVReal; DVReal], SoA)
; ( [Lpmf]
, "neg_binomial_2_log_glm"
, [DVInt; DMatrix; DReal; DVector; DReal]
, SoA ); (full_lpdf, "normal", [DVReal; DVReal; DVReal], SoA)
; ([Lpdf], "normal_id_glm", [DVector; DMatrix; DReal; DVector; DReal], SoA)
; ([Lpmf], "ordered_logistic", [DInt; DReal; DVector], SoA)
; ([Lpmf], "ordered_logistic_glm", [DVInt; DMatrix; DVector; DVector], SoA)
; ([Lpmf], "ordered_probit", [DInt; DReal; DVector], SoA)
; (full_lpdf, "pareto", [DVReal; DVReal; DVReal], SoA)
; (full_lpdf, "pareto_type_2", [DVReal; DVReal; DVReal; DVReal], SoA)
; (full_lpmf, "poisson", [DVInt; DVReal], SoA)
; ([Lpmf; Rng], "poisson_log", [DVInt; DVReal], SoA)
; ([Lpmf], "poisson_log_glm", [DVInt; DMatrix; DReal; DVector], SoA)
; (full_lpdf, "rayleigh", [DVReal; DVReal], SoA)
; (full_lpdf, "scaled_inv_chi_square", [DVReal; DVReal; DVReal], SoA)
; (full_lpdf, "skew_normal", [DVReal; DVReal; DVReal; DVReal], SoA)
; (full_lpdf, "skew_double_exponential", [DVReal; DVReal; DVReal; DVReal], SoA)
; (full_lpdf, "student_t", [DVReal; DVReal; DVReal; DVReal], SoA)
; (full_lpdf, "std_normal", [DVReal], SoA)
; (full_lpdf, "uniform", [DVReal; DVReal; DVReal], SoA)
; (full_lpdf, "von_mises", [DVReal; DVReal; DVReal], SoA)
; (full_lpdf, "weibull", [DVReal; DVReal; DVReal], SoA)
; ([Lpdf], "wiener", [DVReal; DVReal; DVReal; DVReal; DVReal], SoA)
(* new wiener_lpdfs -- c++ is fully vectorized, but this style of implementation
in the typechecker is too expensive to enumerate, so we provide only the
full scalar and full vector case *)
; ([Lpdf], "wiener", [DReal; DReal; DReal; DReal; DReal; DReal], AoS)
; ( [Lpdf]
, "wiener"
, [DReal; DReal; DReal; DReal; DReal; DReal; DReal; DReal]
, AoS )
; ( [Lpdf]
, "wiener"
, [DVector; DVector; DVector; DVector; DVector; DVector]
, AoS )
; ( [Lpdf]
, "wiener"
, [DVector; DVector; DVector; DVector; DVector; DVector; DVector; DVector]
, AoS ); ([Lpdf], "wishart_cholesky", [DMatrix; DReal; DMatrix], SoA)
; ([Lpdf], "wishart", [DMatrix; DReal; DMatrix], SoA) ]
let basic_vectorized = UnaryVectorized IntsToReals
let math_sigs =
[ ([UnaryVectorized SameAsArg], "abs", [DDeepVectorized], Mem_pattern.SoA)
; ([basic_vectorized], "acos", [DDeepVectorized], SoA)
; ([basic_vectorized], "acosh", [DDeepVectorized], SoA)
; ([basic_vectorized], "asin", [DDeepVectorized], SoA)
; ([basic_vectorized], "asinh", [DDeepVectorized], SoA)
; ([basic_vectorized], "atan", [DDeepVectorized], SoA)
; ([basic_vectorized], "atanh", [DDeepVectorized], SoA)
; ([basic_vectorized], "cbrt", [DDeepVectorized], SoA)
; ([basic_vectorized], "ceil", [DDeepVectorized], SoA)
; ([basic_vectorized], "cos", [DDeepVectorized], SoA)
; ([basic_vectorized], "cosh", [DDeepVectorized], SoA)
; ([UnaryVectorized SameAsArg], "conj", [DDeepComplexVectorized], AoS)
; ([basic_vectorized], "digamma", [DDeepVectorized], SoA)
; ([basic_vectorized], "erf", [DDeepVectorized], SoA)
; ([basic_vectorized], "erfc", [DDeepVectorized], SoA)
; ([basic_vectorized], "exp", [DDeepVectorized], SoA)
; ([basic_vectorized], "exp2", [DDeepVectorized], SoA)
; ([basic_vectorized], "expm1", [DDeepVectorized], SoA)
; ([UnaryVectorized ComplexToReals], "get_imag", [DDeepComplexVectorized], AoS)
; ([UnaryVectorized ComplexToReals], "get_real", [DDeepComplexVectorized], AoS)
; ([UnaryVectorized ComplexToReals], "abs", [DDeepComplexVectorized], AoS)
; ([basic_vectorized], "floor", [DDeepVectorized], SoA)
; ([basic_vectorized], "inv", [DDeepVectorized], SoA)
; ([basic_vectorized], "inv_cloglog", [DDeepVectorized], SoA)
; ([basic_vectorized], "inv_erfc", [DDeepVectorized], SoA)
; ([basic_vectorized], "inv_logit", [DDeepVectorized], SoA)
; ([basic_vectorized], "inv_Phi", [DDeepVectorized], SoA)
; ([basic_vectorized], "inv_sqrt", [DDeepVectorized], SoA)
; ([basic_vectorized], "inv_square", [DDeepVectorized], SoA)
; ([basic_vectorized], "lambert_w0", [DDeepVectorized], SoA)
; ([basic_vectorized], "lambert_wm1", [DDeepVectorized], SoA)
; ([basic_vectorized], "lgamma", [DDeepVectorized], SoA)
; ([basic_vectorized], "log", [DDeepVectorized], SoA)
; ([basic_vectorized], "log10", [DDeepVectorized], SoA)
; ([basic_vectorized], "log1m", [DDeepVectorized], SoA)
; ([basic_vectorized], "log1m_exp", [DDeepVectorized], SoA)
; ([basic_vectorized], "log1m_inv_logit", [DDeepVectorized], SoA)
; ([basic_vectorized], "log1p", [DDeepVectorized], SoA)
; ([basic_vectorized], "log1p_exp", [DDeepVectorized], SoA)
; ([basic_vectorized], "log2", [DDeepVectorized], SoA)
; ([basic_vectorized], "log_inv_logit", [DDeepVectorized], SoA)
; ([basic_vectorized], "logit", [DDeepVectorized], SoA)
; ([UnaryVectorized SameAsArg], "minus", [DDeepVectorized], SoA)
; ([UnaryVectorized SameAsArg], "minus", [DDeepComplexVectorized], SoA)
; ([basic_vectorized], "Phi", [DDeepVectorized], SoA)
; ([basic_vectorized], "Phi_approx", [DDeepVectorized], SoA)
; ([basic_vectorized], "round", [DDeepVectorized], SoA)
; ([basic_vectorized], "sin", [DDeepVectorized], SoA)
; ([basic_vectorized], "sinh", [DDeepVectorized], SoA)
; ([basic_vectorized], "sqrt", [DDeepVectorized], SoA)
; ([basic_vectorized], "square", [DDeepVectorized], SoA)
(* TODO: Eventually will want to move _qf to be part of the distribution list above *)
; ([basic_vectorized], "std_normal_qf", [DDeepVectorized], SoA)
(* std_normal_qf is an alias for inv_Phi *)
; ([basic_vectorized], "std_normal_log_qf", [DDeepVectorized], SoA)
; ([basic_vectorized], "step", [DReal], SoA)
; ([basic_vectorized], "tan", [DDeepVectorized], SoA)
; ([basic_vectorized], "tanh", [DDeepVectorized], SoA)
; ([basic_vectorized], "tgamma", [DDeepVectorized], SoA)
; ([basic_vectorized], "trunc", [DDeepVectorized], SoA)
; ([basic_vectorized], "trigamma", [DDeepVectorized], SoA) ]
let all_declarative_sigs = distributions @ math_sigs
let declarative_fnsigs =
List.concat_map ~f:mk_declarative_sig all_declarative_sigs
let is_stan_math_function_name name =
let name = Utils.stdlib_distribution_name name in
Hashtbl.mem stan_math_signatures name
let is_stan_math_variadic_function_name name =
Hashtbl.mem stan_math_variadic_signatures name
let operator_to_stan_math_fns op =
match op with
| Operator.Plus -> ["add"]
| PPlus -> ["plus"]
| Minus -> ["subtract"]
| PMinus -> ["minus"]
| Times -> ["multiply"]
| Divide -> ["mdivide_right"; "divide"]
| Modulo -> ["modulus"]
| IntDivide -> []
| LDivide -> ["mdivide_left"]
| EltTimes -> ["elt_multiply"]
| EltDivide -> ["elt_divide"]
| Pow -> ["pow"]
| EltPow -> ["pow"]
| Or -> ["logical_or"]
| And -> ["logical_and"]
| Equals -> ["logical_eq"]
| NEquals -> ["logical_neq"]
| Less -> ["logical_lt"]
| Leq -> ["logical_lte"]
| Greater -> ["logical_gt"]
| Geq -> ["logical_gte"]
| PNot -> ["logical_negation"]
| Transpose -> ["transpose"]
let int_divide_type =
UnsizedType.
( ReturnType UInt
, [(AutoDiffable, UInt); (AutoDiffable, UInt)]
, Mem_pattern.AoS )
let get_sigs name =
let name = Utils.stdlib_distribution_name name in
Hashtbl.find_multi stan_math_signatures name |> List.sort ~compare
let make_assignmentoperator_stan_math_signatures assop =
(match assop with
| Operator.Divide -> ["divide"]
| assop -> operator_to_stan_math_fns assop)
|> List.concat_map ~f:get_sigs
|> List.concat_map ~f:(function
| ReturnType rtype, [(ad1, lhs); (ad2, rhs)], _
when rtype = lhs
&& not
((assop = Operator.EltTimes || assop = Operator.EltDivide)
&& UnsizedType.is_scalar_type rtype) ->
if rhs = UReal then
[ (UnsizedType.Void, [(ad1, lhs); (ad2, UInt)], Mem_pattern.SoA)
; (Void, [(ad1, lhs); (ad2, UReal)], SoA) ]
else [(Void, [(ad1, lhs); (ad2, rhs)], SoA)]
| _ -> [])
let pp_math_sig ppf (rt, args, mem_pattern) =
UnsizedType.pp ppf (UFun (args, rt, FnPlain, mem_pattern))
let pp_math_sigs ppf name =
(Fmt.list ~sep:Fmt.cut pp_math_sig) ppf (get_sigs name)
let pretty_print_math_sigs = Fmt.str "@[<v>@,%a@]" pp_math_sigs
let string_operator_to_stan_math_fns str =
match str with
| "Plus__" -> "add"
| "PPlus__" -> "plus"
| "Minus__" -> "subtract"
| "PMinus__" -> "minus"
| "Times__" -> "multiply"
| "Divide__" -> "divide"
| "Modulo__" -> "modulus"
| "IntDivide__" -> "divide"
| "LDivide__" -> "mdivide_left"
| "EltTimes__" -> "elt_multiply"
| "EltDivide__" -> "elt_divide"
| "Pow__" -> "pow"
| "EltPow__" -> "pow"
| "Or__" -> "logical_or"
| "And__" -> "logical_and"
| "Equals__" -> "logical_eq"
| "NEquals__" -> "logical_neq"
| "Less__" -> "logical_lt"
| "Leq__" -> "logical_lte"
| "Greater__" -> "logical_gt"
| "Geq__" -> "logical_gte"
| "PNot__" -> "logical_negation"
| "Transpose__" -> "transpose"
| _ -> str
let pretty_print_all_math_sigs ppf () =
let open Fmt in
Format.pp_set_margin ppf 180;
let pp_sig ppf (name, (rt, args, _)) =
pf ppf "%s(@[<h>%a@]) => %a" name
(list ~sep:comma UnsizedType.pp)
(List.map ~f:snd args) UnsizedType.pp_returntype rt in
let pp_sigs_for_name ppf name =
(list ~sep:cut pp_sig) ppf
(List.map ~f:(fun t -> (name, t)) (get_sigs name)) in
pf ppf "@[<v>%a@]"
(list ~sep:cut pp_sigs_for_name)
(List.sort ~compare (Hashtbl.keys stan_math_signatures))
let pretty_print_all_math_distributions ppf () =
let open Fmt in
let distributions =
String.Map.of_alist_reduce
(List.map ~f:(fun (kinds, name, _, _) -> (name, kinds)) distributions)
~f:(fun v1 v2 -> v1 @ v2 |> Set.Poly.of_list |> Set.to_list)
|> Map.to_alist in
let pp_dist ppf (name, kinds) =
pf ppf "@[%s: %a@]" name
(list ~sep:comma Fmt.string)
(List.map ~f:(Fn.compose String.lowercase show_fkind) kinds) in
pf ppf "@[<v>%a@]" (list ~sep:cut pp_dist) distributions
let pretty_print_math_lib_operator_sigs op =
if op = Operator.IntDivide then
[Fmt.str "@[<v>@,%a@]" pp_math_sig int_divide_type]
else operator_to_stan_math_fns op |> List.map ~f:pretty_print_math_sigs
(* -- Some helper definitions to populate stan_math_signatures -- *)
let add_qualified (name, rt, argts, supports_soa) =
Hashtbl.add_multi stan_math_signatures ~key:name
~data:(rt, argts, supports_soa)
let add_nullary name =
add_unqualified (name, UnsizedType.ReturnType UReal, [], AoS)
let add_binary_vec_general ~return_fn ~vectors ~scalars name supports_soa =
List.iter
~f:(fun i ->
List.iter
~f:(fun j ->
add_unqualified (name, ReturnType (return_fn i), [i; j], supports_soa))
scalars)
scalars;
List.iter
~f:(fun i ->
List.iter
~f:(fun j ->
add_unqualified
( name
, ReturnType (return_fn (bare_array_type (j, i)))
, [bare_array_type (j, i); bare_array_type (j, i)]
, supports_soa ))
vectors)
(List.range 0 8);
List.iter
~f:(fun i ->
List.iter
~f:(fun j ->
List.iter
~f:(fun k ->
add_unqualified
( name
, ReturnType (return_fn (bare_array_type (k, j)))
, [bare_array_type (k, j); i]
, supports_soa ))
vectors)
(List.range 0 8))
scalars;
List.iter
~f:(fun i ->
List.iter
~f:(fun j ->
List.iter
~f:(fun k ->
add_unqualified
( name
, ReturnType (return_fn (bare_array_type (k, j)))
, [i; bare_array_type (k, j)]
, supports_soa ))
vectors)
(List.range 0 8))
scalars
let add_binary_vec name supports_soa =
add_binary_vec_general ~return_fn:ints_to_real
~vectors:[UArray UInt; UArray UReal; UVector; URowVector; UMatrix]
~scalars:[UInt; UReal] name supports_soa
let add_binary_vec_real_real name supports_soa =
add_binary_vec_general ~return_fn:Fun.id
~vectors:[UArray UReal; UVector; URowVector; UMatrix]
~scalars:[UReal] name supports_soa
let add_binary_vec_complex_complex name supports_soa =
add_binary_vec_general ~return_fn:Fun.id
~vectors:[UArray UComplex; UComplexVector; UComplexRowVector; UComplexMatrix]
~scalars:[UComplex] name supports_soa
let add_binary_vec_reals_to_complex name supports_soa =
add_binary_vec_general ~return_fn:real_to_complex
~vectors:[UArray UReal; UVector; URowVector; UMatrix]
~scalars:[UReal] name supports_soa
(* the following mix types in a way that doesn't
work with the general method used above *)
let add_binary_vec_int_real name supports_soa =
List.iter
~f:(fun i ->
List.iter
~f:(fun j ->
add_unqualified
( name
, ReturnType (bare_array_type (i, j))
, [UInt; bare_array_type (i, j)]
, supports_soa ))
(List.range 0 8))
[UnsizedType.UArray UReal; UVector; URowVector; UMatrix];
List.iter
~f:(fun i ->
List.iter
~f:(fun j ->
add_unqualified
( name
, ReturnType (bare_array_type (i, j))
, [bare_array_type (UInt, j + 1); bare_array_type (i, j)]
, supports_soa ))
(List.range 0 8))
[UnsizedType.UArray UReal; UVector; URowVector];
List.iter
~f:(fun i ->
add_unqualified
( name
, ReturnType (bare_array_type (UMatrix, i))
, [bare_array_type (UInt, i + 2); bare_array_type (UMatrix, i)]
, supports_soa ))
(List.range 0 8);
List.iter
~f:(fun i ->
add_unqualified
( name
, ReturnType (bare_array_type (UReal, i))
, [bare_array_type (UInt, i); UReal]
, supports_soa ))
(List.range 0 8)
let add_binary_vec_real_int name supports_soa =
List.iter
~f:(fun i ->
List.iter
~f:(fun j ->
add_unqualified
( name
, ReturnType (bare_array_type (i, j))
, [bare_array_type (i, j); UInt]
, supports_soa ))
(List.range 0 8))
[UnsizedType.UArray UReal; UVector; URowVector; UMatrix];
List.iter
~f:(fun i ->
List.iter
~f:(fun j ->
add_unqualified
( name
, ReturnType (bare_array_type (i, j))
, [bare_array_type (i, j); bare_array_type (UInt, j + 1)]
, supports_soa ))
(List.range 0 8))
[UnsizedType.UArray UReal; UVector; URowVector];
List.iter
~f:(fun i ->
add_unqualified
( name
, ReturnType (bare_array_type (UMatrix, i))
, [bare_array_type (UMatrix, i); bare_array_type (UInt, i + 2)]
, supports_soa ))
(List.range 0 8);
List.iter
~f:(fun i ->
add_unqualified
( name
, ReturnType (bare_array_type (UReal, i))
, [UReal; bare_array_type (UInt, i)]
, supports_soa ))
(List.range 0 8)
let add_binary_vec_int_int name supports_soa =
List.iter
~f:(fun i ->
add_unqualified
( name
, ReturnType (bare_array_type (UInt, i))
, [bare_array_type (UInt, i); UInt]
, supports_soa ))
(List.range 0 8);
List.iter
~f:(fun i ->
add_unqualified
( name
, ReturnType (bare_array_type (UInt, i))
, [UInt; bare_array_type (UInt, i)]
, supports_soa ))
(List.range 1 8);
List.iter
~f:(fun i ->
add_unqualified
( name
, ReturnType (bare_array_type (UInt, i))
, [bare_array_type (UInt, i); bare_array_type (UInt, i)]
, supports_soa ))
(List.range 1 8)
let add_ternary name supports_soa =
add_unqualified (name, ReturnType UReal, [UReal; UReal; UReal], supports_soa)
(*Adds functions that operate on matrix, double array and real types*)
let add_ternary_vec name supports_soa =
add_unqualified (name, ReturnType UReal, [UReal; UReal; UReal], supports_soa);
add_unqualified
(name, ReturnType UVector, [UVector; UReal; UReal], supports_soa);
add_unqualified
(name, ReturnType UVector, [UVector; UVector; UReal], supports_soa);
add_unqualified
(name, ReturnType UVector, [UVector; UReal; UVector], supports_soa);
add_unqualified
(name, ReturnType UVector, [UVector; UVector; UVector], supports_soa);
add_unqualified
(name, ReturnType UVector, [UReal; UVector; UReal], supports_soa);
add_unqualified
(name, ReturnType UVector, [UReal; UVector; UVector], supports_soa);
add_unqualified
(name, ReturnType UVector, [UReal; UReal; UVector], supports_soa);
add_unqualified
(name, ReturnType URowVector, [URowVector; UReal; UReal], supports_soa);
add_unqualified
(name, ReturnType URowVector, [URowVector; URowVector; UReal], supports_soa);
add_unqualified
(name, ReturnType URowVector, [URowVector; UReal; URowVector], supports_soa);
add_unqualified
( name
, ReturnType URowVector
, [URowVector; URowVector; URowVector]
, supports_soa );
add_unqualified
(name, ReturnType URowVector, [UReal; URowVector; UReal], supports_soa);
add_unqualified
(name, ReturnType URowVector, [UReal; URowVector; URowVector], supports_soa);
add_unqualified
(name, ReturnType URowVector, [UReal; UReal; URowVector], supports_soa);
add_unqualified
(name, ReturnType UMatrix, [UMatrix; UReal; UReal], supports_soa);
add_unqualified
(name, ReturnType UMatrix, [UMatrix; UMatrix; UReal], supports_soa);
add_unqualified
(name, ReturnType UMatrix, [UMatrix; UReal; UMatrix], supports_soa);
add_unqualified
(name, ReturnType UMatrix, [UMatrix; UMatrix; UMatrix], supports_soa);
add_unqualified
(name, ReturnType UMatrix, [UReal; UMatrix; UReal], supports_soa);
add_unqualified
(name, ReturnType UMatrix, [UReal; UMatrix; UMatrix], supports_soa);
add_unqualified
(name, ReturnType UMatrix, [UReal; UReal; UMatrix], supports_soa)
let for_all_vector_types s = List.iter ~f:s all_vector_types
let for_vector_types s = List.iter ~f:s vector_types
(* -- Start populating stan_math_signaturess -- *)
let () =
List.iter declarative_fnsigs ~f:(fun (key, rt, args, mem_pattern) ->
Hashtbl.add_multi stan_math_signatures ~key ~data:(rt, args, mem_pattern));
add_unqualified ("acos", ReturnType UComplex, [UComplex], AoS);
add_unqualified ("acosh", ReturnType UComplex, [UComplex], AoS);
List.iter
~f:(fun x -> add_unqualified ("add", ReturnType x, [x; x], SoA))
bare_types;
add_unqualified ("add", ReturnType UVector, [UVector; UReal], SoA);
add_unqualified ("add", ReturnType URowVector, [URowVector; UReal], SoA);
add_unqualified ("add", ReturnType UMatrix, [UMatrix; UReal], SoA);
add_unqualified ("add", ReturnType UVector, [UReal; UVector], SoA);
add_unqualified ("add", ReturnType URowVector, [UReal; URowVector], SoA);
add_unqualified ("add", ReturnType UMatrix, [UReal; UMatrix], SoA);
add_unqualified
("add", ReturnType UComplexVector, [UComplexVector; UComplex], SoA);
add_unqualified
("add", ReturnType UComplexRowVector, [UComplexRowVector; UComplex], SoA);
add_unqualified
("add", ReturnType UComplexMatrix, [UComplexMatrix; UComplex], SoA);
add_unqualified
("add", ReturnType UComplexVector, [UComplex; UComplexVector], SoA);
add_unqualified
("add", ReturnType UComplexRowVector, [UComplex; UComplexRowVector], SoA);
add_unqualified
("add", ReturnType UComplexMatrix, [UComplex; UComplexMatrix], SoA);
add_unqualified ("add_diag", ReturnType UMatrix, [UMatrix; UReal], AoS);
add_unqualified ("add_diag", ReturnType UMatrix, [UMatrix; UVector], AoS);
add_unqualified ("add_diag", ReturnType UMatrix, [UMatrix; URowVector], AoS);
add_unqualified
("add_diag", ReturnType UComplexMatrix, [UComplexMatrix; UComplex], AoS);
add_unqualified
( "add_diag"
, ReturnType UComplexMatrix
, [UComplexMatrix; UComplexVector]
, AoS );
add_unqualified
( "add_diag"
, ReturnType UComplexMatrix
, [UComplexMatrix; UComplexRowVector]
, AoS );
add_qualified
( "algebra_solver"
, ReturnType UVector
, [ ( AutoDiffable
, UFun
( [ (AutoDiffable, UVector); (AutoDiffable, UVector)
; (DataOnly, UArray UReal); (DataOnly, UArray UInt) ]
, ReturnType UVector
, FnPlain
, AoS ) ); (AutoDiffable, UVector); (AutoDiffable, UVector)
; (DataOnly, UArray UReal); (DataOnly, UArray UInt) ]
, AoS );
add_qualified
( "algebra_solver"
, ReturnType UVector
, [ ( AutoDiffable
, UFun
( [ (AutoDiffable, UVector); (AutoDiffable, UVector)
; (DataOnly, UArray UReal); (DataOnly, UArray UInt) ]
, ReturnType UVector
, FnPlain
, Mem_pattern.AoS ) ); (AutoDiffable, UVector)
; (AutoDiffable, UVector); (DataOnly, UArray UReal)
; (DataOnly, UArray UInt); (DataOnly, UReal); (DataOnly, UReal)
; (DataOnly, UReal) ]
, AoS );
add_qualified
( "algebra_solver_newton"
, ReturnType UVector
, [ ( AutoDiffable
, UFun
( [ (AutoDiffable, UVector); (AutoDiffable, UVector)
; (DataOnly, UArray UReal); (DataOnly, UArray UInt) ]
, ReturnType UVector
, FnPlain
, Mem_pattern.AoS ) ); (AutoDiffable, UVector)
; (AutoDiffable, UVector); (DataOnly, UArray UReal)
; (DataOnly, UArray UInt) ]
, AoS );
add_qualified
( "algebra_solver_newton"
, ReturnType UVector
, [ ( AutoDiffable
, UFun
( [ (AutoDiffable, UVector); (AutoDiffable, UVector)
; (DataOnly, UArray UReal); (DataOnly, UArray UInt) ]
, ReturnType UVector
, FnPlain
, Mem_pattern.AoS ) ); (AutoDiffable, UVector)
; (AutoDiffable, UVector); (DataOnly, UArray UReal)
; (DataOnly, UArray UInt); (DataOnly, UReal); (DataOnly, UReal)
; (DataOnly, UReal) ]
, AoS );
List.iter
~f:(fun i ->
List.iter
~f:(fun t ->
add_unqualified
( "append_array"
, ReturnType (bare_array_type (t, i))
, [bare_array_type (t, i); bare_array_type (t, i)]
, AoS ))
bare_types)
(List.range 1 8);
add_unqualified ("arg", ReturnType UReal, [UComplex], AoS);
add_unqualified ("asin", ReturnType UComplex, [UComplex], AoS);
add_unqualified ("asinh", ReturnType UComplex, [UComplex], AoS);
add_unqualified ("atan", ReturnType UComplex, [UComplex], AoS);
add_unqualified ("atanh", ReturnType UComplex, [UComplex], AoS);
add_binary_vec "atan2" AoS;
add_unqualified
( "bernoulli_logit_glm_lpmf"
, ReturnType UReal
, [UArray UInt; UMatrix; UVector; UVector]
, SoA );
add_unqualified
( "bernoulli_logit_glm_lpmf"
, ReturnType UReal
, [UInt; UMatrix; UVector; UVector]
, SoA );
add_unqualified
( "bernoulli_logit_glm_lpmf"
, ReturnType UReal
, [UArray UInt; URowVector; UReal; UVector]
, SoA );
add_unqualified
( "bernoulli_logit_glm_lpmf"
, ReturnType UReal
, [UArray UInt; URowVector; UVector; UVector]
, SoA );
add_unqualified
( "bernoulli_logit_glm_rng"
, ReturnType (UArray UInt)
, [UMatrix; UVector; UVector]
, AoS );
add_unqualified
( "bernoulli_logit_glm_rng"
, ReturnType (UArray UInt)
, [URowVector; UVector; UVector]
, AoS );
add_unqualified
( "binomial_logit_glm_lpmf"
, ReturnType UReal
, [UArray UInt; UArray UInt; UMatrix; UVector; UVector]
, SoA );
add_unqualified
( "binomial_logit_glm_lpmf"
, ReturnType UReal
, [UInt; UInt; UMatrix; UVector; UVector]
, SoA );
add_unqualified
( "binomial_logit_glm_lpmf"
, ReturnType UReal
, [UArray UInt; UArray UInt; URowVector; UReal; UVector]
, SoA );
add_unqualified
( "binomial_logit_glm_lpmf"
, ReturnType UReal
, [UArray UInt; UArray UInt; URowVector; UVector; UVector]
, SoA );
add_binary_vec_int_real "bessel_first_kind" SoA;
add_binary_vec_int_real "bessel_second_kind" SoA;
add_binary_vec "beta" SoA;
(* XXX For some reason beta_proportion_rng doesn't take ints as first arg *)
for_vector_types (fun t ->
for_all_vector_types (fun u ->
add_unqualified
( "beta_proportion_rng"
, ReturnType (rng_return_type UReal [t; u])
, [t; u]
, AoS )));
add_binary_vec_int_real "binary_log_loss" AoS;
add_unqualified
("block", ReturnType UMatrix, [UMatrix; UInt; UInt; UInt; UInt], SoA);
add_unqualified
( "block"
, ReturnType UComplexMatrix
, [UComplexMatrix; UInt; UInt; UInt; UInt]
, AoS );
add_unqualified ("categorical_rng", ReturnType UInt, [UVector], AoS);
add_unqualified ("categorical_logit_rng", ReturnType UInt, [UVector], AoS);
add_unqualified
( "categorical_logit_glm_lpmf"
, ReturnType UReal
, [UArray UInt; URowVector; UVector; UMatrix]
, SoA );
add_unqualified
( "categorical_logit_glm_lpmf"
, ReturnType UReal
, [UInt; URowVector; UVector; UMatrix]
, SoA );
add_unqualified ("append_col", ReturnType UMatrix, [UMatrix; UMatrix], AoS);
add_unqualified ("append_col", ReturnType UMatrix, [UVector; UMatrix], AoS);
add_unqualified ("append_col", ReturnType UMatrix, [UMatrix; UVector], AoS);
add_unqualified ("append_col", ReturnType UMatrix, [UVector; UVector], AoS);
add_unqualified
("append_col", ReturnType URowVector, [URowVector; URowVector], AoS);
add_unqualified ("append_col", ReturnType URowVector, [UReal; URowVector], AoS);
add_unqualified ("append_col", ReturnType URowVector, [URowVector; UReal], AoS);
add_unqualified
( "append_col"
, ReturnType UComplexMatrix
, [UComplexMatrix; UComplexMatrix]
, AoS );
add_unqualified
( "append_col"
, ReturnType UComplexMatrix
, [UComplexVector; UComplexMatrix]
, AoS );
add_unqualified
( "append_col"
, ReturnType UComplexMatrix
, [UComplexMatrix; UComplexVector]
, AoS );
add_unqualified
( "append_col"
, ReturnType UComplexMatrix
, [UComplexVector; UComplexVector]
, AoS );
add_unqualified
( "append_col"
, ReturnType UComplexRowVector
, [UComplexRowVector; UComplexRowVector]
, AoS );
add_unqualified
( "append_col"
, ReturnType UComplexRowVector
, [UComplex; UComplexRowVector]
, AoS );
add_unqualified
( "append_col"
, ReturnType UComplexRowVector
, [UComplexRowVector; UComplex]
, AoS );
add_unqualified ("chol2inv", ReturnType UMatrix, [UMatrix], AoS);
add_unqualified ("cholesky_decompose", ReturnType UMatrix, [UMatrix], SoA);
add_binary_vec_int_int "choose" AoS;
add_unqualified ("col", ReturnType UVector, [UMatrix; UInt], AoS);
add_unqualified ("col", ReturnType UComplexVector, [UComplexMatrix; UInt], SoA);
add_unqualified ("cols", ReturnType UInt, [UVector], SoA);
add_unqualified ("cols", ReturnType UInt, [URowVector], SoA);
add_unqualified ("cols", ReturnType UInt, [UMatrix], SoA);
add_unqualified ("cols", ReturnType UInt, [UComplexVector], SoA);
add_unqualified ("cols", ReturnType UInt, [UComplexRowVector], SoA);
add_unqualified ("cols", ReturnType UInt, [UComplexMatrix], SoA);
add_unqualified
("columns_dot_product", ReturnType URowVector, [UVector; UVector], AoS);
add_unqualified
("columns_dot_product", ReturnType URowVector, [URowVector; URowVector], AoS);
add_unqualified
("columns_dot_product", ReturnType URowVector, [UMatrix; UMatrix], SoA);
add_unqualified