Skip to content

non-concrete fields in structs are considered harmful #49

@jlapeyre

Description

@jlapeyre

epsilon here should be a concrete type

struct GRAPE <: AbstractGRAPE
max_episode::Int
epsilon::Number
end

There are many other similar structs in the code. See the doc on this.

Something like this is better

 struct GRAPE{T<:Number} <: AbstractGRAPE 
     max_episode::Int  
     epsilon::T
 end 

This allows the compiler to infer types in more situations. It also makes a more efficient layout.

The following line is in a tight loop and the type of epsilon is not known to the compiler. (I'm fairly sure, but could be missing something.) This means the code is probably not optimized for, say Float64.

dynamics.data.ctrl[cm][tm] = dynamics.data.ctrl[cm][tm] + alg.epsilon*δF

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions