Skip to content

Commit eae28f9

Browse files
authored
Inherit matrix printing style from the parent array (#127)
1 parent 2ce0104 commit eae28f9

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ julia = "0.7, 1"
88
[extras]
99
CatIndices = "aafaddc9-749c-510e-ac4f-586e18779b91"
1010
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
11+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1112
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1213

1314
[targets]
14-
test = ["CatIndices", "DelimitedFiles", "Test"]
15+
test = ["CatIndices", "DelimitedFiles", "Test", "LinearAlgebra"]

src/OffsetArrays.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ printindices(io::IO, ind1) = print(io, _unslice(ind1))
240240
_unslice(x) = x
241241
_unslice(x::IdentityUnitRange) = x.indices
242242

243+
function Base.replace_in_print_matrix(A::OffsetArray{<:Any,2}, i::Integer, j::Integer, s::AbstractString)
244+
J = map(parentindex, axes(A), (i,j))
245+
Base.replace_in_print_matrix(parent(A), J..., s)
246+
end
247+
function Base.replace_in_print_matrix(A::OffsetArray{<:Any,1}, i::Integer, j::Integer, s::AbstractString)
248+
ip = parentindex(axes(A,1), i)
249+
Base.replace_in_print_matrix(parent(A), ip, j, s)
250+
end
251+
243252
"""
244253
no_offset_view(A)
245254

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using Test
33
using DelimitedFiles
44
using OffsetArrays: IdentityUnitRange, no_offset_view
55
using CatIndices: BidirectionalVector
6+
using LinearAlgebra
67

78
@test isempty(detect_ambiguities(OffsetArrays, Base, Core))
89

@@ -380,6 +381,13 @@ end
380381

381382
show(io, OffsetArray(3:5, 0:2))
382383
@test String(take!(io)) == "3:5 with indices 0:2"
384+
385+
d = Diagonal([1,2,3])
386+
Base.print_array(io, d)
387+
s1 = String(take!(io))
388+
Base.print_array(io, OffsetArray(d, -1:1, 3:5))
389+
s2 = String(take!(io))
390+
@test s1 == s2
383391
end
384392

385393
@testset "readdlm/writedlm" begin

0 commit comments

Comments
 (0)