@@ -106,6 +106,53 @@ function _domain_label(transformation::ArrayTransformation, index::Int)
106
106
_array_domain_label (inner_transformation, dims, index)
107
107
end
108
108
109
+ # ###
110
+ # ### array view
111
+ # ###
112
+
113
+ """
114
+ $(TYPEDEF)
115
+
116
+ View of an array with `dims`.
117
+
118
+ !!! note
119
+ This feature is experimental, and not part of the stable API; it may disappear or change without
120
+ relevant changes in SemVer or deprecations. Inner transformations are not supported.
121
+ """
122
+ struct ViewTransformation{M} <: VectorTransform
123
+ dims:: NTuple{M, Int}
124
+ end
125
+
126
+ function as (:: typeof (view), dims:: Tuple{Vararg{Int}} )
127
+ @argcheck all (d -> d ≥ 0 , dims) " All dimensions need to be non-negative."
128
+ ViewTransformation (dims)
129
+ end
130
+
131
+ as (:: typeof (view), dims:: Int... ) = as (view, dims)
132
+
133
+ dimension (transformation:: ViewTransformation ) = prod (transformation. dims)
134
+
135
+ function transform_with (flag:: LogJacFlag , t:: ViewTransformation , x, index)
136
+ index′ = index + dimension (t)
137
+ y = reshape (@view (x[index: (index′- 1 )]), t. dims)
138
+ y, logjac_zero (flag, robust_eltype (x)), index′
139
+ end
140
+
141
+ function _domain_label (transformation:: ViewTransformation , index:: Int )
142
+ @unpack dims = transformation
143
+ _array_domain_label (asℝ, dims, index)
144
+ end
145
+
146
+ inverse_eltype (transformation:: ViewTransformation , y) = eltype (y)
147
+
148
+ function inverse_at! (x:: AbstractVector , index, transformation:: ViewTransformation ,
149
+ y:: AbstractArray )
150
+ @argcheck size (y) == transformation. dims
151
+ index′ = index + dimension (transformation)
152
+ copy! (@view (x[index: (index′- 1 )]), vec (y))
153
+ index′
154
+ end
155
+
109
156
# ###
110
157
# ### static array
111
158
# ###
0 commit comments