Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new postfix transpose() operator different from ' #35593

Closed
johnalx opened this issue Apr 24, 2020 · 5 comments
Closed

new postfix transpose() operator different from ' #35593

johnalx opened this issue Apr 24, 2020 · 5 comments

Comments

@johnalx
Copy link

johnalx commented Apr 24, 2020

Can we introduce a new postfix operator for the transpose, like A^⊤ or ?

It would of great help to us who write expressions with a lot of transposes. For example:

a = (transpose(s)*A*s)\s*(Q-transpose(s)*p+U*transpose(R)*κ)

and it would more true to form if the multiple calls to transpose() were replaced with something more terse. Even if the language defaulted to transpose for A' unless it knew a complex data type was used when the adoint is more appropriate.

@MasonProtter
Copy link
Contributor

MasonProtter commented Apr 25, 2020

Ref #34507, JuliaLang/LinearAlgebra.jl#410

If you like, you can always do this:

struct Transposer end
const= Transposer() #typed \^T<TAB>
Base.:(*)(x, ::Transposer) = transpose(x)
julia> rand(5)ᵀ*randn(5,5)*rand(5)
0.7409506780313673

julia> A = rand(5); (A)ᵀ*rand(5, 5)*A
2.7952114562233827

@johnalx
Copy link
Author

johnalx commented Apr 27, 2020

Ref #34507, JuliaLang/LinearAlgebra.jl#410

If you like, you can always do this:

struct Transposer end
const= Transposer() #typed \^T<TAB>
Base.:(*)(x, ::Transposer) = transpose(x)
julia> rand(5)ᵀ*randn(5,5)*rand(5)
0.7409506780313673

julia> A = rand(5); (A)ᵀ*rand(5, 5)*A
2.7952114562233827

Yet the following does not work

z = rand(3)
zᵀ*z    # ERROR: UndefVarError: zᵀ not defined

And that is the point of having a built in operator, such that the parser will recognize zᵀ as transpose(z). This hack is interesting, though.

@MasonProtter
Copy link
Contributor

It works if you surround z in parentheses.

julia> (z)ᵀ*z
1.4221674642522308

I should also reference this PR: #34549 where they run PkgEval to show what registered packages would be effected by changing the meaning of zᵀ from just a variable named zᵀ to transpose(z). The list of broken packages is quite small, but the Julia devs take breaking changes very seriously.

@JeffBezanson
Copy link
Member

duplicate of JuliaLang/LinearAlgebra.jl#410

@JeffBezanson
Copy link
Member

Even if the language defaulted to transpose for A' unless it knew a complex data type was used when the adoint is more appropriate.

Isn't that already the case --- adjoint and transpose are equivalent for reals?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants