Skip to content

Commit

Permalink
Consolidate IOContext calls, add parens in a range
Browse files Browse the repository at this point in the history
  • Loading branch information
tkelman committed Jul 1, 2017
1 parent c2bcd15 commit 8db51e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function Base.show(io::IOContext, S::SparseMatrixCSC)
print(io, "\n \u22ee")
# find the column to start printing in for the last print_count elements
nextcol = searchsortedfirst(S.colptr, nnz(S) - print_count + 1)
for r = nnz(S) - print_count + 1 : S.colptr[nextcol] - 1
for r = (nnz(S) - print_count + 1) : (S.colptr[nextcol] - 1)
print(io, "\n", _format_line(r, nextcol - 1))
end
# print all of the remaining columns
Expand Down
8 changes: 4 additions & 4 deletions test/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1773,14 +1773,14 @@ end
show(io, MIME"text/plain"(), spzeros(Float32, Int64, 2, 2))
@test String(take!(io)) == "2×2 SparseMatrixCSC{Float32,Int64} with 0 stored entries"

ioc = IOContext(IOContext(io, :displaysize => (5, 80)), :limit => true)
ioc = IOContext(io, displaysize = (5, 80), limit = true)
show(ioc, MIME"text/plain"(), sparse(Int64[1], Int64[1], [1.0]))
@test String(take!(io)) == "1×1 SparseMatrixCSC{Float64,Int64} with 1 stored entry:\n [1, 1] = 1.0"
show(ioc, MIME"text/plain"(), sparse(Int64[1, 1], Int64[1, 2], [1.0, 2.0]))
@test String(take!(io)) == "1×2 SparseMatrixCSC{Float64,Int64} with 2 stored entries:\n"

# even number of rows
ioc = IOContext(IOContext(io, :displaysize => (8, 80)), :limit => true)
ioc = IOContext(io, displaysize = (8, 80), limit = true)
show(ioc, MIME"text/plain"(), sparse(Int64[1,2,3,4], Int64[1,1,2,2], [1.0,2.0,3.0,4.0]))
@test String(take!(io)) == string("4×2 SparseMatrixCSC{Float64,Int64} with 4 stored entries:\n [1, 1]",
" = 1.0\n [2, 1] = 2.0\n [3, 2] = 3.0\n [4, 2] = 4.0")
Expand All @@ -1794,7 +1794,7 @@ end
" = 1.0\n\n [5, 3] = 1.0")

# odd number of rows
ioc = IOContext(IOContext(io, :displaysize => (9, 80)), :limit => true)
ioc = IOContext(io, displaysize = (9, 80), limit = true)
show(ioc, MIME"text/plain"(), sparse(Int64[1,2,3,4,5], Int64[1,1,2,2,3], [1.0,2.0,3.0,4.0,5.0]))
@test String(take!(io)) == string("5×3 SparseMatrixCSC{Float64,Int64} with 5 stored entries:\n [1, 1]",
" = 1.0\n [2, 1] = 2.0\n [3, 2] = 3.0\n [4, 2] = 4.0\n [5, 3] = 5.0")
Expand All @@ -1807,7 +1807,7 @@ end
@test String(take!(io)) == string("6×3 SparseMatrixCSC{Float64,$Int} with 18 stored entries:\n [1, 1]",
" = 1.0\n [2, 1] = 1.0\n\n [5, 3] = 1.0\n [6, 3] = 1.0")

ioc = IOContext(io, :displaysize => (9, 80))
ioc = IOContext(io, displaysize = (9, 80))
show(ioc, MIME"text/plain"(), sparse(Int64[1,2,3,4,5,6], Int64[1,1,2,2,3,3], [1.0,2.0,3.0,4.0,5.0,6.0]))
@test String(take!(io)) == string("6×3 SparseMatrixCSC{Float64,Int64} with 6 stored entries:\n [1, 1] = 1.0\n",
" [2, 1] = 2.0\n [3, 2] = 3.0\n [4, 2] = 4.0\n [5, 3] = 5.0\n [6, 3] = 6.0")
Expand Down

0 comments on commit 8db51e6

Please sign in to comment.