Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tensorcontract type stability #96

Open
khanley6 opened this issue Oct 23, 2020 · 0 comments
Open

tensorcontract type stability #96

khanley6 opened this issue Oct 23, 2020 · 0 comments

Comments

@khanley6
Copy link

Hi there,

It seems that tensorcontract, with its current definition, is type unstable:

julia> @code_warntype tensorcontract(A, a_idx, B, b_idx)
Variables
  #self#::Core.Compiler.Const(TensorOperations.tensorcontract, false)
  A::Array{Int64,2}
  IA::Tuple{Int64,Int64}
  B::Array{Int64,2}
  IB::Tuple{Int64,Int64}

Body::Array
1 ─ %1 = TensorOperations.symdiff(IA, IB)::Array{Int64,1}
│   %2 = (#self#)(A, IA, B, IB, %1)::Array
└──      return %2

However, changing the definition (tested below) results in stability:

julia> mytensorcontract(A, IA, B, IB, IC = Tuple(symdiff(IA, IB))) =
          tensorcontract(A, tuple(IA...), B, tuple(IB...), IC)
julia> @code_warntype mytensorcontract(A, a_idx, B, b_idx)
Variables
  #self#::Core.Compiler.Const(mytensorcontract, false)
  A::Array{Int64,2}
  IA::Tuple{Int64,Int64}
  B::Array{Int64,2}
  IB::Tuple{Int64,Int64}

Body::Union{}
1 ─ %1 = Main.symdiff(IA, IB)::Array{Int64,1}
│   %2 = Main.tuple(%1)::Tuple{Array{Int64,1}}
│        (#self#)(A, IA, B, IB, %2)
└──      Core.Compiler.Const(:(return %3), false)

I have made the change locally and all tests pass.

Is there any reason to use the current definition over the proposed one? I guess there is still an issue with passing an array explicitly:

c_idx::Array{Int} = ...
@code_warntype mytensorcontract(A, a_idx, B, b_idx, c_idx) #-> not stable
@code_warntype mytensorcontract(A, a_idx, B, b_idx, Tuple(c_idx)) #-> stable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant