Skip to content

Commit

Permalink
Sorting should throw is a comparison is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Jul 10, 2023
1 parent 9be3ba2 commit 81d2618
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Base: size, getindex, setindex!, IndexStyle, checkbounds, convert,
any, all, axes, isone, iterate, unique, allunique, permutedims, inv,
copy, vec, setindex!, count, ==, reshape, _throw_dmrs, map, zero,
show, view, in, mapreduce, one, reverse, promote_op, promote_rule, repeat,
parent
parent, issorted

import LinearAlgebra: rank, svdvals!, tril, triu, tril!, triu!, diag, transpose, adjoint, fill!,
dot, norm2, norm1, normInf, normMinusInf, normp, lmul!, rmul!, diagzero, AdjointAbsVec, TransposeAbsVec,
Expand Down Expand Up @@ -237,8 +237,22 @@ Base.@propagate_inbounds getindex(A::AbstractFill, kr::AbstractArray{Bool}) = _f
v, (v, n+1)
end

sort(a::AbstractFill; kwds...) = a
sort!(a::AbstractFill; kwds...) = a
#################
# Sorting
#################
function issorted(f::AbstractFill; kw...)
v = getindex_value(f)
issorted((v, v); kw...)
end
function sort(a::AbstractFill; kwds...)
issorted(a; kwds...) # ensure that the values may be compared
return a
end
function sort!(a::AbstractFill; kwds...)
issorted(a; kwds...) # ensure that the values may be compared
return a
end

svdvals!(a::AbstractFillMatrix) = [getindex_value(a)*sqrt(prod(size(a))); Zeros(min(size(a)...)-1)]

function fill_reshape(parent, dims::Integer...)
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,10 @@ end
@test svdvals(fill(2,5,6)) svdvals(Fill(2,5,6))
@test svdvals(Eye(5)) === Fill(1.0,5)
@test sort(Ones(5)) == sort!(Ones(5))

@test_throws MethodError issorted(Fill(im, 2))
@test_throws MethodError sort(Fill(im, 2))
@test_throws MethodError sort!(Fill(im, 2))
end

@testset "Cumsum and diff" begin
Expand Down Expand Up @@ -777,6 +781,8 @@ end
@test (@inferred Base.IteratorSize(Fill(2, (r, 1:2)))) == Base.IsInfinite()
@test (@inferred Base.IteratorSize(Fill(2, (r, r)))) == Base.IsInfinite()
end

@test issorted(Fill(2, (InfiniteArrays.OneToInf(),)))
end
end

Expand Down

0 comments on commit 81d2618

Please sign in to comment.