Skip to content

new syntax for transpose #410

@StefanKarpinski

Description

@StefanKarpinski
Member

Now that .op is generally the vectorized form of op, it's very confusing that .' means transpose rather than the vectorized form of ' (adjoint, aka ctranspose). This issue is for discussing alternative syntaxes for transpose and/or adjoint.

Activity

mbauman

mbauman commented on Mar 15, 2017

@mbauman
SponsorMember

Andreas tried Aᵀ (and maybe Aᴴ) in JuliaLang/julia#19344, but it wasn't very well received. We could similarly pun on ^ with special exponent types T (and maybe H) such that A^T is transpose, but that's rather shady, too. Not sure there are many other good options that still kinda/sorta look like math notation.

StefanKarpinski

StefanKarpinski commented on Mar 15, 2017

@StefanKarpinski
SponsorMemberAuthor

I kind of think that t(A) might be the best, but it's unfortunate to "steal" another one-letter name.

nalimilan

nalimilan commented on Mar 15, 2017

@nalimilan
Member

Moving my comment from the other issue (not that it solves anything, but...):

+1 for using something else than .'.

I couldn't find languages with a special syntax for transposition, except for APL which uses the not-so-obvious , and Python which uses *X (which would be confusing for Julia). Several languages use transpose(X); R uses t(X). That's not pretty, but it's not worse than .'. At least you're less tempted to use ' by confusing it with .': it would be clear that these are very different operations.

See Rosetta code. (BTW, the Julia example actually illustrates conjugate transpose...)

mauro3

mauro3 commented on Mar 15, 2017

@mauro3

Could one of the other ticks be used? ` or "

ararslan

ararslan commented on Mar 15, 2017

@ararslan
Member

-100 to changing adjoint, since it's one of the awesome things that makes writing Julia code as clear as writing math, plus conjugate transpose is usually what you want anyway so it makes sense to have an abbreviated syntax for it.

As long as we have the nice syntax for conjugate transpose, a postfix operator for regular transpose seems mostly unnecessary, so just having it be a regular function call seems fine to me. transpose already works; couldn't we just use that? I find the t(x) R-ism unfortunate, as it's not clear from the name what it's actually supposed to do.

Using a different tick would be kind of weird, e.g. A` can look a lot like A' depending on the font, and A" looks too much like A''.

added
designDesign of APIs or of the language itself
speculativeWhether the change will be implemented is speculative
on Mar 15, 2017
stevengj

stevengj commented on Mar 16, 2017

@stevengj
Member

If we make the change in #408, then a postfix transpose actually becomes more useful than it is now. e.g. if you have two vectors x and y and you want to apply f pairwise on them, you can do e.g. f.(x, y.') ... with #408, this will be applicable to arrays of arbitrary types.

Honestly, I think our best option is still to leave it as-is. None of the suggestions seem like a clear improvement to me. .' has the advantage of familiarity from Matlab. The . actually is somewhat congruent with dot-call syntax in examples like f.(x, y.'), and suggests (somewhat correctly) that the transpose "fuses" (it doesn't produce a temporary copy thanks to RowVector and future generalizations thereof).

In fact, we could even take it further, and make f.(x, g.(y).') a fusing operation. i.e. we change .' transpose to be non-recursive ala #408 and we extend its semantics to include fusion with other nested dot calls. (If you want the non-fusing version, you would call transpose.)

StefanKarpinski

StefanKarpinski commented on Mar 16, 2017

@StefanKarpinski
SponsorMemberAuthor

I like that plan a lot, @stevengj.

StefanKarpinski

StefanKarpinski commented on Mar 16, 2017

@StefanKarpinski
SponsorMemberAuthor

One wrinkle: presumably the @. macro does not turn y' into y.' (since that would be wrong). It could, however, turn y' into some kind of fused adjoint operation.

stevengj

stevengj commented on Mar 16, 2017

@stevengj
Member

The main problem is finding a clean way to make f.(x, g.(y).') have fusing semantics. One possibility would be to transform it to f.(x, g.(y.')) and hence to broadcast(x,y -> f(x, g(y)), x, y.')?

Note that, for this to work properly, we might need to restore the fallback transpose(x) = x method, in which case we might as well let transpose remain recursive.

StefanKarpinski

StefanKarpinski commented on Mar 17, 2017

@StefanKarpinski
SponsorMemberAuthor

I think deciding whether transpose should be recursive or not is orthogonal to whether we make it participate in dot syntax fusion. The choice of making it non-recursive is not motivated by that.

stevengj

stevengj commented on Mar 17, 2017

@stevengj
Member

@StefanKarpinski, if restore a fallback transpose(x) = x, then most of the motivation for changing it to be non-recursive goes away.

107 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    parserLanguage parsing and surface syntax

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @StefanKarpinski@mbauman@andreasnoack@c42f@JeffBezanson

      Issue actions

        new syntax for transpose · Issue #410 · JuliaLang/LinearAlgebra.jl