I was surprised by this:
julia> sqrt(5.0I)
ERROR: MethodError: no method matching sqrt(::UniformScaling{Float64})
Closest candidates are:
sqrt(::Float16) at math.jl:1085
sqrt(::Complex{Float16}) at math.jl:1086
sqrt(::Missing) at math.jl:1138
...
Stacktrace:
[1] top-level scope at REPL[25]:1
julia> sqrt(Matrix(5I, 5, 5))
5脳5 Array{Float64,2}:
2.23607 0.0 0.0 0.0 0.0
0.0 2.23607 0.0 0.0 0.0
0.0 0.0 2.23607 0.0 0.0
0.0 0.0 0.0 2.23607 0.0
0.0 0.0 0.0 0.0 2.23607
Since we already have a few matrix functions defined, such as
https://github.com/JuliaLang/julia/blob/e36fe95a639c6956aa39367bef8e727b174e52b2/stdlib/LinearAlgebra/src/dense.jl#L702-L759
it would seem reasonable to expect at least these elementary functions to be defined for UniformScaling as well:
^(::UniformScaling, ::Number) (already added in https://github.com/JuliaLang/julia/pull/34008)exp, logexpm1, logp1sin, cos, tan, csc, sec, cot + inverses and hyperbolic versionssqrt, cbrtpinv, trreal, imag, reimAll of the above have been added in #28872, the question is now which additional functions are of interest, i.e. which are used for matrices? Candidates are
abs - one could argue that the matrix generalization is detabs(A) asQ*abs.(位)*Q', which is something different.abs2log10, log2exp2, exp10sinc, coscI am unsure if the functions below are sensible for matrices, possibly
with the exception of sinpi and cospi.
sinpi, cospisind, cosd, tand, secd, cscd, cotdasind, acosd, atand, asecd, acscd, acotddeg2rad, rad2degmod2piFrom #28872 remains also the idea of matrix decompositions.
Initial implementation: https://github.com/jagot/UniformScalingMatrixFunctions.jl
There was some initial effort made in #28872, but then got stale.
Good to know! Maybe that PR should be revived instead?
Yes. Actually, that PR had all that you are asking for here. So we could resolve merge conflicts there, merge, and open a new issue to track the ambitious unresolved broadcasting aspects.
sqrt
exp, log
sin, cos, tan + asin, acos, atan
sinh, cosh, tanh + asinh, acosh, atanh
other similar from Base.Math: cbrt , expm1, log1p
I've rebased #28872 and pushed to my fork. Just need to build and test and then make a new PR?
I've just resolved the merge conflicts there and one qualification issue, tests are running. If they pass, I'd suggest to merge #28872, and then continue from there.
Hmm, double work double the fun?
@antoine-levitt suggested this list of functions:
https://github.com/stevengj/ChangePrecision.jl/blob/402b3eec7710552b655555e8335faca2737235e4/src/ChangePrecision.jl#L33-L46
supplemented by
https://github.com/JuliaDiff/DiffRules.jl/blob/master/src/rules.jl
@antoine-levitt suggested this list of functions:
...
supplemented by
...
Sounds good. Maybe update the OP to reflect the missing parts now that #28872 is merged? One open issue there were matrix decompositions.
Updated!
Most helpful comment
Updated!