Skip to content

cp_norm returns an imaginary norm for complex CP weights #655

Closed

Description

@ktz03

Describe the bug

cp_norm and CPTensor.norm() disagree with the Frobenius norm of the represented tensor when CP weights are complex. The factor Gram matrices already conjugate one factor, but the weight outer product multiplies weights without conjugation. A purely imaginary weight can therefore produce a purely imaginary norm.

Steps or Code to Reproduce

import tensorly as tl
from tensorly.cp_tensor import CPTensor, cp_norm, cp_to_tensor

weights = tl.tensor([1j])
factors = [tl.tensor([[1.0], [2.0]]), tl.tensor([[3.0], [4.0]])]
cp = (weights, factors)
print(cp_norm(cp))
print(CPTensor(cp).norm())
print(tl.norm(cp_to_tensor(cp)))

Expected behavior

All three results should equal sqrt(125), approximately 11.180339887498949. Multiplying a tensor by a unit complex phase preserves its norm.

Actual result

On main a4f895404d8159bc1127e5304df8453f6c6a091e with the NumPy backend, the two CP norm calls return 11.180339887498949j, while the dense tensor norm returns 11.180339887498949.

The complex-factor support introduced by @aarmey in #423 conjugates the factor Gram matrices; the remaining difference is in the complex weights. Conjugating the second weight axis fixes this public example and mixed complex-weight cases.

Versions

Windows 11, Python 3.12.14, NumPy 2.3.5, SciPy 1.16.3, TensorLy 0.10.0 from main a4f895404d8159bc1127e5304df8453f6c6a091e. The new input cases also pass with PyTorch 2.8.0+cpu after the fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions