Skip to content

Commit 187b579

Browse files
committed
add/fix tests
1 parent 1afabba commit 187b579

6 files changed

Lines changed: 51 additions & 36 deletions

File tree

docs/src/index.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ julia> I = [1, 4, 3, 5]; J = [4, 7, 18, 9]; V = [1, 2, -5, 3];
113113
114114
julia> S = sparse(I,J,V)
115115
5×18 SparseMatrixCSC{Int64, Int64} with 4 stored entries:
116-
⎡⠀⠈⠀⠀⠀⠀⠀⠀⢀⎤
117-
⎣⠀⠀⠀⠂⡀⠀⠀⠀⠀⎦
116+
⋅ ⋅ ⋅ 1 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
117+
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
118+
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ -5
119+
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 2 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
120+
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 3 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
118121
119122
julia> R = sparsevec(I,V)
120123
5-element SparseVector{Int64, Int64} with 4 stored entries:

src/linalg.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,19 +2094,19 @@ julia> A[4:4:8] .= 1;
20942094
20952095
julia> A
20962096
3×3 SparseMatrixCSC{Float64, Int64} with 2 stored entries:
2097-
1.0 ⋅
2098-
⋅ 1.0
2099-
⋅ ⋅
2097+
1.0 ⋅
2098+
⋅ 1.0
2099+
⋅ ⋅
21002100
21012101
julia> C = spzeros(3,3);
21022102
21032103
julia> C[2:4:6] .= 2;
21042104
21052105
julia> C
21062106
3×3 SparseMatrixCSC{Float64, Int64} with 2 stored entries:
2107-
⋅ ⋅
2108-
2.0 ⋅
2109-
⋅ 2.0
2107+
⋅ ⋅ ⋅
2108+
2.0 ⋅ ⋅
2109+
⋅ 2.0 ⋅
21102110
21112111
julia> SparseArrays.mergeinds!(C, A)
21122112
3×3 SparseMatrixCSC{Float64, Int64} with 4 stored entries:

src/solvers/spqr.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ Q factor:
192192
4×4 SparseArrays.SPQR.QRSparseQ{Float64, Int64}
193193
R factor:
194194
2×2 SparseMatrixCSC{Float64, Int64} with 2 stored entries:
195-
-1.41421 ⋅
196-
-1.41421
195+
-1.41421
196+
-1.41421
197197
Row permutation:
198198
4-element Vector{Int64}:
199199
1
@@ -471,10 +471,10 @@ when the problem is underdetermined.
471471
```jldoctest
472472
julia> A = sparse([1,2,4], [1,1,1], [1.0,1.0,1.0], 4, 2)
473473
4×2 SparseMatrixCSC{Float64, Int64} with 3 stored entries:
474-
1.0
475-
1.0
476-
477-
1.0
474+
1.0 ⋅
475+
1.0 ⋅
476+
⋅ ⋅
477+
1.0 ⋅
478478
479479
julia> qr(A)\\fill(1.0, 4)
480480
2-element Vector{Float64}:

src/sparsematrix.jl

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ function Base.show(io::IO, ::MIME"text/plain", S::AbstractSparseMatrixCSCInclAdj
360360
show_circular(io, S) && return
361361
io = IOContext(io, :compact=>true, :typeinfo=>eltype(S), :SHOWN_SET=>S)
362362

363-
if (screen[1] < size(S, 1) + 4) | (screen[2] < 3size(S, 2))
363+
if (screen[1] < size(S, 1) + 5) | (screen[2] < 3size(S, 2))
364364
_show_with_braille_patterns(io, S)
365365
else
366366
_show_with_dotted_zeros(io, S)
@@ -410,12 +410,6 @@ end
410410

411411
const brailleBlocks = UInt16['', '', '', '', '', '', '', '']
412412
function _show_with_braille_patterns(io::IO, S::AbstractSparseMatrixCSCInclAdjointAndTranspose)
413-
try
414-
zero(eltype(S))
415-
catch
416-
printstyled(io, "WARNING: could not find generic zero for given elements. expect errors and wrong results\n", color=:red)
417-
end
418-
419413
m, n = size(S)
420414
(m == 0 || n == 0) && return show(io, MIME("text/plain"), S)
421415

@@ -424,6 +418,13 @@ function _show_with_braille_patterns(io::IO, S::AbstractSparseMatrixCSCInclAdjoi
424418
maxHeight = displaysize(io)[1] - 4 # -4 from [Prompt, header, newline after elements, new prompt]
425419
maxWidth = displaysize(io)[2] - 2 # -2 from brackets
426420

421+
try
422+
zero(eltype(S))
423+
catch
424+
printstyled(stderr, "WARNING: could not find generic zero for given elements. expect errors and wrong results\n", color=:red)
425+
maxHeight = maxHeight - 1
426+
end
427+
427428
# In the process of generating the braille pattern to display the nonzero
428429
# structure of `S`, we need to be able to scale the matrix `S` to a
429430
# smaller matrix with the same aspect ratio as `S`, but fits on the
@@ -511,14 +512,14 @@ function _show_with_dotted_zeros(io::IO, S::AbstractSparseMatrixCSCInclAdjointAn
511512
rows, cols, vals = rowvals(parent(S)), ColumnIndices(parent(S)), nonzeros(parent(S))
512513
(S isa Adjoint) | (S isa Transpose) && ((rows, cols) = (cols, rows))
513514

514-
align = [alignment(io, val) for val in vals]
515+
align = [isassigned(vals, val) ? alignment(io, vals[val]) : (3, 3) for val in eachindex(vals)]
515516
colwidths = [max.((0, 0), align[findall(==(col), cols)]...) for col in axes(S,2)]
516517
displaysize(io)[2] < sum(sum.(colwidths) .+ 2) && return _show_with_braille_patterns(io, S)
517518

518519
try
519520
zero(eltype(S))
520521
catch
521-
printstyled(io, "WARNING: could not find generic zero for given elements. expect errors and wrong results\n", color=:red)
522+
printstyled(stderr, "WARNING: could not find generic zero for given elements. expect errors and wrong results\n", color=:red)
522523
end
523524

524525
for row in axes(S,1)
@@ -531,7 +532,9 @@ function _show_with_dotted_zeros(io::IO, S::AbstractSparseMatrixCSCInclAdjointAn
531532
print(io, " "^l * "" * (col==axes(S,2)[end] ? "" : " "^r))
532533
else
533534
l, r = (l+1, r+1) .- align[index][]
534-
print(io, " "^l, vals[index][], (col==axes(S,2)[end] ? "" : " "^r))
535+
print(io, " "^l)
536+
show(io, isassigned(vals, index[]) ? vals[index][] : "#undef")
537+
col == axes(S,2)[end] || print(io, " "^r)
535538
end
536539
end
537540
row == axes(S,1)[end] || println(io)
@@ -1954,9 +1957,9 @@ julia> A = sparse([1, 2, 3], [1, 2, 3], [1.0, 0.0, 1.0])
19541957
19551958
julia> dropzeros(A)
19561959
3×3 SparseMatrixCSC{Float64, Int64} with 2 stored entries:
1957-
1.0
1958-
1959-
1.0
1960+
1.0
1961+
1962+
1.0
19601963
```
19611964
"""
19621965
dropzeros(A::AbstractSparseMatrixCSC) = dropzeros!(copy(A))
@@ -2126,7 +2129,7 @@ argument specifies a random number generator, see [Random Numbers](@ref).
21262129
```jldoctest; setup = :(using Random; Random.seed!(0))
21272130
julia> sprandn(2, 2, 0.75)
21282131
2×2 SparseMatrixCSC{Float64, Int64} with 3 stored entries:
2129-
-1.20577 ⋅
2132+
-1.20577
21302133
0.311817 -0.234641
21312134
```
21322135
"""
@@ -2153,9 +2156,9 @@ specified.
21532156
```jldoctest
21542157
julia> spzeros(3, 3)
21552158
3×3 SparseMatrixCSC{Float64, Int64} with 0 stored entries:
2156-
2157-
2158-
2159+
2160+
2161+
21592162
21602163
julia> spzeros(Float32, 4)
21612164
4-element SparseVector{Float32, Int64} with 0 stored entries

test/issues.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,14 +758,14 @@ let
758758
B = similar(A, T12960)
759759
@test repr(B) == "sparse([1, 2, 3], [1, 2, 3], $T12960[#undef, #undef, #undef], 3, 3)"
760760
@test occursin(
761-
"\n #undef \n #undef \n #undef",
761+
" #undef ⋅ \n ⋅ #undef \n #undef",
762762
repr(MIME("text/plain"), B),
763763
)
764764

765765
B[1,2] = T12960()
766766
@test repr(B) == "sparse([1, 1, 2, 3], [1, 2, 2, 3], $T12960[#undef, $T12960(), #undef, #undef], 3, 3)"
767767
@test occursin(
768-
"\n #undef T12960() \n #undef \n #undef",
768+
"\n #undef T12960() \n ⋅ #undef \n #undef",
769769
repr(MIME("text/plain"), B),
770770
)
771771
end
@@ -805,6 +805,15 @@ end
805805
7 16 4])
806806
end
807807

808+
@testset "Issue #512" begin # suppresses but does not fix the error mentioned
809+
x = sparse([1, 1, 3], [1, 4, 3], [20, 0, [2]])
810+
@test_warn "WARNING: could not find generic zero" repr(MIME("text/plain"), x)
811+
x = sparse([1, 100, 3], [1, 4, 300], [20, 0, [2]])
812+
@test_warn "WARNING: could not find generic zero" repr(MIME("text/plain"), x)
813+
814+
@test_broken repr(MIME("text/plain"), transpose(x'))
815+
end
816+
808817
@testset "Issue #574" begin
809818
a = spzeros(Float32, Int16, 2, 3)
810819
v = spzeros(Float32, Int16, 2)

test/sparsematrix_constructors_indexing.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,9 +1514,9 @@ end
15141514
A = spzeros(Float32, Int64, 2, 2)
15151515
for (transform, showstring) in zip(
15161516
(identity, adjoint, transpose), (
1517-
"2×2 $SparseMatrixCSC{Float32, Int64} with 0 stored entries:\n \n ",
1518-
"2×2 $Adjoint{Float32, $SparseMatrixCSC{Float32, Int64}} with 0 stored entries:\n \n ",
1519-
"2×2 $Transpose{Float32, $SparseMatrixCSC{Float32, Int64}} with 0 stored entries:\n \n ",
1517+
"2×2 $SparseMatrixCSC{Float32, Int64} with 0 stored entries:\n\n",
1518+
"2×2 $Adjoint{Float32, $SparseMatrixCSC{Float32, Int64}} with 0 stored entries:\n\n",
1519+
"2×2 $Transpose{Float32, $SparseMatrixCSC{Float32, Int64}} with 0 stored entries:\n\n",
15201520
))
15211521
show(io, MIME"text/plain"(), transform(A))
15221522
@test String(take!(io)) == showstring

0 commit comments

Comments
 (0)