@@ -39,17 +39,17 @@ Return `r::DiffResult`, with output value storage provided by `value` and output
39
39
storage provided by `derivs`.
40
40
41
41
In reality, `DiffResult` is an abstract supertype of two concrete types, `MutableDiffResult`
42
- and `ImmutableDiffResult`. If all `value`/`derivs` are all `Number`s or `SArray `s, then `r`
43
- will be immutable (i.e. `r::ImmutableDiffResult`). Otherwise, `r` will be mutable
42
+ and `ImmutableDiffResult`. If all `value`/`derivs` are all `Number`s or `StaticArray `s,
43
+ then `r` will be immutable (i.e. `r::ImmutableDiffResult`). Otherwise, `r` will be mutable
44
44
(i.e. `r::MutableDiffResult`).
45
45
46
46
Note that `derivs` can be provide in splatted form, i.e. `DiffResult(value, derivs...)`.
47
47
"""
48
48
DiffResult
49
49
50
50
DiffResult (value:: Number , derivs:: Tuple{Vararg{Number}} ) = ImmutableDiffResult (value, derivs)
51
- DiffResult (value:: Number , derivs:: Tuple{Vararg{SArray }} ) = ImmutableDiffResult (value, derivs)
52
- DiffResult (value:: SArray , derivs:: Tuple{Vararg{SArray }} ) = ImmutableDiffResult (value, derivs)
51
+ DiffResult (value:: Number , derivs:: Tuple{Vararg{StaticArray }} ) = ImmutableDiffResult (value, derivs)
52
+ DiffResult (value:: StaticArray , derivs:: Tuple{Vararg{StaticArray }} ) = ImmutableDiffResult (value, derivs)
53
53
DiffResult (value:: Number , derivs:: Tuple{Vararg{AbstractArray}} ) = MutableDiffResult (value, derivs)
54
54
DiffResult (value:: AbstractArray , derivs:: Tuple{Vararg{AbstractArray}} ) = MutableDiffResult (value, derivs)
55
55
DiffResult (value:: Union{Number,AbstractArray} , derivs:: Union{Number,AbstractArray} ...) = DiffResult (value, derivs)
@@ -65,7 +65,7 @@ shape information. If you want to allocate storage yourself, use the `DiffResult
65
65
constructor instead.
66
66
"""
67
67
GradientResult (x:: AbstractArray ) = DiffResult (first (x), similar (x))
68
- GradientResult (x:: SArray ) = DiffResult (first (x), x)
68
+ GradientResult (x:: StaticArray ) = DiffResult (first (x), x)
69
69
70
70
"""
71
71
JacobianResult(x::AbstractArray)
@@ -79,7 +79,7 @@ shape information. If you want to allocate storage yourself, use the `DiffResult
79
79
constructor instead.
80
80
"""
81
81
JacobianResult (x:: AbstractArray ) = DiffResult (similar (x), similar (x, length (x), length (x)))
82
- JacobianResult (x:: SArray{<:Any,T,<:Any,L} ) where {T,L} = DiffResult (x, zeros (SMatrix{L,L,T} ))
82
+ JacobianResult (x:: StaticArray ) = DiffResult (x, zeros (StaticArrays . similar_type ( typeof (x), Size ( length (x), length (x))) ))
83
83
84
84
"""
85
85
JacobianResult(y::AbstractArray, x::AbstractArray)
@@ -92,7 +92,7 @@ Like the single argument version, `y` and `x` are only used for type and
92
92
shape information and are not stored in the returned `DiffResult`.
93
93
"""
94
94
JacobianResult (y:: AbstractArray , x:: AbstractArray ) = DiffResult (similar (y), similar (y, length (y), length (x)))
95
- JacobianResult (y:: SArray{<:Any,<:Any,<:Any,Y} , x:: SArray{<:Any,T,<:Any,X} ) where {T,Y,X} = DiffResult (y, zeros (SMatrix{Y,X,T} ))
95
+ JacobianResult (y:: StaticArray , x:: StaticArray ) = DiffResult (y, zeros (StaticArrays . similar_type ( typeof (x), Size ( length (y), length (x))) ))
96
96
97
97
"""
98
98
HessianResult(x::AbstractArray)
@@ -105,7 +105,7 @@ shape information. If you want to allocate storage yourself, use the `DiffResult
105
105
constructor instead.
106
106
"""
107
107
HessianResult (x:: AbstractArray ) = DiffResult (first (x), similar (x), similar (x, length (x), length (x)))
108
- HessianResult (x:: SArray{<:Any,T,<:Any,L} ) where {T,L} = DiffResult (first (x), x, zeros (SMatrix{L,L,T} ))
108
+ HessianResult (x:: StaticArray ) = DiffResult (first (x), x, zeros (StaticArrays . similar_type ( typeof (x), Size ( length (x), length (x))) ))
109
109
110
110
# ############
111
111
# Interface #
@@ -203,7 +203,7 @@ function derivative!(r::MutableDiffResult, x::AbstractArray, ::Type{Val{i}} = Va
203
203
return r
204
204
end
205
205
206
- function derivative! (r:: ImmutableDiffResult , x:: Union{Number,SArray } , :: Type{Val{i}} = Val{1 }) where {i}
206
+ function derivative! (r:: ImmutableDiffResult , x:: Union{Number,StaticArray } , :: Type{Val{i}} = Val{1 }) where {i}
207
207
return ImmutableDiffResult (value (r), tuple_setindex (r. derivs, x, Val{i}))
208
208
end
209
209
@@ -232,7 +232,7 @@ function derivative!(f, r::ImmutableDiffResult, x::Number, ::Type{Val{i}} = Val{
232
232
return derivative! (r, f (x), Val{i})
233
233
end
234
234
235
- function derivative! (f, r:: ImmutableDiffResult , x:: SArray , :: Type{Val{i}} = Val{1 }) where {i}
235
+ function derivative! (f, r:: ImmutableDiffResult , x:: StaticArray , :: Type{Val{i}} = Val{1 }) where {i}
236
236
return derivative! (r, map (f, x), Val{i})
237
237
end
238
238
0 commit comments