Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Heptazhou committed Nov 26, 2024
1 parent 06bc63e commit 1c7ccd3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const extra = Vector{Module}()
const links = InterLinks(
"Julia" => cache("https://docs.julialang.org/en/v1/"),
"OrderedCollections" => cache("https://juliacollections.github.io/OrderedCollections.jl/dev/"),
#? wait for OrderedCollections v1.6.4+
)

cd(@__DIR__) do
Expand Down
37 changes: 17 additions & 20 deletions src/BaseExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@ See [`Base.$($T)`](@extref).
""" $T
end

function Base.adjoint(m::T) where T <: AbstractVecOrMat{Any}
permutedims(m)::AbstractMatrix{Any}
end
function Base.adjoint(m::T) where T <: AbstractVecOrMat{<:Symbol}
permutedims(m)::AbstractMatrix{<:Symbol}
end
function Base.adjoint(m::T) where T <: AbstractVecOrMat{<:AbstractChar}
permutedims(m)::AbstractMatrix{<:AbstractChar}
end
function Base.adjoint(m::T) where T <: AbstractVecOrMat{<:AbstractString}
permutedims(m)::AbstractMatrix{<:AbstractString}
let VM = AbstractVecOrMat, M = AbstractMatrix
#! format: noindent
@inline Base.adjoint(m::VM{Any}) = permutedims(m)::M{Any}
@inline Base.adjoint(m::VM{Regex}) = permutedims(m)::M{Regex}
@inline Base.adjoint(m::VM{Symbol}) = permutedims(m)::M{Symbol}
@inline Base.adjoint(m::VM{T}) where T <: AbstractChar = permutedims(m)::M{T}
@inline Base.adjoint(m::VM{T}) where T <: AbstractString = permutedims(m)::M{T}
end

function Base.collect(f::Function, collection)
Expand All @@ -59,26 +55,27 @@ function Base.convert(::Type{S}, v::AbstractVector) where S <: AbstractSet{T} wh
S(T[v;])
end

let UU = Union{Union, UnionAll}
let UT = Union{Union, DataType}, UA = UnionAll,
UU = Union{Union, UA}, TT = NTuple{2, Type}
#! format: noindent
@inline rewrap(r::Type, ::UU) = r
@inline unwrap(r::Union) = r
@inline rewrap(T::DataType, U::UnionAll) = rewrap_unionall(T, U)::UnionAll
@inline unwrap(T::UnionAll) = unwrap_unionall(T)::Union{Union, DataType}
@inline rewrap(r::Type, ::UU) = r
@inline rewrap(T::DataType, U::UA)::UA = rewrap_unionall(T, U)
@inline unwrap(r::Union) = r
@inline unwrap(T::UA)::UT = unwrap_unionall(T)

@inline Base.iterate(::TypeofBottom) = nothing
@inline Base.iterate(::UnionAll, ::DataType) = nothing
@inline Base.iterate(::UA, ::DataType) = nothing
@inline Base.iterate(::UU, ::TypeofBottom) = nothing
@inline Base.iterate(::UU, T::Type) = T, Bottom
@inline Base.iterate(T::DataType, i::Int = 1) = iterate(T.parameters, i)
@inline Base.iterate(T::UU) = iterate(T, unwrap(T))
@inline Base.iterate(U::UU, T::Union) = rewrap(T.a, U), rewrap(T.b, U)
@inline Base.iterate(T::UU) = iterate(T, unwrap(T)::UT)
@inline Base.iterate(U::UU, T::Union)::TT = rewrap(T.a, U), rewrap(T.b, U)
end

@inline Base.length(T::DataType) = length(T.parameters)

"""
log10(x::T, σ::T) -> NTuple{2, AbstractFloat} where T <: Real
log10(x::T, σ::T) where T <: Real -> NTuple{2, AbstractFloat}
Compute the logarithm of `x ± σ` to base 10.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/Function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function ext(x::Symbol)::Maybe{Module}
end

"""
invsqrt(x::T) -> AbstractFloat where T <: Real
invsqrt(x::T) where T <: Real -> AbstractFloat
Return ``\\sqrt{x^{-1}}``.
Expand Down
14 changes: 13 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ end
end

@testset "Base" begin
using Base: unwrap_unionall
ms = methods(ntuple, (Int, Any), (Base))
ts = [unwrap_unionall(m.sig) for m ms]
v1 = ["$(t.parameters[(3)])" for t ts]
v2 = ["$Int", "Integer", "Val{N}", ("Val{$N}" for N 0:3)...]
@test v1 v2

@static if !Sys.iswindows()
#! format: noindent
@test Bool(0) == Base.isdir("")
Expand Down Expand Up @@ -162,9 +169,13 @@ end
@test_throws MethodError collect(Tuple{})
@test_throws MethodError convert(Set, 1:3)
@test_throws MethodError convert(Set{Int}, 1:3)
@test_throws MethodError display([:_, -1]')
@test_throws MethodError display([:p, :q]')
@test_throws MethodError display(['1', '2']')
@test_throws MethodError display(["x", "y"]')
@test_throws MethodError display([(r"^"), (r"$")]')
@test_throws MethodError log10(11, 2)
@test_throws MethodError ntuple(2, 1)
@test_throws MethodError repr([:a, 1]')
a_unionall = Union{Vector{T}, Matrix{T}, Array{T, 3}} where T
a2_missing = Array{Missing, 2}(undef, Tuple(rand(0:9, 2)))
a3_nothing = Array{Nothing, 3}(undef, Tuple(rand(0:9, 3)))
Expand All @@ -178,6 +189,7 @@ end
@test [:p :q] == [:p, :q]'
@test ['1' '2'] == ['1', '2']'
@test ["x" "y"] == ["x", "y"]'
@test [(r"^") (r"$")] == [(r"^"), (r"$")]'
@test [a_unionall::UnionAll...] == UnionAll[Vector, Matrix, Array{T, 3} where T]
@test [AbstractMatrix...] == [Vector...] == []
@test [AbstractMatrix{UInt8}...] == [UInt8, 2]
Expand Down

0 comments on commit 1c7ccd3

Please sign in to comment.