# Faulty Transpose and Adjoint Multiplication

**URL:** <https://discourse.julialang.org/t/faulty-transpose-and-adjoint-multiplication/13742>\
**Category:** General Usage\
**Tags:** linearalgebra\
**Created:** [August 20, 2018, 1:38am UTC](https://discourse.julialang.org/t/faulty-transpose-and-adjoint-multiplication/13742 "2018-08-20T01:38:25Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 20, 2018, 3:11pm UTC](https://discourse.julialang.org/t/faulty-transpose-and-adjoint-multiplication/13742/21 "2018-08-20T15:11:37Z")

</div>

Fair enough. However you can see how this inconsistency will have people scratching their heads, as can be seen in the OP. The sizes will contradict the types…

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [August 20, 2018, 3:11pm UTC](https://discourse.julialang.org/t/faulty-transpose-and-adjoint-multiplication/13742/22 "2018-08-20T15:11:39Z")

</div>

Please do propose any documentation improvements you think would make this clearer.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [August 20, 2018, 3:14pm UTC](https://discourse.julialang.org/t/faulty-transpose-and-adjoint-multiplication/13742/23 "2018-08-20T15:14:59Z")

</div>

Not really. Vectors and column matrices are behaviorally identified in the same way that adjoint vectors and row matrices are. There are also many situations where trailing singleton dimensions can behave as if they don’t exist or as if more of them exist than actually do. What is the actual problem here?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 20, 2018, 3:16pm UTC](https://discourse.julialang.org/t/faulty-transpose-and-adjoint-multiplication/13742/24 "2018-08-20T15:16:45Z")

</div>

```julia
size(a)
(1, 1)

size(b)
(1, 2)

```

Clearly the objects are compatible for matrix-matrix multiplication (by size), however the types say they are not compatible.

EDIT: Sorry.

```julia
a = transpose([-6.5])
b = [0, .95]'

size(a)
(1, 1)

size(b)
(1, 2)

```

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [August 20, 2018, 3:19pm UTC](https://discourse.julialang.org/t/faulty-transpose-and-adjoint-multiplication/13742/25 "2018-08-20T15:19:23Z")

</div>

I’ve lost track of which `a` and `b` definitions you’re referring to.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [August 20, 2018, 4:51pm UTC](https://discourse.julialang.org/t/faulty-transpose-and-adjoint-multiplication/13742/27 "2018-08-20T16:51:10Z")

</div>

I agree that should work; this just seems like a missing method bug to me. It’s a bit questionable from the perspective of variance analysis, if we were to keep track of up and down dimensions and/or covariant and contravariant dimensions, but we don’t do that in general, so I don’t think we should do it here either, so this should “just work”. It’s a little weird since `b'*a'` doesn’t work, but I think that’s the consequence of how we’ve chosen to identify vector transposes with row matrices.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 20, 2018, 5:03pm UTC](https://discourse.julialang.org/t/faulty-transpose-and-adjoint-multiplication/13742/28 "2018-08-20T17:03:31Z")

</div>

I might disagree. I don’t think `a*b` or `b'*a'` should work: vector-vector or row vector-row vector products don’t make sense. What bothers me is the disconnect between the sizes and the types. The sizes provide hints inconsistent with the behaviour based on types.

---

<div class="post-metadata">

**Author:** ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)\
**Post date:** [August 20, 2018, 5:08pm UTC](https://discourse.julialang.org/t/faulty-transpose-and-adjoint-multiplication/13742/29 "2018-08-20T17:08:20Z")

</div>

I am not sure why people use `transpose` in general, but since the definition is for `AbstractMatrix{<:Number}` (see, `permutedims` for non-numeric), I would hope one could use these for matrix multiplication with a close relation to the mathematical concept, especially with the `size` suggesting these work as such). A second best, would be to have to call `Matrix(transpose(::AbstractMatrix{<:Real}))` to get that behavior. For `Factorization` there is a good reason behind it, but here I fail to see why it should just work.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [August 20, 2018, 5:08pm UTC](https://discourse.julialang.org/t/faulty-transpose-and-adjoint-multiplication/13742/30 "2018-08-20T17:08:29Z")

</div>

I think we should tread carefully here.

Right now if you do

```julia
a = rand(4,4)
b = rand(4)
a*b

```

You are doing {a^{i}}\_{j}b^{j}. Note that the order of oprations determines the contractions. This is why you currently _cannot_ do `b*a` which would give b^{i}{a^{i}}\_{j}. Meanwhile `b'*a` does b\_{i}{a^{i}}\_{j}.

In this particular case we have two objects with the index structure {a^{i}}\_{j}, {b^{i}}\_{\alpha} where the latin and greek indices have different numbers of dimensions. So `b'*a'` would give you {b\_{\alpha}}^{i}{a\_{i}}^{j}, so yes, that should work.

Right now I think everything is correct in the general metric signature case. It would be nice if we can make sure that we do not specialize to the Euclidean metric signature case as this might make it harder to implement other metric signatures.

[Previous page](https://discourse.julialang.org/t/faulty-transpose-and-adjoint-multiplication/13742.md?page=1)
