1
1
# returns all variables of a cost function, in terms of appearance
2
2
extract_variables (t:: Term ) = variables (t)
3
3
4
- function extract_variables {N} (t:: NTuple{N,Term} )
4
+ function extract_variables (t:: NTuple{N,Term} ) where {N}
5
5
x = variables .(t)
6
6
xAll = x[1 ]
7
7
for i = 2 : length (x)
@@ -21,15 +21,15 @@ function extract_functions(t::Term)
21
21
# TODO change this
22
22
return f
23
23
end
24
- extract_functions {N} (t:: NTuple{N,Term} ) = SeparableSum (extract_functions .(t))
24
+ extract_functions (t:: NTuple{N,Term} ) where {N} = SeparableSum (extract_functions .(t))
25
25
extract_functions (t:: Tuple{Term} ) = extract_functions (t[1 ])
26
26
27
27
# extract functions from terms without displacement
28
28
function extract_functions_nodisp (t:: Term )
29
29
f = t. lambda == 1. ? t. f : Postcompose (t. f, t. lambda)
30
30
return f
31
31
end
32
- extract_functions_nodisp {N} (t:: NTuple{N,Term} ) = SeparableSum (extract_functions_nodisp .(t))
32
+ extract_functions_nodisp (t:: NTuple{N,Term} ) where {N} = SeparableSum (extract_functions_nodisp .(t))
33
33
extract_functions_nodisp (t:: Tuple{Term} ) = extract_functions_nodisp (t[1 ])
34
34
35
35
# extract operators from terms
@@ -39,10 +39,10 @@ extract_functions_nodisp(t::Tuple{Term}) = extract_functions_nodisp(t[1])
39
39
# single term, single variable
40
40
extract_operators (xAll:: Tuple{Variable} , t:: Term ) = operator (t)
41
41
42
- extract_operators {N} (xAll:: NTuple{N,Variable} , t:: Term ) = extract_operators (xAll, (t,))
42
+ extract_operators (xAll:: NTuple{N,Variable} , t:: Term ) where {N} = extract_operators (xAll, (t,))
43
43
44
44
# multiple terms, multiple variables
45
- function extract_operators {N,M} (xAll:: NTuple{N,Variable} , t:: NTuple{M,Term} )
45
+ function extract_operators (xAll:: NTuple{N,Variable} , t:: NTuple{M,Term} ) where {N,M}
46
46
ops = ()
47
47
for ti in t
48
48
tex = expand (xAll,ti)
53
53
54
54
sort_and_extract_operators (xAll:: Tuple{Variable} , t:: Term ) = operator (t)
55
55
56
- function sort_and_extract_operators {N} (xAll:: NTuple{N,Variable} , t:: Term )
56
+ function sort_and_extract_operators (xAll:: NTuple{N,Variable} , t:: Term ) where {N}
57
57
p = zeros (Int,N)
58
58
xL = variables (t)
59
59
for i in eachindex (xAll)
69
69
# single term, single variable
70
70
extract_affines (xAll:: Tuple{Variable} , t:: Term ) = affine (t)
71
71
72
- extract_affines {N} (xAll:: NTuple{N,Variable} , t:: Term ) = extract_affines (xAll, (t,))
72
+ extract_affines (xAll:: NTuple{N,Variable} , t:: Term ) where {N} = extract_affines (xAll, (t,))
73
73
74
74
# multiple terms, multiple variables
75
- function extract_affines {N,M} (xAll:: NTuple{N,Variable} , t:: NTuple{M,Term} )
75
+ function extract_affines (xAll:: NTuple{N,Variable} , t:: NTuple{M,Term} ) where {N,M}
76
76
ops = ()
77
77
for ti in t
78
78
tex = expand (xAll,ti)
83
83
84
84
sort_and_extract_affines (xAll:: Tuple{Variable} , t:: Term ) = affine (t)
85
85
86
- function sort_and_extract_affines {N} (xAll:: NTuple{N,Variable} , t:: Term )
86
+ function sort_and_extract_affines (xAll:: NTuple{N,Variable} , t:: Term ) where {N}
87
87
p = zeros (Int,N)
88
88
xL = variables (t)
89
89
for i in eachindex (xAll)
@@ -93,7 +93,7 @@ function sort_and_extract_affines{N}(xAll::NTuple{N,Variable}, t::Term)
93
93
end
94
94
95
95
# expand term domain dimensions
96
- function expand {N,T1,T2,T3} (xAll:: NTuple{N,Variable} , t:: Term{T1,T2,T3} )
96
+ function expand (xAll:: NTuple{N,Variable} , t:: Term{T1,T2,T3} ) where {N,T1,T2,T3}
97
97
xt = variables (t)
98
98
C = codomainType (operator (t))
99
99
size_out = size (operator (t),1 )
165
165
166
166
extract_proximable (xAll:: Variable , t:: Term ) = extract_merge_functions (t)
167
167
extract_proximable (xAll:: NTuple{N,Variable} , t:: Term ) where {N} = extract_proximable (xAll,(t,))
168
-
0 commit comments