Skip to content

Commit

Permalink
define some more methods for abstract type
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Jun 2, 2023
1 parent 889ce72 commit eb6c504
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
abstract type AbstractToeplitzSingleVector{T} <: AbstractToeplitz{T} end

parent(A::AbstractToeplitzSingleVector) = A.v
basetype(x) = basetype(typeof(x))

function size(A::AbstractToeplitzSingleVector)
n = length(parent(A))
Expand Down Expand Up @@ -36,6 +37,10 @@ AbstractToeplitz{T}(A::AbstractToeplitzSingleVector) where T = basetype(A){T}(A)

AbstractMatrix{T}(A::AbstractToeplitzSingleVector) where {T} = basetype(A){T}(AbstractVector{T}(A.v))

for fun in (:zero, :conj, :copy, :-, :real, :imag)
@eval $fun(A::AbstractToeplitzSingleVector) = basetype(A)($fun(parent(A)))
end

for TYPE in (:SymmetricToeplitz, :Circulant, :LowerTriangularToeplitz, :UpperTriangularToeplitz)
@eval begin
struct $TYPE{T, V<:AbstractVector{T}} <: AbstractToeplitzSingleVector{T}
Expand All @@ -46,7 +51,7 @@ for TYPE in (:SymmetricToeplitz, :Circulant, :LowerTriangularToeplitz, :UpperTri
$TYPE{T, typeof(vT)}(vT)
end

basetype(::$TYPE) = $TYPE
basetype(::Type{T}) where {T<:$TYPE} = $TYPE

(==)(A::$TYPE, B::$TYPE) = A.v == B.v

Expand All @@ -57,9 +62,6 @@ for TYPE in (:SymmetricToeplitz, :Circulant, :LowerTriangularToeplitz, :UpperTri
A
end
end
for fun in (:zero, :conj, :copy, :-, :real, :imag)
@eval $fun(A::$TYPE) = $TYPE($fun(A.v))
end
for op in (:+, :-)
@eval $op(A::$TYPE,B::$TYPE) = $TYPE($op(A.v,B.v))
end
Expand Down

0 comments on commit eb6c504

Please sign in to comment.