@@ -136,30 +136,15 @@ hcat(tvs::Transpose{T,Vector{T}}...) where {T} = _transpose_hcat(tvs...)
136
136
# ## higher order functions
137
137
# preserve Adjoint/Transpose wrapper around vectors
138
138
# to retain the associated semantics post-map/broadcast
139
-
140
- # vectorfy takes an Adoint/Transpose-wrapped vector and builds
141
- # an unwrapped vector with the entrywise-same contents
142
- vectorfy (x:: Number ) = x
143
- vectorfy (adjvec:: AdjointAbsVec ) = map (Adjoint, adjvec. parent)
144
- vectorfy (transvec:: TransposeAbsVec ) = map (Transpose, transvec. parent)
145
- vectorfyall (transformedvecs... ) = (map (vectorfy, transformedvecs)... ,)
146
-
147
- # map over collections of Adjoint/Transpose-wrapped vectors
148
- # note that the caller's operation `f` should be applied to the entries of the wrapped
149
- # vectors, rather than the entires of the wrapped vector's parents. so first we use vectorfy
150
- # to build unwrapped vectors with entrywise-same contents as the wrapped input vectors.
151
- # then we map the caller's operation over that set of unwrapped vectors. but now re-wrapping
152
- # the resulting vector would inappropriately transform the result vector's entries. so
153
- # instead of simply mapping the caller's operation over the set of unwrapped vectors,
154
- # we map Adjoint/Transpose composed with the caller's operationt over the set of unwrapped
155
- # vectors. then re-wrapping the result vector yields a wrapped vector with the correct entries.
156
- map (f, avs:: AdjointAbsVec... ) = Adjoint (map (Adjoint∘ f, vectorfyall (avs... )... ))
157
- map (f, tvs:: TransposeAbsVec... ) = Transpose (map (Transpose∘ f, vectorfyall (tvs... )... ))
158
-
159
- # broadcast over collections of Adjoint/Transpose-wrapped vectors and numbers
160
- # similar explanation for these definitions as for map above
161
- broadcast (f, avs:: Union{Number,AdjointAbsVec} ...) = Adjoint (broadcast (Adjoint∘ f, vectorfyall (avs... )... ))
162
- broadcast (f, tvs:: Union{Number,TransposeAbsVec} ...) = Transpose (broadcast (Transpose∘ f, vectorfyall (tvs... ) ... ))
139
+ #
140
+ # note that the caller's operation f operates in the domain of the wrapped vectors' entries.
141
+ # hence the Adjoint->f->Adjoint shenanigans applied to the parent vectors' entries.
142
+ map (f, avs:: AdjointAbsVec... ) = Adjoint (map ((xs... ) -> Adjoint (f (Adjoint .(xs)... )), parent .(avs)... ))
143
+ map (f, tvs:: TransposeAbsVec... ) = Transpose (map ((xs... ) -> Transpose (f (Transpose .(xs)... )), parent .(tvs)... ))
144
+ quasiparentt (x) = parent (x); quasiparentt (x:: Number ) = x # to handle numbers in the defs below
145
+ quasiparenta (x) = parent (x); quasiparenta (x:: Number ) = conj (x) # to handle numbers in the defs below
146
+ broadcast (f, avs:: Union{Number,AdjointAbsVec} ...) = Adjoint (broadcast ((xs... ) -> Adjoint (f (Adjoint .(xs)... )), quasiparenta .(avs)... ))
147
+ broadcast (f, tvs:: Union{Number,TransposeAbsVec} ...) = Transpose (broadcast ((xs... ) -> Transpose (f (Transpose .(xs)... )), quasiparentt .(tvs)... ))
163
148
164
149
165
150
# ## linear algebra
0 commit comments