@@ -241,52 +241,29 @@ function Base.fill!(Ψ::GradVector, v)
241241end
242242
243243
244- # === Matrix interface for GradgenOperator ===
245- #
246- # The following methods are part of the matrix interface and are only
247- # meaningful when `supports_matrix_interface` is true for both component types.
248- # Each method delegates to a private `_name(::Val{supports}, ...)` function:
249- # the Val{true} method contains the implementation, and the Val{false} method
250- # throws an error.
251-
252- function _size (
253- :: Val{true} ,
254- O:: GradgenOperator{num_controls,GT,CGT}
255- ) where {num_controls,GT,CGT}
244+ function Base. size (O:: GradgenOperator{num_controls,GT,CGT} ) where {num_controls,GT,CGT}
256245 return (num_controls + 1 ) .* size (O. G)
257246end
258247
259- function _size (:: Val{false} , O:: GradgenOperator )
260- error (" $(typeof (O)) does not support the matrix interface" )
261- end
262-
263- function Base. size (O:: T ) where {T<: GradgenOperator }
264- return _size (Val (supports_matrix_interface (T)), O)
265- end
266-
267-
268- function _size (
269- :: Val{true} ,
270- O:: GradgenOperator{num_controls,GT,CGT} ,
271- dim:: Integer
272- ) where {num_controls,GT,CGT}
248+ function Base. size (O:: GradgenOperator{num_controls,GT,CGT} , dim:: Integer ) where {num_controls,GT,CGT}
273249 return (num_controls + 1 ) * size (O. G, dim)
274250end
275251
276- function _size (:: Val{false} , O:: GradgenOperator , dim:: Integer )
277- error (" $(typeof (O)) does not support the matrix interface" )
278- end
279252
280- function Base. size (O:: T , dim:: Integer ) where {T<: GradgenOperator }
281- return _size (Val (supports_matrix_interface (T)), O, dim)
282- end
253+ # === Matrix interface for GradgenOperator ===
254+ #
255+ # The following methods are part of the matrix interface and are only
256+ # meaningful when `supports_matrix_interface` is true for both component types.
257+ # Each method delegates to a private `_name(::Val{supports}, ...)` function:
258+ # the Val{true} method contains the implementation, and the Val{false} method
259+ # throws an error. Note that this does not include `size`, which must be
260+ # defined for _all_ operators, whether or not they define the full matrix
261+ # interface.
283262
284263
285264# As for an `Operator`, we implement `similar` to return a standard `Array`
286265# because `GradgenOperator` does not `setindex!`, so it's arguably not a
287266# "mutable array" even if its components are mutable.
288- # similar(O) and similar(O, S) call size(O), which will error if
289- # !supports_matrix_interface. The dims-based variants need no guard.
290267Base. similar (G:: GradgenOperator ) = Array {eltype(G)} (undef, size (G))
291268
292269Base. similar (O:: GradgenOperator , :: Type{S} ) where {S} = Array {S} (undef, size (O))
0 commit comments