Not sure how `Adjoint` types are described

I am upgrading the MixedModels package 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.

   _       _ _(_)_     |  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}}

I believe the problem is similar to:

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

4 Likes

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

isa(trm', Adjoint{Float64,<:MatrixTerm{Float64}})
1 Like

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

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

instead of the 0.6 version which was

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

this is discussed in StaticArrays.jl/issues/410.

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