From 74910f34b5b5d5553a554eae387dd997ddad1156 Mon Sep 17 00:00:00 2001 From: Tommy Hofmann Date: Fri, 2 Feb 2024 19:57:21 +0100 Subject: [PATCH] fix: make dot work again (#1593) --- src/AbstractAlgebra.jl | 3 +++ src/NCRings.jl | 12 ++++++++++++ src/NemoStuff.jl | 3 --- test/NCRings-test.jl | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/AbstractAlgebra.jl b/src/AbstractAlgebra.jl index da7ee3039c..f4641e03c7 100644 --- a/src/AbstractAlgebra.jl +++ b/src/AbstractAlgebra.jl @@ -28,7 +28,10 @@ const import_exclude = [:import_exclude, :QQ, :ZZ, # imported here and in Generic.jl, and exported below. # They should not be imported/exported anywhere else. +import LinearAlgebra + import LinearAlgebra: det +import LinearAlgebra: dot import LinearAlgebra: hessenberg import LinearAlgebra: ishermitian import LinearAlgebra: issymmetric diff --git a/src/NCRings.jl b/src/NCRings.jl index d8f2953ec0..a95daf9f1e 100644 --- a/src/NCRings.jl +++ b/src/NCRings.jl @@ -290,3 +290,15 @@ Base.oftype(x::NCRingElem, y::Rational) = parent(x)(y) ############################################################################### Base.broadcastable(x::NCRingElem) = Ref(x) + +################################################################################ +# +# Dot +# +################################################################################ + +dot(x::NCRingElem, y::NCRingElem) = x * y + +dot(x::NCRingElem, y::Union{Integer, Rational, AbstractFloat}) = x * y + +dot(x::Union{Integer, Rational, AbstractFloat}, y::NCRingElem) = x * y diff --git a/src/NemoStuff.jl b/src/NemoStuff.jl index 8a4052fda0..b6cb93fd99 100644 --- a/src/NemoStuff.jl +++ b/src/NemoStuff.jl @@ -398,9 +398,6 @@ end Random.gentype(::Type{T}) where {T<:FinField} = elem_type(T) -import LinearAlgebra -LinearAlgebra.dot(a::NCRingElem, b::NCRingElem) = a * b - transpose!(A::MatrixElem) = transpose(A) function Base.div(f::PolyRingElem, g::PolyRingElem) diff --git a/test/NCRings-test.jl b/test/NCRings-test.jl index 530443fc5b..5f77883996 100644 --- a/test/NCRings-test.jl +++ b/test/NCRings-test.jl @@ -56,3 +56,22 @@ end M = matrix_space(ZZ, 2, rand(3:9)) @test_throws DomainError powers(rand(M, 1:9), rand(1:9)) end + +@testset "dot" begin + dot = AbstractAlgebra.LinearAlgebra.dot + + Qx, x = QQ["x"] + @test dot([x, x^2], [1, 1]) == x + x^2 + @test dot([x, x^2], Rational{BigInt}[1, 1]) == x + x^2 + @test dot([1, 1], [x, x^2]) == x + x^2 + @test dot(Rational{BigInt}[1, 1], [x, x^2]) == x + x^2 + @test dot([x], [x^2]) == x^3 + + R = matrix_ring(QQ, 2) + x = R([1 2; 3 4]) + @test dot([x, x^2], [1, 1]) == x + x^2 + @test dot([x, x^2], Rational{BigInt}[1, 1]) == x + x^2 + @test dot([1, 1], [x, x^2]) == x + x^2 + @test dot(Rational{BigInt}[1, 1], [x, x^2]) == x + x^2 + @test dot([x], [x^2]) == x^3 +end