Skip to content

Commit

Permalink
Use input type to construct return types
Browse files Browse the repository at this point in the history
  • Loading branch information
saschatimme committed Nov 5, 2017
1 parent 8fcdd52 commit 337278f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ end
gradient(g, x, cfg::GradientConfig[, precomputed=false])
Compute the gradient of `g` at `x` using the precomputated values in `cfg`.
The return vector is constructed using `similar(x, T)`.
### Example
```julia
Expand All @@ -310,7 +311,7 @@ the result is only correct if you previouls called `evaluate`, or `gradient` wit
`x`.
"""
function gradient(g::Polynomial, x::AbstractVector, cfg::GradientConfig{T}, precomputed=false) where T
u = zeros(T, nvariables(g))
u = similar(x, T, nvariables(g))
gradient!(u, g, x, cfg, precomputed)
u
end
Expand Down Expand Up @@ -467,6 +468,7 @@ end
Evaluate the system `F` at `x` using the precomputated values in `cfg`.
Note that this is usually signifcant faster than `map(f -> evaluate(f, x), F)`.
The return vector is constructed using `similar(x, T)`.
### Example
```julia
Expand All @@ -479,7 +481,7 @@ the result is only correct if you previouls called `evaluate`, or `jacobian` wit
`x`.
"""
function evaluate(G::Vector{<:Polynomial}, x::AbstractVector, cfg::JacobianConfig{T}, precomputed=false) where T
evaluate!(zeros(T, length(G)), G, x, cfg, precomputed)
evaluate!(similar(x, T, length(G)), G, x, cfg, precomputed)
end

"""
Expand Down Expand Up @@ -515,9 +517,10 @@ function evaluate!(u::AbstractVector, G::Vector{<:Polynomial}, x::AbstractVector
end

"""
jacobian!(u, F, x, cfg::JacobianConfig [, precomputed=false])
jacobian(u, F, x, cfg::JacobianConfig [, precomputed=false])
Evaluate the jacobian of `F` at `x` using the precomputated values in `cfg`.
Evaluate the jacobian of `F` at `x` using the precomputated values in `cfg`. The return
matrix is constructed using `similar(x, T, m, n)`.
### Example
```julia
Expand All @@ -530,7 +533,7 @@ the result is only correct if you previouls called `evaluate`, or `jacobian` wit
`x`.
"""
function jacobian(g::Vector{<:Polynomial}, x::AbstractVector, cfg::JacobianConfig{T}, precomputed=false) where T
u = zeros(T, length(g), length(x))
u = similar(x, T, (length(g), length(x)))
jacobian!(u, g, x, cfg, precomputed)
u
end
Expand Down

0 comments on commit 337278f

Please sign in to comment.