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

Fix promotion of outer product #263

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/implementations/LinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ function promote_array_mul(
::Type{<:AbstractVector{S}},
::Type{<:LinearAlgebra.Adjoint{T,<:AbstractVector{T}}},
) where {S,T}
return Matrix{promote_sum_mul(S, T)}
return Matrix{promote_operation(*, S, T)}
end

function promote_array_mul(
::Type{<:AbstractVector{S}},
::Type{<:LinearAlgebra.Transpose{T,<:AbstractVector{T}}},
) where {S,T}
return Matrix{promote_sum_mul(S, T)}
return Matrix{promote_operation(*, S, T)}
end

function promote_array_mul(
Expand Down
19 changes: 19 additions & 0 deletions test/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,22 @@ end
y = MA.@rewrite sum(A[i, :] * LinearAlgebra.transpose(x[i, :]) for i in 1:2)
@test y == BigInt[10 14; 14 20]
end

struct Monomial end
LinearAlgebra.transpose(m::Monomial) = m
LinearAlgebra.adjoint(m::Monomial) = m
MA.promote_operation(::typeof(*), ::Type{Monomial}, ::Type{Monomial}) = Monomial
Base.:*(m::Monomial, ::Monomial) = m

# `Monomial` does not implement `+`, we should check that it does not prevent
# to do outer products of vectors
@testset "Vector*Transpose{Vector}_issue_256 with Monomial" begin
m = Monomial()
a = [m, m]
for f in [LinearAlgebra.transpose, LinearAlgebra.adjoint]
b = f(a)
T = MA.promote_operation(*, typeof(a), typeof(b))
@test T == typeof(a * b)
@test T == typeof(MA.operate(*, a, b))
end
end
Loading