alphaville/optimization-engine

Objective and Gradient Compilation Error due to FnMut vs. Fn Closures

開放

#139 建立於 2019年10月25日

 (3 則留言) (0 個反應) (1 位負責人)Rust (69 個分叉)auto 404
enhancementgood first issuerust

倉庫指標

星標
 (642 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Hi! I am very new to Rust, so I apologize if this ends up being a naive question.

So, for my robot motion optimization application, I have created an objective function and gradient function in the required format using closures, but the closure types are FnMut’s rather than Fn’s. This leads to the compiler complaining since the OpEn library forces the objective and gradient functions to be Fn’s. However, it is necessary in my case that the closures be able to mutate data from outside of their function. For example, the gradient is calculated using hyper-dual automatic differentiation, which has to be able to access and mutate aspects of the objective function variables. Further, the objective is calculated by mutating a reference to a large robot manipulator kinematic and dynamics model, that would be extremely costly to reinitialize at each update in order to meet the Fn requirement.

Would it be possible to accommodate closure types of FnMut for the objective and gradient? As far as I can tell, this shouldn’t change anything at the optimization level: the objective will still just output an f64, and the gradient will still update accordingly. Any help would be appreciated. Thanks!

貢獻者指南