From be1ad170332720f84d9f1b2bf8430aa82d9a8d69 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Wed, 31 May 2023 18:58:33 +0530 Subject: [PATCH] getproperty for Adjoint/Transpose wrappers --- src/ToeplitzMatrices.jl | 22 +++++++++++++++++++++- test/runtests.jl | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/ToeplitzMatrices.jl b/src/ToeplitzMatrices.jl index 687cd4f..c9472bb 100644 --- a/src/ToeplitzMatrices.jl +++ b/src/ToeplitzMatrices.jl @@ -6,7 +6,7 @@ import Base: adjoint, convert, transpose, size, getindex, similar, copy, getprop import Base: ==, +, -, *, \ import LinearAlgebra: Cholesky, Factorization import LinearAlgebra: ldiv!, factorize, lmul!, pinv, eigvals, cholesky!, cholesky, tril!, triu!, checksquare, rmul!, dot, mul!, tril, triu -import LinearAlgebra: UpperTriangular, LowerTriangular, Symmetric, Adjoint +import LinearAlgebra: UpperTriangular, LowerTriangular, Symmetric, Adjoint, Transpose import AbstractFFTs: Plan, plan_fft! import StatsBase @@ -18,6 +18,26 @@ include("iterativeLinearSolvers.jl") # Abstract abstract type AbstractToeplitz{T<:Number} <: AbstractMatrix{T} end +function getproperty(A::Transpose{<:Number, <:AbstractToeplitz}, s::Symbol) + if s == :vc + getproperty(parent(A), :vr) + elseif s == :vr + getproperty(parent(A), :vc) + else + getfield(A, s) + end +end + +function getproperty(A::Adjoint{<:Number, <:AbstractToeplitz}, s::Symbol) + if s == :vc + vec(adjoint(getproperty(parent(A), :vr))) + elseif s == :vr + vec(adjoint(getproperty(parent(A), :vc))) + else + getfield(A, s) + end +end + size(A::AbstractToeplitz) = (length(A.vc),length(A.vr)) @inline _vr(A::AbstractToeplitz) = A.vr @inline _vc(A::AbstractToeplitz) = A.vc diff --git a/test/runtests.jl b/test/runtests.jl index 3f39660..e1864b9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -71,6 +71,28 @@ for (As, Al, st) in cases end end +@testset "Transpose/Adjoint wrappers" begin + vc, vr = [0,im,0], [0, 2+3im, 0] + @testset "Toeplitz" begin + T = Toeplitz(vc, vr) + @test Transpose(T).vc == vr + @test Transpose(T).vr == vc + @test Adjoint(T).vc == vec(vr') + @test Adjoint(T).vr == vec(vc') + end + + @testset for TT in (Circulant, + UpperTriangularToeplitz, LowerTriangularToeplitz, + SymmetricToeplitz) + T = TT(vc) + M = Matrix(T) + @test Transpose(T).vc == ToeplitzMatrices._vr(M) + @test Transpose(T).vr == ToeplitzMatrices._vc(M) + @test Adjoint(T).vc == vec(ToeplitzMatrices._vr(M)') + @test Adjoint(T).vr == vec(ToeplitzMatrices._vc(M)') + end +end + @testset "Mixed types" begin @test eltype(Toeplitz([1, 2], [1, 2])) === Int @test Toeplitz([1, 2], [1, 2]) * ones(2) == fill(3, 2)