From 465ebaa46640063f7226f131e07f96c4137ff22f Mon Sep 17 00:00:00 2001 From: DSVarga Date: Wed, 6 Nov 2024 14:25:23 +0100 Subject: [PATCH] Extensions of pmmultrsym --- ext/FourierApproxExt/pmops_Fourier.jl | 8 ++++++++ src/pmops_sym.jl | 9 +++++++++ test/test_pmops.jl | 18 ++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/ext/FourierApproxExt/pmops_Fourier.jl b/ext/FourierApproxExt/pmops_Fourier.jl index fa8782a..52ede19 100644 --- a/ext/FourierApproxExt/pmops_Fourier.jl +++ b/ext/FourierApproxExt/pmops_Fourier.jl @@ -159,3 +159,11 @@ Base.isapprox(J::UniformScaling{<:Real}, A::FourierFunctionMatrix; kwargs...) = function PeriodicMatrices.pmrand(::Type{PM}, n::Int, m::Int, period::Real = 2*pi; nh::Int = 1) where {PM <:FourierFunctionMatrix} convert(PM,HarmonicArray(rand(n,m), [rand(n,m) for i in 1:nh], [rand(n,m) for i in 1:nh], period)) end +for PMF in (:pmmulsym, :pmtrmulsym, :pmmultrsym) + for PM in (:FourierFunctionMatrix,) + @eval begin + PeriodicMatrices.$PMF(B::$PM,C::$PM, β = true) = convert($PM,PeriodicMatrices.$PMF(convert(PeriodicFunctionMatrix,B), convert(PeriodicFunctionMatrix,C), β)) + end + end +end + diff --git a/src/pmops_sym.jl b/src/pmops_sym.jl index b6c829b..a3c38a7 100644 --- a/src/pmops_sym.jl +++ b/src/pmops_sym.jl @@ -193,3 +193,12 @@ function pmrand(::Type{PM}, n::Int, m::Int, period::Real = 2*pi; nh::Int = 1) wh pmrand(PM{:c,Float64}, n, m, period; nh) end +for PMF in (:pmmulsym, :pmtrmulsym, :pmmultrsym) + for PM in (:PeriodicSymbolicMatrix,) + @eval begin + $PMF(B::$PM,C::$PM, β = true) = convert($PM,$PMF(convert(PeriodicFunctionMatrix,B), convert(PeriodicFunctionMatrix,C), β)) + end + end +end + + diff --git a/test/test_pmops.jl b/test/test_pmops.jl index 7f02fbe..d11e969 100644 --- a/test/test_pmops.jl +++ b/test/test_pmops.jl @@ -346,7 +346,7 @@ At1=PeriodicFunctionMatrix(A11,2pi) @test As*Xs+Xs*As'+Cs ≈ pmderiv(Xs) ≈ Xders @test As'*Xs+Xs*As+Cds ≈ -pmderiv(Xs) @test transpose(As) == As' -ac = rand(2,2) +ac = rand(2,2); Ac = PeriodicSymbolicMatrix(ac,2.) @test As+ac ≈ ac+As @test As-ac ≈ -(ac-As) @test As-I == -(I-As) @@ -363,6 +363,13 @@ ac = rand(2,2) @test horzcat(As,ac)(1) == [As(1) ac] && horzcat(ac,As)(1) == [ac As(1)] @test vertcat(As,ac)(1) == [As(1); ac] && vertcat(ac,As)(1) == [ac; As(1)] +Ast = transpose(As) +@test pmmulsym(As, Ast, 1) ≈ As*Ast +@test pmmulsym(Ac, Ac', 1) ≈ Ac*Ac' +@test pmtrmulsym(As, As, 1) ≈ Ast*As +@test pmmultrsym(As, As, 1) ≈ As*Ast + + D = rand(2,2) @test As+I == I+As && As*5 == 5*As && As*D ≈ -As*(-D) && iszero(As-As) && !iszero(As) @@ -445,7 +452,7 @@ As = PeriodicSymbolicMatrix(A11,2*pi) @test ≈(As,PeriodicSymbolicMatrix(ffm2psm(Af,0:0)+ffm2psm(Af,1:1),As.period)) @test domain((Af+Af2).M).b ≈ 4pi && domain((Af*Af2).M).b ≈ 4pi -ac = rand(2,2) +ac = rand(2,2); Ac = FourierFunctionMatrix(ac,2) @test Af+ac ≈ ac+Af @test Af-ac ≈ -(ac-Af) @test Af-I == -(I-Af) @@ -462,6 +469,13 @@ ac = rand(2,2) @test horzcat(Af,ac)(1) ≈ [Af(1) ac] && horzcat(ac,Af)(1) ≈ [ac Af(1)] @test vertcat(Af,ac)(1) ≈ [Af(1); ac] && vertcat(ac,Af)(1) ≈ [ac; Af(1)] +Aft = transpose(Af) +@test pmmulsym(Af, Aft, 1) ≈ Af*Aft +@test pmmulsym(Ac, Ac', 1) ≈ Ac*Ac' +@test pmtrmulsym(Af, Af, 1) ≈ Aft*Af +@test pmmultrsym(Af, Af, 1) ≈ Af*Aft + + @test issymmetric(Cf) && issymmetric(Cdf) && issymmetric(Xf) && issymmetric(Xderf) @test Af*Xf+Xf*Af'+Cf ≈ pmderiv(Xf) ≈ Xderf