-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Description
Some basic math functions are missing generic implementations. Among these are exp
, sin
, cos
, sinh
, and cosh
, although likely there are several others that should be included. From this list, all the functions can be evaluated in terms of exp
. Functions like tan
and tanh
should be re-assessed once these others are fixed. Functions like acos
, asin
, etc, are a bit more complicated but should probably get a look eventually.
exp(::T)
should work for any type for which evalpoly
can be made to work, which requires *(::T,::T)
and +(::UniformScaling{<:Number},::T)
(in place of the UniformScaling
method, oneunit(::T)
, *(::Number,::T)
, and +(::T,::T)
can serve). Accurate results are much easier to achieve if opnorm(::T)
is defined, although a different implementation of the polynomial evaluation could continue the Taylor series until convergence (at a potentially-significant computational cost).
For example, these functions cannot be used with matrices of dual numbers or quaternions:
# Julia v1.9.1
julia> using ForwardDiff
julia> ForwardDiff.derivative(t->exp([0 t; 0 0]),1.0)
ERROR: MethodError: no method matching exp!(::Matrix{ForwardDiff.Dual{ForwardDiff.Tag{var"#89#90", Float64}, Float64, 1}})
Closest candidates are:
exp!(::StridedMatrix{T}) where T<:Union{Float32, Float64, ComplexF64, ComplexF32}
@ LinearAlgebra ~/julia-1.9.1/share/julia/stdlib/v1.9/LinearAlgebra/src/dense.jl:649
julia> using Quaternions
julia> exp([0 quat(1.0); 0 0])
ERROR: MethodError: no method matching exp!(::Matrix{QuaternionF64})
Closest candidates are:
exp!(::StridedMatrix{T}) where T<:Union{Float32, Float64, ComplexF64, ComplexF32}
@ LinearAlgebra ~/julia-1.9.1/share/julia/stdlib/v1.9/LinearAlgebra/src/dense.jl:649
The listed functions do have methods with ::AbstractMatrix
signatures, but they fail like here when the elements do not promote to LinearAlgebra.BlasFloat
types. In any case, a suitable fallback should work for types other than matrices, too.
It's not critical that these functions be fast, but they should exist and be mostly accurate (to the extent that we can predict what inputs might occur).