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

[ITensors] [ENHANCEMENT] ITensors.contract!(a, b, c, 1, 1) promotion to the type of a #1175

Open
ArtemStrashko opened this issue Aug 8, 2023 · 1 comment
Labels
enhancement New feature or request ITensors Issues or pull requests related to the `ITensors` package.

Comments

@ArtemStrashko
Copy link

Is your feature request related to a problem? Please describe.

ITensors.contract!(a, b, c, 1, 1) throws an error if promoted tensor element type of a and b ("greater" type) does not match tensor element type of a. For example, the code below

indices = [Index(2), Index(3), Index(4)]
a = randomITensor(type_1, indices[1])
b = randomITensor(type_2, indices)
c = randomITensor(type_3, indices[2:3])
ITensors.contract!(a, b, c, 1, 1)

does not work if a promoted type of type_2 and type_3 does not match type_1. For example, it would not work if type_1=Float64 and type_2=Float32, type_3=Float16. It would also not work if type_3=Float32. It would only work if one or both of type_2 and type_3 is of Float64 type.

Describe the solution you'd like

Rather than promoting the result of contraction of b and c to the common type (I believe it is done natively by Julia under the hood), promote it to the type of a if possible (may not be possible, e.g., if a is real, while b and c are complex).

Describe alternatives you've considered

Keep types consistent with the signature of ITensors.contract!(a, b, c, alpha, beta).

@ArtemStrashko ArtemStrashko added enhancement New feature or request ITensors Issues or pull requests related to the `ITensors` package. labels Aug 8, 2023
@ArtemStrashko ArtemStrashko changed the title [ITensors] [ENHANCEMENT] YOUR SHORT DESCRIPTION OF THE FEATURE REQUEST HERE [ITensors] [ENHANCEMENT] ITensors.contract!(a, b, c, 1, 1) promotion to the type of a Aug 8, 2023
@mtfishman
Copy link
Member

Thanks for the report @ArtemStrashko, I agree we should be handling that promotion better using information from the buffer tensor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ITensors Issues or pull requests related to the `ITensors` package.
Projects
None yet
Development

No branches or pull requests

2 participants