Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ DocStringExtensions = "0.8.6, 0.9"
LinearAlgebra = "1"
OMEinsum = "0.9.1"
Pkg = "1"
PrettyTables = "2"
PrettyTables = "2, 3"
ProblemReductions = "0.3"
StatsBase = "0.34"
TropicalNumbers = "0.5.4, 0.6"
Expand Down
6 changes: 5 additions & 1 deletion src/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ Base.length(s::Samples) = size(s.samples, 2)
Base.size(s::Samples) = (size(s.samples, 2),)
function Base.show(io::IO, s::Samples) # display with PrettyTables
println(io, typeof(s))
PrettyTables.pretty_table(io, s.samples', header=s.labels)
if pkgversion(PrettyTables) < v"3"
PrettyTables.pretty_table(io, s.samples'; header=s.labels)
else
PrettyTables.pretty_table(io, s.samples'; column_labels=s.labels)
end
end
num_samples(samples::Samples) = size(samples.samples, 2)
function idx4labels(totalset::AbstractVector{L}, labels::AbstractVector{L})::Vector{Int} where L
Expand Down
12 changes: 11 additions & 1 deletion test/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ using TensorInference, Test, LinearAlgebra
import StatsBase
using OMEinsum, Random

@testset "Samples display" begin
samples = TensorInference.Samples([0 1; 1 0], ["x", "y"])
output = sprint(show, samples)
@test occursin("Samples{String}", output)
@test occursin("x", output)
@test occursin("y", output)
@test occursin("0", output)
@test occursin("1", output)
end

@testset "sampling" begin
model = TensorInference.read_model_from_string("""MARKOV
8
Expand Down Expand Up @@ -96,4 +106,4 @@ end
mps.tensors[setdiff(1:length(mps.tensors), mps.unity_tensors_idx)] .*= 100
samples = sample(mps, 1; rescale = true)
@test samples isa TensorInference.Samples
end
end
Loading