Skip to content

Commit

Permalink
replace Base64.stringmime by sprint (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub authored Nov 20, 2023
1 parent 56ccada commit 4c466fc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 35 deletions.
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[compat]
Aqua = "0.8"
Base64 = "1.6"
ArrayLayouts = "1.0.8"
Documenter = "0.27"
FillArrays = "1"
Expand All @@ -23,7 +22,6 @@ julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -32,4 +30,4 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "Base64", "Documenter", "OffsetArrays", "SparseArrays", "StaticArrays", "Test", "Random"]
test = ["Aqua", "Documenter", "OffsetArrays", "SparseArrays", "StaticArrays", "Test", "Random"]
12 changes: 6 additions & 6 deletions test/test_blockarrayinterface.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BlockArrays, LinearAlgebra, FillArrays, Base64, Test
using BlockArrays, LinearAlgebra, FillArrays, Test

# avoid fast-paths for view
bview(a, b) = Base.invoke(view, Tuple{AbstractArray,Any}, a, b)
Expand Down Expand Up @@ -51,7 +51,7 @@ end
@test H[Block(2, 3)] == A[2:3, 4:6]
@test H[Block(3, 2)] == A[2:3, 4:6]'

@test stringmime("text/plain", UpperTriangular(A)) == "10×10 UpperTriangular{ComplexF64, PseudoBlockMatrix{ComplexF64, Matrix{ComplexF64}, $(typeof(axes(A)))}} with indices 1:1:10×1:1:10:\n 1.0+0.0im │ 11.0+0.0im 21.0+0.0im │ 31.0+0.0im 41.0+0.0im 51.0+0.0im │ 61.0+0.0im 71.0+0.0im 81.0+0.0im 91.0+0.0im\n ───────────┼──────────────────────────┼──────────────────────────────────────┼─────────────────────────────────────────────────\n ⋅ │ 12.0+0.0im 22.0+0.0im │ 32.0+0.0im 42.0+0.0im 52.0+0.0im │ 62.0+0.0im 72.0+0.0im 82.0+0.0im 92.0+0.0im\n ⋅ │ ⋅ 23.0+0.0im │ 33.0+0.0im 43.0+0.0im 53.0+0.0im │ 63.0+0.0im 73.0+0.0im 83.0+0.0im 93.0+0.0im\n ───────────┼──────────────────────────┼──────────────────────────────────────┼─────────────────────────────────────────────────\n ⋅ │ ⋅ ⋅ │ 34.0+0.0im 44.0+0.0im 54.0+0.0im │ 64.0+0.0im 74.0+0.0im 84.0+0.0im 94.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ 45.0+0.0im 55.0+0.0im │ 65.0+0.0im 75.0+0.0im 85.0+0.0im 95.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ 56.0+0.0im │ 66.0+0.0im 76.0+0.0im 86.0+0.0im 96.0+0.0im\n ───────────┼──────────────────────────┼──────────────────────────────────────┼─────────────────────────────────────────────────\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ 67.0+0.0im 77.0+0.0im 87.0+0.0im 97.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ ⋅ 78.0+0.0im 88.0+0.0im 98.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ ⋅ ⋅ 89.0+0.0im 99.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ ⋅ ⋅ ⋅ 100.0+0.0im"
@test sprint(show, "text/plain", UpperTriangular(A)) == "10×10 UpperTriangular{ComplexF64, PseudoBlockMatrix{ComplexF64, Matrix{ComplexF64}, $(typeof(axes(A)))}} with indices 1:1:10×1:1:10:\n 1.0+0.0im │ 11.0+0.0im 21.0+0.0im │ 31.0+0.0im 41.0+0.0im 51.0+0.0im │ 61.0+0.0im 71.0+0.0im 81.0+0.0im 91.0+0.0im\n ───────────┼──────────────────────────┼──────────────────────────────────────┼─────────────────────────────────────────────────\n ⋅ │ 12.0+0.0im 22.0+0.0im │ 32.0+0.0im 42.0+0.0im 52.0+0.0im │ 62.0+0.0im 72.0+0.0im 82.0+0.0im 92.0+0.0im\n ⋅ │ ⋅ 23.0+0.0im │ 33.0+0.0im 43.0+0.0im 53.0+0.0im │ 63.0+0.0im 73.0+0.0im 83.0+0.0im 93.0+0.0im\n ───────────┼──────────────────────────┼──────────────────────────────────────┼─────────────────────────────────────────────────\n ⋅ │ ⋅ ⋅ │ 34.0+0.0im 44.0+0.0im 54.0+0.0im │ 64.0+0.0im 74.0+0.0im 84.0+0.0im 94.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ 45.0+0.0im 55.0+0.0im │ 65.0+0.0im 75.0+0.0im 85.0+0.0im 95.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ 56.0+0.0im │ 66.0+0.0im 76.0+0.0im 86.0+0.0im 96.0+0.0im\n ───────────┼──────────────────────────┼──────────────────────────────────────┼─────────────────────────────────────────────────\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ 67.0+0.0im 77.0+0.0im 87.0+0.0im 97.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ ⋅ 78.0+0.0im 88.0+0.0im 98.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ ⋅ ⋅ 89.0+0.0im 99.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ ⋅ ⋅ ⋅ 100.0+0.0im"

V = view(A, Block.(1:2), Block.(1:2))
@test blockisequal(axes(Symmetric(V)), axes(view(A, Block.(1:2), Block.(1:2))))
Expand Down Expand Up @@ -130,7 +130,7 @@ end
@test_throws BlockBoundsError A[Block(1, 3)]
@test A == [1 2 0 0; 0 0 1 2]
@test BlockArray(A) == A
@test stringmime("text/plain", A) == "2×2-blocked 2×4 BlockMatrix{$Int, Diagonal{Matrix{$Int}, Vector{Matrix{$Int}}}, Tuple{BlockedUnitRange{Vector{$Int}}, BlockedUnitRange{Vector{$Int}}}}:\n 1 2 │ ⋅ ⋅\n ──────┼──────\n ⋅ ⋅ │ 1 2"
@test sprint(show, "text/plain", A) == "2×2-blocked 2×4 BlockMatrix{$Int, Diagonal{Matrix{$Int}, Vector{Matrix{$Int}}}, Tuple{BlockedUnitRange{Vector{$Int}}, BlockedUnitRange{Vector{$Int}}}}:\n 1 2 │ ⋅ ⋅\n ──────┼──────\n ⋅ ⋅ │ 1 2"

N = 3
D = Diagonal(mortar(Fill.(-(0:N) - (0:N) .^ 2, 1:2:2N+1)))
Expand Down Expand Up @@ -187,9 +187,9 @@ end

U = UpperTriangular(Ones((blockedrange([1, 2]), blockedrange([2, 1]))))

@test stringmime("text/plain", A) == "5-element Fill{$Int, 1, Tuple{BlockedUnitRange{Vector{$Int}}}} with indices 1:1:5, with entries equal to 2"
@test stringmime("text/plain", B) == "3×3 Diagonal{Float64, Ones{Float64, 1, Tuple{BlockedUnitRange{Vector{$Int}}}}} with indices 1:1:3×1:1:3"
@test stringmime("text/plain", U) == "3×3 UpperTriangular{Float64, Ones{Float64, 2, Tuple{BlockedUnitRange{Vector{$Int}}, BlockedUnitRange{Vector{$Int}}}}} with indices 1:1:3×1:1:3:\n 1.0 1.0 │ 1.0\n ──────────┼─────\n ⋅ 1.0 │ 1.0\n ⋅ ⋅ │ 1.0"
@test sprint(show, "text/plain", A) == "5-element Fill{$Int, 1, Tuple{BlockedUnitRange{Vector{$Int}}}} with indices 1:1:5, with entries equal to 2"
@test sprint(show, "text/plain", B) == "3×3 Diagonal{Float64, Ones{Float64, 1, Tuple{BlockedUnitRange{Vector{$Int}}}}} with indices 1:1:3×1:1:3"
@test sprint(show, "text/plain", U) == "3×3 UpperTriangular{Float64, Ones{Float64, 2, Tuple{BlockedUnitRange{Vector{$Int}}, BlockedUnitRange{Vector{$Int}}}}} with indices 1:1:3×1:1:3:\n 1.0 1.0 │ 1.0\n ──────────┼─────\n ⋅ 1.0 │ 1.0\n ⋅ ⋅ │ 1.0"

@testset "views" begin
# This in theory can be dropped because `view` returns the block, but we keep in case needed
Expand Down
24 changes: 12 additions & 12 deletions test/test_blockarrays.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SparseArrays, BlockArrays, Base64, FillArrays, LinearAlgebra, Test
using SparseArrays, BlockArrays, FillArrays, LinearAlgebra, Test
import BlockArrays: _BlockArray

function test_error_message(f, needle, expected = Exception)
Expand Down Expand Up @@ -480,24 +480,24 @@ end
end

@testset "replstring" begin
@test stringmime("text/plain",BlockArray(collect(1:4), [1,3])) == "2-blocked 4-element BlockVector{$Int}:\n 1\n\n 2\n 3\n 4"
@test stringmime("text/plain",PseudoBlockArray(collect(1:4), [1,3])) == "2-blocked 4-element PseudoBlockVector{$Int}:\n 1\n\n 2\n 3\n 4"
@test stringmime("text/plain",BlockArray(collect(reshape(1:16, 4, 4)), [1,3], [2,2])) == "2×2-blocked 4×4 BlockMatrix{$Int}:\n 1 5 │ 9 13\n ──────┼────────\n 2 6 │ 10 14\n 3 7 │ 11 15\n 4 8 │ 12 16"
@test stringmime("text/plain",PseudoBlockArray(collect(reshape(1:16, 4, 4)), [1,3], [2,2])) == "2×2-blocked 4×4 PseudoBlockMatrix{$Int}:\n 1 5 │ 9 13\n ──────┼────────\n 2 6 │ 10 14\n 3 7 │ 11 15\n 4 8 │ 12 16"
@test stringmime("text/plain",BlockArray(collect(reshape(1:8, 2, 2, 2)), [1,1], [1,1], [1,1])) == "2×2×2-blocked 2×2×2 BlockArray{$Int, 3}:\n[:, :, 1] =\n 1 3\n 2 4\n\n[:, :, 2] =\n 5 7\n 6 8"
@test stringmime("text/plain",PseudoBlockArray(collect(reshape(1:8, 2, 2, 2)), [1,1], [1,1], [1,1])) == "2×2×2-blocked 2×2×2 PseudoBlockArray{$Int, 3}:\n[:, :, 1] =\n 1 3\n 2 4\n\n[:, :, 2] =\n 5 7\n 6 8"
@test sprint(show, "text/plain", BlockArray(collect(1:4), [1,3])) == "2-blocked 4-element BlockVector{$Int}:\n 1\n\n 2\n 3\n 4"
@test sprint(show, "text/plain", PseudoBlockArray(collect(1:4), [1,3])) == "2-blocked 4-element PseudoBlockVector{$Int}:\n 1\n\n 2\n 3\n 4"
@test sprint(show, "text/plain", BlockArray(collect(reshape(1:16, 4, 4)), [1,3], [2,2])) == "2×2-blocked 4×4 BlockMatrix{$Int}:\n 1 5 │ 9 13\n ──────┼────────\n 2 6 │ 10 14\n 3 7 │ 11 15\n 4 8 │ 12 16"
@test sprint(show, "text/plain", PseudoBlockArray(collect(reshape(1:16, 4, 4)), [1,3], [2,2])) == "2×2-blocked 4×4 PseudoBlockMatrix{$Int}:\n 1 5 │ 9 13\n ──────┼────────\n 2 6 │ 10 14\n 3 7 │ 11 15\n 4 8 │ 12 16"
@test sprint(show, "text/plain", BlockArray(collect(reshape(1:8, 2, 2, 2)), [1,1], [1,1], [1,1])) == "2×2×2-blocked 2×2×2 BlockArray{$Int, 3}:\n[:, :, 1] =\n 1 3\n 2 4\n\n[:, :, 2] =\n 5 7\n 6 8"
@test sprint(show, "text/plain", PseudoBlockArray(collect(reshape(1:8, 2, 2, 2)), [1,1], [1,1], [1,1])) == "2×2×2-blocked 2×2×2 PseudoBlockArray{$Int, 3}:\n[:, :, 1] =\n 1 3\n 2 4\n\n[:, :, 2] =\n 5 7\n 6 8"
design = zeros(Int16,6,9);
A = BlockArray(design,[6],[4,5])
@test stringmime("text/plain",A) == "1×2-blocked 6×9 BlockMatrix{Int16}:\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0"
@test sprint(show, "text/plain", A) == "1×2-blocked 6×9 BlockMatrix{Int16}:\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0"
A = PseudoBlockArray(design,[6],[4,5])
@test stringmime("text/plain",A) == "1×2-blocked 6×9 PseudoBlockMatrix{Int16}:\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0"
@test sprint(show, "text/plain", A) == "1×2-blocked 6×9 PseudoBlockMatrix{Int16}:\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0"
D = PseudoBlockArray(Diagonal(1:3), [1,2], [2,1])
@test stringmime("text/plain", D) == "2×2-blocked 3×3 $(PseudoBlockMatrix{Int, Diagonal{Int, UnitRange{Int}}, Tuple{BlockedUnitRange{Vector{Int}}, BlockedUnitRange{Vector{Int}}}}):\n 1 ⋅ │ ⋅\n ──────┼───\n ⋅ 2 │ ⋅\n ⋅ ⋅ │ 3"
@test sprint(show, "text/plain", D) == "2×2-blocked 3×3 $(PseudoBlockMatrix{Int, Diagonal{Int, UnitRange{Int}}, Tuple{BlockedUnitRange{Vector{Int}}, BlockedUnitRange{Vector{Int}}}}):\n 1 ⋅ │ ⋅\n ──────┼───\n ⋅ 2 │ ⋅\n ⋅ ⋅ │ 3"

a = BlockArray{Int}(undef_blocks, [1,2])
@test stringmime("text/plain", a) == "2-blocked 3-element BlockVector{Int64}:\n #undef\n ──────\n #undef\n #undef"
@test sprint(show, "text/plain", a) == "2-blocked 3-element BlockVector{Int64}:\n #undef\n ──────\n #undef\n #undef"
B = BlockArray{Int}(undef_blocks, [1,2], [1,1])
@test stringmime("text/plain", B) == "2×2-blocked 3×2 BlockMatrix{Int64}:\n #undef │ #undef\n ────────┼────────\n #undef │ #undef\n #undef │ #undef"
@test sprint(show, "text/plain", B) == "2×2-blocked 3×2 BlockMatrix{Int64}:\n #undef │ #undef\n ────────┼────────\n #undef │ #undef\n #undef │ #undef"
end

@testset "AbstractVector{Int} blocks" begin
Expand Down
22 changes: 11 additions & 11 deletions test/test_blockindices.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BlockArrays, FillArrays, Test, Base64, StaticArrays, ArrayLayouts
using BlockArrays, FillArrays, Test, StaticArrays, ArrayLayouts
using OffsetArrays
import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice

Expand Down Expand Up @@ -100,16 +100,16 @@ import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice
end

@testset "print" begin
@test stringmime("text/plain", Block()) == "Block()"
@test stringmime("text/plain", Block(1)) == "Block(1)"
@test stringmime("text/plain", Block(1,2)) == "Block(1, 2)"
@test stringmime("text/plain", Block{0}()) == "Block()"
@test stringmime("text/plain", Block{1}(1)) == "Block(1)"
@test stringmime("text/plain", Block{2}(1,2)) == "Block(1, 2)"
@test sprint(show, "text/plain", Block()) == "Block()"
@test sprint(show, "text/plain", Block(1)) == "Block(1)"
@test sprint(show, "text/plain", Block(1,2)) == "Block(1, 2)"
@test sprint(show, "text/plain", Block{0}()) == "Block()"
@test sprint(show, "text/plain", Block{1}(1)) == "Block(1)"
@test sprint(show, "text/plain", Block{2}(1,2)) == "Block(1, 2)"

@test stringmime("text/plain", Block{0,BigInt}()) == "Block{0, BigInt}(())"
@test stringmime("text/plain", Block{1,BigInt}(1)) == "Block{1, BigInt}((1,))"
@test stringmime("text/plain", Block{2}(1,2)) == "Block(1, 2)"
@test sprint(show, "text/plain", Block{0,BigInt}()) == "Block{0, BigInt}(())"
@test sprint(show, "text/plain", Block{1,BigInt}(1)) == "Block{1, BigInt}((1,))"
@test sprint(show, "text/plain", Block{2}(1,2)) == "Block(1, 2)"

@test sprint(show, BlockRange(1:2, 2:3)) == "BlockRange(1:2, 2:3)"
@test sprint(show, "text/plain", BlockRange(1:2, 2:3)) == "BlockRange(1:2, 2:3)"
Expand Down Expand Up @@ -314,7 +314,7 @@ end
@test findblock(b,1) == Block(1)
@test_throws BoundsError findblock(b,0)
@test_throws BoundsError findblock(b,6)
@test stringmime("text/plain",blockedrange([1,2,2])) == "3-blocked 5-element BlockedUnitRange{Vector{$Int}}:\n 1\n\n 2\n 3\n\n 4\n 5"
@test sprint(show, "text/plain", blockedrange([1,2,2])) == "3-blocked 5-element BlockedUnitRange{Vector{$Int}}:\n 1\n\n 2\n 3\n\n 4\n 5"
end

@testset "BlockIndex type piracy (#108)" begin
Expand Down
6 changes: 3 additions & 3 deletions test/test_blockviews.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BlockArrays, ArrayLayouts, Test, Base64
using BlockArrays, ArrayLayouts, Test

# useds to force SubArray return
bview(a, b) = Base.invoke(view, Tuple{AbstractArray,Any}, a, b)
Expand Down Expand Up @@ -193,11 +193,11 @@ bview(a, b) = Base.invoke(view, Tuple{AbstractArray,Any}, a, b)
@test blocks(V) == blocks(A)[1:1,1:2]
@test blocks(W) == blocks(A)[1:2,1:1]
Vi = parentindices(V)
@test stringmime("text/plain", V) == "1×3 view(::BlockMatrix{$Int, Matrix{Matrix{$Int}}, "*
@test sprint(show, "text/plain", V) == "1×3 view(::BlockMatrix{$Int, Matrix{Matrix{$Int}}, "*
"$(typeof(axes(A)))}, $(Vi[1]), $(Vi[2])) "*
"with eltype $Int with indices $(axes(V,1))×$(axes(V,2)):\n 1 │ 2 3"
Wi = parentindices(W)
@test stringmime("text/plain", W) == "3×1 view(::BlockMatrix{$Int, Matrix{Matrix{$Int}}"*
@test sprint(show, "text/plain", W) == "3×1 view(::BlockMatrix{$Int, Matrix{Matrix{$Int}}"*
", $(typeof(axes(A)))}, $(Wi[1]), $(Wi[2])) "*
"with eltype $Int with indices $(axes(W,1))×$(axes(W,2)):\n 1\n\n 4\n 7"
end
Expand Down

0 comments on commit 4c466fc

Please sign in to comment.