1
- function cast (:: D , :: D , ψ:: Vector{U} ) where {D <: Domain ,U <: Integer }
1
+ function cast (:: Pair{D,D} , ψ:: Vector{U} ) where {U <: Integer ,D <: Domain }
2
2
return copy (ψ)
3
3
end
4
4
5
- cast (:: BoolDomain , :: SpinDomain , ψ:: Vector{U} ) where {U<: Integer } = (2 .* ψ) .- 1
6
- cast (:: SpinDomain , :: BoolDomain , ψ:: Vector{U} ) where {U<: Integer } = (ψ .+ 1 ) .÷ 2
5
+ cast (:: Pair{BoolDomain,SpinDomain} , x:: Integer ) = (2 * x) - 1
6
+ cast (:: Pair{SpinDomain,BoolDomain} , s:: Integer ) = (s + 1 ) ÷ 2
7
+ cast (:: Pair{BoolDomain,SpinDomain} , ψ:: Vector{U} ) where {U<: Integer } = (2 .* ψ) .- 1
8
+ cast (:: Pair{SpinDomain,BoolDomain} , ψ:: Vector{U} ) where {U<: Integer } = (ψ .+ 1 ) .÷ 2
7
9
8
- function cast (source :: Domain , target :: Domain , Ψ:: Vector{Vector{U}} ) where {U<: Integer }
9
- return cast .(source, target , Ψ)
10
+ function cast (route :: Pair{X,Y} , Ψ:: Vector{Vector{U}} ) where {U<: Integer ,X <: Domain ,Y <: Domain }
11
+ return cast .(route , Ψ)
10
12
end
11
13
12
14
@doc raw """
@@ -92,15 +94,15 @@ function format(data::Vector{Sample{T,U}}) where {T,U}
92
94
return sort (collect (values (cache)))
93
95
end
94
96
95
- function cast (source :: Domain , target :: Domain , s:: Sample{T,U} ) where {T,U}
96
- return Sample {T,U} (cast (source, target , state (s)), value (s), reads (s))
97
+ function cast (route :: Pair{X,Y} , s:: Sample{T,U} ) where {T,U,X <: Domain ,Y <: Domain }
98
+ return Sample {T,U} (cast (route , state (s)), value (s), reads (s))
97
99
end
98
100
99
- function cast (:: S , :: S , s:: Sample{T,U} ) where {S<: Sense ,T,U}
101
+ function cast (:: Pair{S,S} , s:: Sample{T,U} ) where {S<: Sense ,T,U}
100
102
return Sample {T,U} (state (s), value (s), reads (s))
101
103
end
102
104
103
- function cast (:: S1 , :: S2 , s:: Sample{T,U} ) where {S1 <: Sense ,S2 <: Sense ,T,U }
105
+ function cast (:: Pair{A,B} , s:: Sample{T,U} ) where {T,U,A <: Sense ,B <: Sense }
104
106
return Sample {T,U} (state (s), - value (s), reads (s))
105
107
end
106
108
@@ -189,18 +191,19 @@ reads(ω::AbstractSampleSet) = sum(reads.(ω))
189
191
@doc raw """
190
192
SampleSet{T,U}(
191
193
data::Vector{Sample{T,U}},
192
- metadata::Dict{String, Any},
194
+ metadata::Dict{String,Any},
193
195
) where {T,U}
194
196
195
197
It compresses repeated states by adding up the `reads` field.
196
- It was inspired by [1 ], with a few tweaks.
198
+ It was inspired by [^dwave ], with a few tweaks.
197
199
198
200
!!! info
199
201
A `SampleSet{T,U}` was designed to be read-only.
200
202
It is optimized to support queries over the solution set.
201
203
202
204
## References
203
- [1] [ocean docs](https://docs.ocean.dwavesys.com/en/stable/docs_dimod/reference/S.html#dimod.SampleSet)
205
+ [^dwave]:
206
+ [ocean docs](https://docs.ocean.dwavesys.com/en/stable/docs_dimod/reference/S.html#dimod.SampleSet)
204
207
""" struct SampleSet{T,U} <: AbstractSampleSet{T,U}
205
208
data:: Vector{Sample{T,U}}
206
209
metadata:: Dict{String,Any}
@@ -265,16 +268,10 @@ Base.iterate(ω::SampleSet, i::Integer) = iterate(ω.data, i)
265
268
266
269
metadata (ω:: SampleSet ) = ω. metadata
267
270
268
- function cast (source:: Domain , target:: Domain , ω:: SampleSet{T,U} ) where {T,U}
269
- return SampleSet {T,U} (
270
- Vector {Sample{T,U}} (cast .(source, target, ω)),
271
- deepcopy (metadata (ω)),
272
- )
271
+ function cast (route:: Pair{A,B} , ω:: SampleSet{T,U} ) where {T,U,A<: Sense ,B<: Sense }
272
+ return SampleSet {T,U} (Vector {Sample{T,U}} (cast .(route, ω)), deepcopy (metadata (ω)))
273
273
end
274
274
275
- function cast (source:: Sense , target:: Sense , ω:: SampleSet{T,U} ) where {T,U}
276
- return SampleSet {T,U} (
277
- Vector {Sample{T,U}} (cast .(source, target, ω)),
278
- deepcopy (metadata (ω)),
279
- )
280
- end
275
+ function cast (route:: Pair{X,Y} , ω:: SampleSet{T,U} ) where {T,U,X<: Domain ,Y<: Domain }
276
+ return SampleSet {T,U} (Vector {Sample{T,U}} (cast .(route, ω)), deepcopy (metadata (ω)))
277
+ end
0 commit comments