Skip to content

Commit

Permalink
A little helper struct for feeding NLPs to JuMP.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Geoga committed Apr 3, 2023
1 parent 3143d9d commit 43e5ca5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/structstypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,21 @@ function RCholApplicationBuffer(U::RCholesky{T}, ndata::Int64, ::Val{V}) where{T
RCholApplicationBuffer{Z}(bufv, bufm, bufz, out)
end

# A struct wrapper of a function that handles argument splatting and also
# "converts" errors to NaNs. Very useful when feeding NLPs to JuMP.
struct WrapSplatted{F} <: Function
f::F
end
function (s::WrapSplatted{F})(p) where{F}
try
return s.f(p)
catch er
er isa InterruptException && rethrow(er)
return NaN
end
end
(s::WrapSplatted{F})(p...) where{F} = s(collect(p))

# Not good code or anything. Just a quick and dirty way to make a Vecchia object
# with a KD-tree to choose the conditioning points.
function kdtreeconfig(data, pts, chunksize, blockrank, kfun)
Expand Down

0 comments on commit 43e5ca5

Please sign in to comment.