From 43d1707520fc960915c8008dc1d53bb5d5706be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 3 Jul 2024 19:24:01 +0200 Subject: [PATCH 1/2] Allow multiplication with different algebras --- src/arithmetic.jl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/arithmetic.jl b/src/arithmetic.jl index 346a1a49..6958200a 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -148,6 +148,24 @@ function MA.operate_to!( return res end +function mstructure(args::AbstractStarAlgebra...) + for arg in args + @assert arg == first(args) + end + return mstructure(basis(args[1])) +end + +function MA.operate!( + ::UnsafeAddMul{typeof(*)}, + res::AlgebraElement, + A::BasisTransformation, + args::Vararg{AlgebraElement,N}, +) where {N} + mstr = mstructure(algebra(res), algebra.(args)...) + MA.operate!(UnsafeAddMul(mstr), coeffs(res), coeffs.(args)...) + return res +end + function MA.operate!( ::UnsafeAddMul{typeof(*)}, res::AlgebraElement, @@ -156,7 +174,7 @@ function MA.operate!( for arg in args @assert parent(res) == parent(arg) end - mstr = mstructure(basis(res)) + mstr = mstructure(basis(res), basis.(args)...) MA.operate!(UnsafeAddMul(mstr), coeffs(res), coeffs.(args)...) return res end From 8a6e2dd8380a08ef2556965b384fa4288b41be4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 21 Aug 2024 11:08:35 +0200 Subject: [PATCH 2/2] Fixes --- src/arithmetic.jl | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/arithmetic.jl b/src/arithmetic.jl index 6958200a..c25b898f 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -140,10 +140,7 @@ function MA.operate_to!( ::typeof(*), args::Vararg{AlgebraElement,N}, ) where {N} - for arg in args - @assert parent(res) == parent(arg) - end - mstr = mstructure(basis(res)) + mstr = mstructure(parent(res), parent.(args)...) MA.operate_to!(coeffs(res), mstr, coeffs.(args)...) return res end @@ -158,23 +155,9 @@ end function MA.operate!( ::UnsafeAddMul{typeof(*)}, res::AlgebraElement, - A::BasisTransformation, args::Vararg{AlgebraElement,N}, ) where {N} - mstr = mstructure(algebra(res), algebra.(args)...) - MA.operate!(UnsafeAddMul(mstr), coeffs(res), coeffs.(args)...) - return res -end - -function MA.operate!( - ::UnsafeAddMul{typeof(*)}, - res::AlgebraElement, - args::Vararg{AlgebraElement,N}, -) where {N} - for arg in args - @assert parent(res) == parent(arg) - end - mstr = mstructure(basis(res), basis.(args)...) + mstr = mstructure(parent(res), parent.(args)...) MA.operate!(UnsafeAddMul(mstr), coeffs(res), coeffs.(args)...) return res end