Skip to content

Type of sunpos is too restrictive for use with ForwardDiff #73

Closed
@NOTtheMessiah

Description

sunpos is intended "either a scalar or a vector" as per consistency with the IDL Astronomy User's Library, however the implementation of it does not take advantage of multiple dispatch, rather it relies on a single-dispatch wrapper over that loops over the values of the vector input, does explicit type conversions, and passes it onto a hidden method _sunpos. This manner of implementation, seemingly based directly on IDL, is not Julian, as it's overly restrictive and gets in the way of metaprogramming and interoperability with other libraries such as ForwardDiff and IntervalRootFinding, useful for differentiating and solving. ForwardDiff tries to generalize over Dual numbers and spits out this type error when it encounters a method defined only over floats:
MethodError: no method matching _sunpos(::ForwardDiff.Dual{ForwardDiff.Tag{typeof(f), Float64}, Float64, 1}, ::Bool) Closest candidates are: _sunpos(!Matched::AbstractFloat, ::Bool) at ~/.julia/packages/AstroLib/Yq5lS/src/sunpos.jl:4

A more Julian implementation would define two methods, one defined over reals, and the other defined on vectors of reals, and not force floats.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions