Skip to content

Commit

Permalink
Add dispatch options
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromxavier committed Apr 13, 2023
1 parent 0175484 commit 7142759
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/interface/generic/cast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ end
function cast(
sense_route::Pair{A,B},
domain_route::Pair{X,Y},
data,
data...,
) where {A<:Sense,B<:Sense,X<:Domain,Y<:Domain}
return cast(sense_route, cast(domain_route, data))
return cast(sense_route, cast(domain_route, data...)...)
end
13 changes: 8 additions & 5 deletions src/library/sampleset.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
function cast(::Pair{D,D}, ψ::Vector{U}) where {U<:Integer,D<:Domain}
return copy(ψ)
end
cast(::Pair{D,D}, x::Integer) where {D<:Domain} = x
cast(::Pair{BoolDomain,SpinDomain}, x::Integer) = (2 * x) - 1
cast(::Pair{SpinDomain,BoolDomain}, s::Integer) = (s + 1) ÷ 2

cast(::Pair{BoolDomain,SpinDomain}, x::Integer) = (2 * x) - 1
cast(::Pair{SpinDomain,BoolDomain}, s::Integer) = (s + 1) ÷ 2
cast(::Pair{D,D}, ψ::Vector{U}) where {U<:Integer,D<:Domain} = copy(ψ)
cast(::Pair{BoolDomain,SpinDomain}, ψ::Vector{U}) where {U<:Integer} = (2 .* ψ) .- 1
cast(::Pair{SpinDomain,BoolDomain}, ψ::Vector{U}) where {U<:Integer} =.+ 1) 2

Expand Down Expand Up @@ -221,6 +220,10 @@ It was inspired by [^dwave], with a few tweaks.
return new{T,U}(data, metadata)
end

function SampleSet{T,U}(metadata::Dict{String,Any}) where {T,U}
return new{T,U}(Sample{T,U}[], metadata)
end

function SampleSet{T,U}() where {T,U}
return new{T,U}(Sample{T,U}[], Dict{String,Any}())
end
Expand Down

2 comments on commit 7142759

@pedromxavier
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/81533

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.1 -m "<description of version>" 7142759e5ae37ef985de62daaacb47761a4c3ab2
git push origin v0.7.1

Please sign in to comment.