Skip to content

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

Open
@ArtemStrashko

Description

@ArtemStrashko

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    ITensorsIssues or pull requests related to the `ITensors` package.enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions