-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into boostgeneral
- Loading branch information
Showing
20 changed files
with
382 additions
and
401 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export FunctionBlock | ||
|
||
""" | ||
FunctionBlock <: AbstractBlock | ||
This block contains a general function that perform an in-place operation over a register | ||
""" | ||
struct FunctionBlock{FT} <: AbstractBlock | ||
apply! | ||
function FunctionBlock{FT}(f) where FT | ||
!isempty(methods(f)) || throw(ArgumentError("Input is not callable!")) | ||
new{FT}(f) | ||
end | ||
end | ||
|
||
FunctionBlock(f) = FunctionBlock{typeof(f)}(f) | ||
apply!(reg::AbstractRegister, f::FunctionBlock) = f.apply!(reg) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export @fn, InvOrder, addbit, Reset | ||
|
||
macro fn(f) | ||
:(FunctionBlock($(esc(f)))) | ||
end | ||
|
||
macro fn(name::Symbol, f) | ||
FT = FunctionBlock{name} | ||
:($FT($(esc(f)))) | ||
end | ||
|
||
""" | ||
macro fn([name,] f) | ||
Define a in-place function on a register inside circuits. | ||
""" | ||
:(@fn) | ||
|
||
""" | ||
InvOrder | ||
Return a [`FunctionBlock`](@ref) of inversing the order. | ||
""" | ||
const InvOrder = @fn InvOrder invorder! | ||
|
||
""" | ||
Reset | ||
""" | ||
const Reset = @fn Reset reset! | ||
|
||
|
||
""" | ||
addbit(n::Int) -> FunctionBlock{:AddBit} | ||
Return a [`FunctionBlock`](@ref) of adding n bits. | ||
""" | ||
addbit(n::Int) = FunctionBlock{Tuple{:AddBit, n}}(reg->addbit!(reg, n)) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Compat | ||
using Compat.Test | ||
|
||
using Yao | ||
using Yao.Blocks | ||
|
||
@testset "functor" begin | ||
Test_InvOrder = FunctionBlock(invorder!) | ||
reg = rand_state(4) | ||
@test copy(reg) |> invorder! == apply!(copy(reg), Test_InvOrder) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters