changeset 1011:f2c5d44a8db0 feature/lazy_tensors/pretty_printing

Update compact context handeling and fix type
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 21 Mar 2022 08:55:54 +0100
parents 7acd417b780d
children 2c1a0722ddb9
files src/LazyTensors/tensor_types.jl test/LazyTensors/tensor_types_test.jl
diffstat 2 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/LazyTensors/tensor_types.jl	Mon Mar 21 08:04:36 2022 +0100
+++ b/src/LazyTensors/tensor_types.jl	Mon Mar 21 08:55:54 2022 +0100
@@ -19,7 +19,7 @@
 apply_transpose(tmi::IdentityTensor{T,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,D}) where {T,D} = v[I...]
 
 function Base.show(io::IO, ::MIME"text/plain", tm::IdentityTensor{T}) where T
-    if (:comact => true) in io
+    if get(io, :compact, false)
         print(io, "I")
     else
         print(io, "IdentityTensor{$T}")
@@ -47,7 +47,7 @@
 LazyTensors.domain_size(m::ScalingTensor) = m.size
 
 function Base.show(io::IO, ::MIME"text/plain", tm::ScalingTensor{T}) where T
-    if (:comact => true) in io
+    if get(io, :compact, false)
         print(io, "$(tm.λ)*I(")
         join(io, tm.size, ",")
         print(io, ")")
--- a/test/LazyTensors/tensor_types_test.jl	Mon Mar 21 08:04:36 2022 +0100
+++ b/test/LazyTensors/tensor_types_test.jl	Mon Mar 21 08:55:54 2022 +0100
@@ -46,8 +46,8 @@
         @test repr(MIME("text/plain"), IdentityTensor{Float64}(5)) == "IdentityTensor{Float64}(5)"
         @test repr(MIME("text/plain"), IdentityTensor{Int}(4,5)) == "IdentityTensor{Int64}(4,5)"
 
-        @test repr(MIME("text/plain"), IdentityTensor{Float64}(5), context=:comact=>true) == "I(5)"
-        @test repr(MIME("text/plain"), IdentityTensor{Int}(4,5), context=:comact=>true) == "I(4,5)"
+        @test repr(MIME("text/plain"), IdentityTensor{Float64}(5), context=:compact=>true) == "I(5)"
+        @test repr(MIME("text/plain"), IdentityTensor{Int}(4,5), context=:compact=>true) == "I(4,5)"
     end
 end
 
@@ -69,8 +69,8 @@
         @test repr(MIME("text/plain"), ScalingTensor(2., (5,))) == "ScalingTensor{Float64}(2.0, (5,))" # TODO: Can we make this nicer?
         @test repr(MIME("text/plain"), ScalingTensor(3, (4,5))) == "ScalingTensor{Int64}(3, (4, 5))"
 
-        @test repr(MIME("text/plain"), ScalingTensor(4., (5,)), context=:comact=>true) == "4.0*I(5)"
-        @test repr(MIME("text/plain"), ScalingTensor(2, (4,5)), context=:comact=>true) == "2*I(4,5)"
+        @test repr(MIME("text/plain"), ScalingTensor(4., (5,)), context=:compact=>true) == "4.0*I(5)"
+        @test repr(MIME("text/plain"), ScalingTensor(2, (4,5)), context=:compact=>true) == "2*I(4,5)"
     end
 end