Skip to content

Commit

Permalink
change type parameter order (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger-luo authored Apr 23, 2019
1 parent b540df0 commit 98c6531
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/composite/composite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ YaoBase.ishermitian(m::CompositeBlock) = all(ishermitian, subblocks(m)) || isher
YaoBase.isreflexive(m::CompositeBlock) = all(isreflexive, subblocks(m)) || isreflexive(mat(m))

"""
AbstractContainer{N, T} <: CompositeBlock{N, T}
AbstractContainer{BT, N, T} <: CompositeBlock{N, T}
Abstract type for container block. Container blocks are blocks contain a single
block. Container block should have a
"""
abstract type AbstractContainer{N, T, BT <: AbstractBlock} <: CompositeBlock{N, T} end
abstract type AbstractContainer{BT <: AbstractBlock, N, T} <: CompositeBlock{N, T} end

"""
content(x)
Expand Down Expand Up @@ -76,8 +76,8 @@ for METHOD in (:ishermitian, :isreflexive, :isunitary)
end
end

function Base.:(==)(lhs::AbstractContainer{N, T, BT},
rhs::AbstractContainer{N, T, BT}) where {N, T, BT}
function Base.:(==)(lhs::AbstractContainer{BT, N, T},
rhs::AbstractContainer{BT, N, T}) where {BT, N, T}
return content(lhs) == content(rhs)
end

Expand Down
4 changes: 2 additions & 2 deletions src/composite/concentrator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ using YaoBase
export Concentrator, concentrate

"""
Concentrator{N, T, BT <: AbstractBlock} <: AbstractContainer{N, T}
Concentrator{N, T, BT <: AbstractBlock} <: AbstractContainer{BT, N, T}
concentrates serveral lines together in the circuit, and expose
it to other blocks.
"""
struct Concentrator{N, T, BT <: AbstractBlock, C} <: AbstractContainer{N, T, BT}
struct Concentrator{N, T, BT <: AbstractBlock, C} <: AbstractContainer{BT, N, T}
content::BT
locations::NTuple{C, Int}
end
Expand Down
2 changes: 1 addition & 1 deletion src/composite/control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using YaoArrayRegister: matvec

export ControlBlock, control

struct ControlBlock{N, BT<:AbstractBlock, C, M, T} <: AbstractContainer{N, T, BT}
struct ControlBlock{N, BT<:AbstractBlock, C, M, T} <: AbstractContainer{BT, N, T}
ctrl_locs::NTuple{C, Int}
ctrl_config::NTuple{C, Int}
content::BT
Expand Down
2 changes: 1 addition & 1 deletion src/composite/put_block.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export PutBlock, put
Type for putting a block at given locations.
"""
struct PutBlock{N, C, T, GT <: AbstractBlock} <: AbstractContainer{N, T, GT}
struct PutBlock{N, C, T, GT <: AbstractBlock} <: AbstractContainer{GT, N, T}
content::GT
locs::NTuple{C, Int}

Expand Down
2 changes: 1 addition & 1 deletion src/composite/repeated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export RepeatedBlock, repeat
Repeat the same block on given locations.
"""
struct RepeatedBlock{N, C, GT <: AbstractBlock, T} <: AbstractContainer{N, T, GT}
struct RepeatedBlock{N, C, GT <: AbstractBlock, T} <: AbstractContainer{GT, N, T}
content::GT
locs::NTuple{C, Int}
end
Expand Down
4 changes: 2 additions & 2 deletions src/composite/tag/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ CacheServers.pull(frag::CacheFragment) = frag.storage[cache_key(frag.ref)]
CacheServers.clear!(frag::CacheFragment) = (empty!(frag.storage); frag)

"""
CachedBlock{ST, BT, N, T} <: AbstractContainer{N, T, BT}
CachedBlock{ST, BT, N, T} <: TagBlock{BT, N, T}
A label type that tags an instance of type `BT`. It forwards
every methods of the block it contains, except [`mat`](@ref)
and [`apply!`](@ref), it will cache the matrix form whenever
the program has.
"""
struct CachedBlock{ST, BT, N, T} <: TagBlock{N, T, BT}
struct CachedBlock{ST, BT, N, T} <: TagBlock{BT, N, T}
server::ST
content::BT
level::Int
Expand Down
4 changes: 2 additions & 2 deletions src/composite/tag/dagger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ export Daggered
Wrapper block allowing to execute the inverse of a block of quantum circuit.
"""
struct Daggered{N, T, BT <: AbstractBlock} <: TagBlock{N, T, BT}
struct Daggered{BT <: AbstractBlock, N, T} <: TagBlock{BT, N, T}
content::BT
end

Daggered(x::BT) where {N, T, BT<:AbstractBlock{N, T}} =
Daggered{N, T, BT}(x)
Daggered{BT, N, T}(x)

PreserveStyle(::Daggered) = PreserveAll()
mat(blk::Daggered) = adjoint(mat(content(blk)))
Expand Down
2 changes: 1 addition & 1 deletion src/composite/tag/scale.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using LinearAlgebra

export Scale

struct Scale{S <: Union{Number, Val}, N, T, BT <: AbstractBlock{N, T}} <: TagBlock{N, T, BT}
struct Scale{S <: Union{Number, Val}, N, T, BT <: AbstractBlock{N, T}} <: TagBlock{BT, N, T}
alpha::S
content::BT
end
Expand Down
4 changes: 2 additions & 2 deletions src/composite/tag/tag.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export TagBlock

"""
TagBlock{N, T} <: AbstractContainer{N, T}
TagBlock{BT, N, T} <: AbstractContainer{BT, N, T}
`TagBlock` is a special kind of Container block, it forwards most of the methods
but tag the block with some extra information.
"""
abstract type TagBlock{N, T, BT} <: AbstractContainer{N, T, BT} end
abstract type TagBlock{BT, N, T} <: AbstractContainer{BT, N, T} end

cache_key(tb::TagBlock) = cache_key(content(tb))
occupied_locs(x::TagBlock) = occupied_locs(content(x))
Expand Down
2 changes: 1 addition & 1 deletion src/layout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Base.show(io::IO, ::MIME"plain/text", blk::AbstractBlock) = print_tree(io, blk)


function Base.show(io::IO, ::MIME"plain/text",
blk::TagBlock{N, T, <:PrimitiveBlock}) where {N, T}
blk::TagBlock{<:PrimitiveBlock})
return print_tree(io, blk; title=false, compact=false)
end

Expand Down

0 comments on commit 98c6531

Please sign in to comment.