# Not sure how \`Adjoint\` types are described

**URL:** <https://discourse.julialang.org/t/not-sure-how-adjoint-types-are-described/14414>\
**Category:** Internals & Design\
**Created:** [September 1, 2018, 6:11pm UTC](https://discourse.julialang.org/t/not-sure-how-adjoint-types-are-described/14414 "2018-09-01T18:11:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Post date:** [September 1, 2018, 6:11pm UTC](https://discourse.julialang.org/t/not-sure-how-adjoint-types-are-described/14414/1 "2018-09-01T18:11:35Z")

</div>

I am upgrading the [`MixedModels` package](https://github.com/dmbates/MixedModels.jl.git) to Julia v1.0 in the `0.7updates` branch. This package uses linear algebra operations on various types of matrix-like objects. What would previously be a method for a generic like `Ac_mul_B!` should not be a method for `*` in which the first argument is an `Adjoint` type (or whatever is generated by the `adjoint` method for the class).

My problems seem to stem from a misunderstanding of type signatures.

```julia
   _ _ _(_)_ | A fresh approach to technical computing
  (_) | (_) (_) | Documentation: https://docs.julialang.org
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 0.7.0 (2018-08-08 06:46 UTC)
 _/ |\ __'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-pc-linux-gnu

julia> using LinearAlgebra, MixedModels

julia> trm = MatrixTerm(ones(10))
MatrixTerm{Float64,Array{Float64,2}}([1.0; 1.0; … ; 1.0; 1.0], [1.0; 1.0; … ; 1.0; 1.0], [1], 0, [""])

julia> typeof(trm')
Adjoint{Float64,MatrixTerm{Float64,Array{Float64,2}}}

julia> isa(trm', Adjoint{Float64,MatrixTerm{Float64}})
false

```

I’m not sure why the `isa` call is false and what I should put in a method signature instead of `Adjoint{T, MatrixTerm{T}}`

---

<div class="post-metadata">

**Author:** ![Non-Contradiction](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-contradiction/32/2208_2.png) [@Non-Contradiction](https://discourse.julialang.org/u/Non-Contradiction)\
**Post date:** [September 1, 2018, 7:55pm UTC](https://discourse.julialang.org/t/not-sure-how-adjoint-types-are-described/14414/2 "2018-09-01T19:55:43Z")

</div>

I believe the problem is similar to:

```julia
julia> a = ones(4,3)
4×3 Array{Float64,2}:
 1.0 1.0 1.0
 1.0 1.0 1.0
 1.0 1.0 1.0
 1.0 1.0 1.0

julia> a'
3×4 Adjoint{Float64,Array{Float64,2}}:
 1.0 1.0 1.0 1.0
 1.0 1.0 1.0 1.0
 1.0 1.0 1.0 1.0

julia> typeof(a')
Adjoint{Float64,Array{Float64,2}}

julia> isa(a', Adjoint{Float64, Array{Float64}})
false

julia> isa(a', Adjoint{Float64, <:Array{Float64}})
true

```

And is related to the fact that the parametric type is invariant, but not covariant, also see the warning in [https://docs.julialang.org/en/v1.0.0/manual/types/#Parametric-Types-1](https://docs.julialang.org/en/v1.0.0/manual/types/#Parametric-Types-1)

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [September 1, 2018, 11:15pm UTC](https://discourse.julialang.org/t/not-sure-how-adjoint-types-are-described/14414/3 "2018-09-01T23:15:01Z")

</div>

This should work as intended if you don’t want to spell out the second parameter.

```julia
isa(trm', Adjoint{Float64,<:MatrixTerm{Float64}})

```

---

<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:** [September 2, 2018, 1:33am UTC](https://discourse.julialang.org/t/not-sure-how-adjoint-types-are-described/14414/4 "2018-09-02T01:33:47Z")

</div>

Related to it, in MixedModels (similar issue with `reinterpret`), one has to do something like

```julia
wtzv = Vector{SVector{k,T}}(undef, n)
wtzv .= reinterpret(SVector{k,T}, vec(z))

```

instead of the 0.6 version which was

```julia
reinterpret(SVector{k,T}, vec(z))

```

this is discussed in [StaticArrays.jl/issues/410](https://github.com/JuliaArrays/StaticArrays.jl/issues/410).

---

<div class="post-metadata">

**Author:** ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Post date:** [September 5, 2018, 3:27pm UTC](https://discourse.julialang.org/t/not-sure-how-adjoint-types-are-described/14414/5 "2018-09-05T15:27:16Z")

</div>

Thanks to all for your suggestions. I ended up using the form suggested by @mohamed82008 and also incorporated the other suggestion by @Nosferican
