|
1 | | -export is_commutative_semiring |
2 | | -export Max2Poly, TruncatedPoly, Polynomial, Tropical, CountingTropical, StaticElementVector, Mod, ConfigEnumerator, onehotv, ConfigSampler |
3 | | -export set_type, sampler_type |
4 | | - |
5 | 1 | using Polynomials: Polynomial |
6 | 2 | using TropicalNumbers: Tropical, CountingTropical |
7 | 3 | using Mods, Primes |
@@ -60,7 +56,16 @@ function is_commutative_semiring(a::T, b::T, c::T) where T |
60 | 56 | return true |
61 | 57 | end |
62 | 58 |
|
63 | | -# get maximum two countings (polynomial truncated to largest two orders) |
| 59 | +""" |
| 60 | + TruncatedPoly{K,T,TO} <: Number |
| 61 | +
|
| 62 | +Polynomial truncated to largest `K` orders. `T` is the coefficients type and `TO` is the orders type. |
| 63 | +
|
| 64 | +```jldoctest; setup=(using GraphTensorNetworks) |
| 65 | +julia> TruncatedPoly((1,2,3), 6) |
| 66 | +x^4 + 2*x^5 + 3*x^6 |
| 67 | +``` |
| 68 | +""" |
64 | 69 | struct TruncatedPoly{K,T,TO} <: Number |
65 | 70 | coeffs::NTuple{K,T} |
66 | 71 | maxorder::TO |
|
125 | 130 | Base.:*(a::Bool, y::TruncatedPoly{K,T,TO}) where {K,T,TO} = a ? y : zero(y) |
126 | 131 | Base.:*(y::TruncatedPoly{K,T,TO}, a::Bool) where {K,T,TO} = a ? y : zero(y) |
127 | 132 |
|
| 133 | +""" |
| 134 | + ConfigEnumerator{N,S,C} |
| 135 | +
|
| 136 | +Set algebra for enumerating configurations, where `N` is the length of configurations, |
| 137 | +`C` is the size of storage in unit of `UInt64`, |
| 138 | +`S` is the bit width to store a single element in a configuration, i.e. `log2(# of flavors)`, for bitstrings, it is `1``. |
| 139 | +
|
| 140 | +```jldoctest; setup=:(using GraphTensorNetworks) |
| 141 | +julia> a = ConfigEnumerator([StaticBitVector([1,1,1,0,0]), StaticBitVector([1,0,0,0,1])]) |
| 142 | +{11100, 10001} |
| 143 | +
|
| 144 | +julia> b = ConfigEnumerator([StaticBitVector([0,0,0,0,0]), StaticBitVector([1,0,1,0,1])]) |
| 145 | +{00000, 10101} |
| 146 | +
|
| 147 | +julia> a + b |
| 148 | +{11100, 10001, 00000, 10101} |
| 149 | +``` |
| 150 | +""" |
128 | 151 | struct ConfigEnumerator{N,S,C} |
129 | 152 | data::Vector{StaticElementVector{N,S,C}} |
130 | 153 | end |
@@ -158,6 +181,18 @@ Base.show(io::IO, x::ConfigEnumerator) = print(io, "{", join(x.data, ", "), "}") |
158 | 181 | Base.show(io::IO, ::MIME"text/plain", x::ConfigEnumerator) = Base.show(io, x) |
159 | 182 |
|
160 | 183 | # the algebra sampling one of the configurations |
| 184 | +""" |
| 185 | + ConfigSampler{N,S,C} |
| 186 | +
|
| 187 | +The algebra for sampling one configuration, where `N` is the length of configurations, |
| 188 | +`C` is the size of storage in unit of `UInt64`, |
| 189 | +`S` is the bit width to store a single element in a configuration, i.e. `log2(# of flavors)`, for bitstrings, it is `1``. |
| 190 | +
|
| 191 | +```jldoctest; setup=:(using GraphTensorNetworks) |
| 192 | +julia> ConfigSampler(StaticBitVector([1,1,1,0,0])) |
| 193 | +ConfigSampler{5, 1, 1}(11100) |
| 194 | +``` |
| 195 | +""" |
161 | 196 | struct ConfigSampler{N,S,C} |
162 | 197 | data::StaticElementVector{N,S,C} |
163 | 198 | end |
|
0 commit comments