Skip to content

Use Base.real instead of defining real in the package #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ApproxFunBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import Base: values, convert, getindex, setindex!, *, +, -, ==, <, <=, >, |, !,
getproperty, findfirst, unsafe_getindex, fld, div,
eachindex, firstindex, lastindex, isreal,
OneTo, Array, Vector, Matrix, view, ones, @propagate_inbounds,
print_array, split, iszero, permutedims, rad2deg, deg2rad, checkbounds
print_array, split, iszero, permutedims, rad2deg, deg2rad, checkbounds,
real, float

import Base.Broadcast: BroadcastStyle, Broadcasted, AbstractArrayStyle,
broadcastable, DefaultArrayStyle, broadcasted
Expand Down
18 changes: 4 additions & 14 deletions src/LinearAlgebra/helper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,13 @@ isapproxinteger(::Integer) = true
isapproxinteger(x) = isinteger(x) || isapprox(x,round(Int,x)) || isapprox(x+1,round(Int,x+1))


# This creates ApproxFunBase.real, ApproxFunBase.eps and ApproxFunBase.dou
# which we override for default julia types
real(x...) = Base.real(x...)
real(x::UnsetNumber) = x
real(::Type{UnsetNumber}) = UnsetNumber
real(::Type{Array{T,n}}) where {T<:Real,n} = Array{T,n}
real(::Type{Array{T,n}}) where {T<:Complex,n} = Array{real(T),n}
real(::Type{SVector{N,T}}) where {N,T<:Real} = SVector{N,T}
real(::Type{SVector{N,T}}) where {N,T<:Complex} = SVector{N,real(T)}

float(x) = Base.float(x)
Base.float(::UnsetNumber) = UnsetNumber()
Base.float(::Type{UnsetNumber}) = UnsetNumber
float(::Type{Array{T,N}}) where {T,N} = Array{float(T),N}
float(::Type{SVector{N,T}}) where {T,N} = SVector{N,float(T)}


float(x::UnsetNumber) = x
float(::Type{UnsetNumber}) = UnsetNumber

# This creates ApproxFunBase.eps, which we override for default julia types
eps(x...) = Base.eps(x...)
eps(x) = Base.eps(x)

Expand Down
5 changes: 4 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ end
end

@testset "issue #94" begin
@test ApproxFunBase.real !== Base.real
@test_throws MethodError ApproxFunBase.real(1,2)
@test float(ApproxFunBase.UnsetNumber()) == ApproxFunBase.UnsetNumber()
@test float(ApproxFunBase.UnsetNumber) == ApproxFunBase.UnsetNumber
@test real(ApproxFunBase.UnsetNumber()) == ApproxFunBase.UnsetNumber()
@test real(ApproxFunBase.UnsetNumber) == ApproxFunBase.UnsetNumber
end

@testset "hasnumargs" begin
Expand Down