@@ -11,6 +11,11 @@ performing transformations. Subtypes should be able to apply a coordinate system
11
11
transformation on the correct data types by overloading `transform()`, and
12
12
usually would have the corresponding inverse transformation defined by `Base.inv()`.
13
13
Efficient compositions can optionally be defined by `compose()` (equivalently `∘`).
14
+
15
+ Furthermore, transformations can be combined in a tuple to be applied in parallel
16
+ to a tuple of inputs (for example, performing a rotation on a spatial variable
17
+ while leaving the time variable constant). This becomes particularly powerful
18
+ when
14
19
"""
15
20
abstract AbstractTransformation{OutType, InType}
16
21
45
50
return :($ (S. parameters[1 ]))
46
51
end
47
52
53
+ # TODO generated functions for intype and outtype of tuples of AbstractTransformations
54
+
48
55
49
56
# Built-in identity transform
50
57
immutable IdentityTransformation{T} <: AbstractTransformation{T,T} ; end
@@ -63,13 +70,25 @@ function transform{OutType, InType}(trans::AbstractTransformation{OutType, InTyp
63
70
end
64
71
end
65
72
73
+ """
74
+ transform((trans1, trans2, ...), (x1, x2, ...))
75
+
76
+ A set of transformations `trans1`, etc, are applied in parallel to data `x1`, etc,
77
+ returning a tuple of the transformed coordinates.
78
+ """
79
+ function transform {N} (trans:: NTuple{N,AbstractTransformation} , x:: NTuple{N} )
80
+ # TODO generated function for type stability in Julia 0.4
81
+ return ntuple (i-> transform (trans[i], x[i]), Val{N})
82
+ end
83
+
66
84
transform {T} (:: IdentityTransformation{T} , x:: T ) = x
67
85
86
+
68
87
"""
69
88
A `ComposedTransformation` simply executes two transformations successively, and
70
89
is the fallback output type of `compose()`.
71
90
"""
72
- immutable ComposedTransformation{OutType, InType, T1 <: AbstractTransformation , T2 <: AbstractTransformation } <: AbstractTransformation{OutType, InType}
91
+ immutable ComposedTransformation{OutType, InType, T1 <: Union{ AbstractTransformation, Tuple{Vararg{AbstractTransformation}}} , T2 <: Union{ AbstractTransformation, Tuple{Vararg{AbstractTransformation}}} } <: AbstractTransformation{OutType, InType}
73
92
t1:: T1
74
93
t2:: T2
75
94
@@ -78,7 +97,7 @@ immutable ComposedTransformation{OutType, InType, T1 <: AbstractTransformation,
78
97
new (trans1,trans2)
79
98
end
80
99
end
81
- @generated function check_composable {OutType, InType} (out_type:: Type{OutType} ,in_type:: Type{InType} ,trans1:: AbstractTransformation , trans2:: AbstractTransformation )
100
+ @generated function check_composable {OutType, InType} (out_type:: Type{OutType} ,in_type:: Type{InType} ,trans1:: Union{ AbstractTransformation, Tuple{Vararg{AbstractTransformation}}} , trans2:: Union{ AbstractTransformation, Tuple{Vararg{AbstractTransformation}}} )
82
101
if InType != intype (trans2)
83
102
str = " Can't compose transformations: input coordinates types $InType and $(intype (trans2)) do not match."
84
103
error (str)
@@ -117,6 +136,8 @@ compose{InOutType}(trans::IdentityTransformation{InOutType}, ::IdentityTransform
117
136
compose {OutType, InType} (:: IdentityTransformation{OutType} , trans:: AbstractTransformation{OutType, InType} ) = trans
118
137
compose {OutType, InType} (trans:: AbstractTransformation{OutType, InType} , :: IdentityTransformation{InType} ) = trans
119
138
139
+ # TODO compose for tuples of AbstractTransformations (generated function)
140
+
120
141
const ∘ = compose
121
142
122
143
"""
131
152
Base. inv (trans:: ComposedTransformation ) = inv (trans. t2) ∘ inv (trans. t1)
132
153
Base. inv (trans:: IdentityTransformation ) = trans
133
154
155
+ # TODO compose for inverse of AbstractTransformations (generated function)
156
+
134
157
"""
135
158
transform_deriv(trans::AbstractTransformation, x)
136
159
@@ -148,6 +171,8 @@ function transform_deriv{OutType, InType}(trans::ComposedTransformation{OutType,
148
171
return m1 * m2
149
172
end
150
173
174
+ # TODO compose for derivatives of AbstractTransformations (generated function)
175
+
151
176
"""
152
177
transform_deriv_params(trans::AbstractTransformation, x)
153
178
@@ -165,3 +190,5 @@ function transform_deriv_params{OutType, InType}(trans::ComposedTransformation{O
165
190
p1 = transform_deriv_params (trans. t1, x2)
166
191
return hcat (p1, m1* p2)
167
192
end
193
+
194
+ # TODO compose for parameter derivatives of AbstractTransformations (generated function)
0 commit comments