Closed jofrevalles closed 1 year ago
@mofeing Do you agree that adjoint(a::Tensor)
should also be a Tensor
?
Nice catch. Add a test for this pls.
@mofeing Do you agree that
adjoint(a::Tensor)
should also be aTensor
?
I agree. But it is a little tricky in the sense that not every N-dim array has adjoint
defined to it.
The methods should be sth like:
adjoint(t::Tensor{T,2,A}) where {T,A<:AbstractMatrix{T}} = Tensor(adjoint(parent(t)), reverse(labels(t))
adjoint(t::Tensor{T,1,A}) where {T,A<:AbstractVector{T}} = Tensor(conj(parent(t)), labels(t))
The adjoint of a column-vector should not be a row-vector because that info is already encoded on the indices and we would need to create an index with dim=1 (row-vectors have size (1,n)
) which would complicate things needlessly.
@jofrevalles can you check it this continues to be a problem in the new repo Tensors.jl? If not, I will close this issue.
With the last PR this is not a problem anymore:
julia> using Tensors
julia> a = Tensor(rand(Complex{Float64}, 2, 2), (:i, :j));
julia> b = adjoint(a)
2×2 Tensor{ComplexF64, 2, Matrix{ComplexF64}}:
0.798311-0.698864im 0.314514-0.77349im
0.562423-0.160019im 0.986719-0.297658im
julia> b isa Tensor
true
julia> b.labels
(:i, :j)
julia> contract(a, b)
0-dimensional Tensor{ComplexF64, 0, Array{ComplexF64, 0}}:
3.2270577277410437 + 0.0im
Summary
The contraction of an adjoint
Tensor
produces incoherent results with the normalTensor
ones. Specifically, it returns anArray
type of data instead ofTensor
type. I believe that is also why the PR #39 is failing on some tests.Example
I believe that this is a problem with the adjoint
Tensor
not being aTensor
type: