-
Notifications
You must be signed in to change notification settings - Fork 9
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
Stop using Base.@irrational
#18
Comments
I'm well aware of this issue (see, e.g., #12 (comment) and TuringLang/MCMCDiagnosticTools.jl#63 (comment)). The main/only point of this package is that already existing definitions of irrationals, floating around in the ecosystem, are defined in a common package so it's a lightweight dependency and thereby makes it less likely that two packages define the same constants. Most constants have been defined in StatsFuns for a long time before this package was created and have been used in particular in different stats packages; IIRC then at some point someone wanted to use them in SpecialFunctions which does not want to add a dependency on StatsFuns (and StatsFuns even depends on SpecialFunctions). Of course, it's only the second best solution but I think it's definitely better than every package trying to redefine irrational constants. |
I see. Sorry for bothering you. There's one more thing I'd like to ask you about. Is there any problems if we define the constants with |
Yes, I assume the way to fix this are custom types that are not owned by base, as suggested in JuliaLang/julia#46531 (comment). I'm not sure how many methods in base are defined for |
But at least a quick search does not reveal anything: https://github.com/JuliaLang/julia/search?p=1&q=Irrational |
I have not checked all of the code, but it seems we need to define these methods at least. show(io::IO, x::IrrationalConstant{sym}) where {sym} = print(io, sym)
function show(io::IO, ::MIME"text/plain", x::IrrationalConstant{sym}) where {sym}
if get(io, :compact, false)::Bool
print(io, sym)
else
print(io, sym, " = ", string(float(x))[1:min(end,15)], "...")
end
end
==(::IrrationalConstant{s}, ::IrrationalConstant{s}) where {s} = true
<(::IrrationalConstant{s}, ::IrrationalConstant{s}) where {s} = false
<=(::IrrationalConstant{s}, ::IrrationalConstant{s}) where {s} = true
hash(x::IrrationalConstant, h::UInt) = 3*objectid(x) - h # I'm not much familiar with `hash`. just copied from Base. |
I think that we would want to avoid the design of If you don't beat me to it, I might have time to look into it later this evening. |
Fixed by #19, will be released as IrrationalConstants 0.2. |
This macro should not be used outside of
Base
. See JuliaLang/julia#47103 and JuliaLang/julia#46531.The text was updated successfully, but these errors were encountered: