Skip to content

Support I * X = X for Arrays, i.e., UniformScaling as a true identity operator #1656

Description

@JeffFessler

The docstring for UniformScaling describes it as an "identity operator"
yet the support multiplication works only for a Vector or Matrix,
not for a general Array, as illustrated by this MWE:

using LinearAlgebra: I
5I * ones(2,3) # works of course
5I * ones(2,3,4) # fails with MethodError

The culprit is this one line of source code:

*(J::UniformScaling, A::AbstractVecOrMat) = J.λ*A

*(J::UniformScaling, A::AbstractVecOrMat) = J.λ*A

that limits A to be a matrix or vector.

My feature request is to generalize this to

*(J::UniformScaling, A::AbstractArray) = J.λ*A

With this tiny change, I really become an "identity operator" rather than merely an identity "matrix."

For context, I've put this more general method in one of my packages for years, but Aqua.jl tells me that it is type piracy, so it would be better to have this generality here in LinearAlgebra.
I will make a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    speculativeWhether the change will be implemented is speculative

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions