JuliaLang/julia — pull request #6837 by andreasnoackjensen (2014-05-14 08:07:42+00:00)
Title: WIP:Add Transpose immutable

Here is a sketch of how a `Transpose` type could work. Before continuing with redefining all the methods to the new type, I would like to hear what people think about it. Basically, I am just introducing the immutable
```
immutable Transpose{T, N, S<:AbstractArray{T, N}, Conj} <: AbstractArray{T, N}
data::S
end
```
and although there is an `N` there, this proposal deals with arrays of dimension one and two. That is what is possible to transpose right now and I think it is beyond the scope of this proposal to handle higher dimensions.

This is basically a kind of lazy transpose which we can use for dispatch to optimised methods. If the idea is accepted, we can remove all the `Ax_mul_Bx!` methods and just have `mul!` and similarly for `ldiv`/`rdiv`, see #5332.

With this proposal `transpose(Vector{T})` is a `VectorTranspose{T,Vector{T},false}`, which is still a one dimensional thing, but with this we can have
```
julia> A=randn(3,3);x=randn(3);

julia> x'A*x
-3.0853326038138893

julia> x'x
3.0143512744908234
```
which was discussed in #4774. Another useful consequence would be that we can evaluate something like `A*B*C'` more efficiently. Right now `B*C'` calls `A_mul_Bc` without actually forming `C'`, but `A*B*C'` calls `*(A,B,ctranspose(C))` so for more complicated matrix expression there is more copying than necessary.

cc: @jiahao, @toivoh