共轭转置运算符能重载吗

共轭转置运算符 ’ 能直接重载吗?

julia> Base.adjoint(::typeof(sin)) = cos

julia> sin'(1)
0.5403023058681398

julia> cos(1)
0.5403023058681398

可以

1 个赞
help?> '
search:

  '

  The conjugate transposition operator, see adjoint.
help?> adjoint
search: adjoint

  adjoint(A)

  Lazy adjoint (conjugate transposition) (also postfix '). Note that adjoint is applied recursively to elements.

  This operation is intended for linear algebra usage - for general data manipulation see permutedims.

谢谢,必须要操作符所对应的函数名来写重载函数吗

对于 是这样的。不过像 + 什么的不需要。其实我感觉更帅的方法是自己定义算符。比如说:

julia> ᴴ(a) = a'; Base.:*(a, ::typeof(ᴴ)) = ᴴ(a)

julia> (1+im)ᴴ
1 - 1im
1 个赞