Code Monkey home page Code Monkey logo

Comments (7)

waldyrious avatar waldyrious commented on June 18, 2024
julia> sintau(convert(Int,1.0)) === zero(Int)
true

julia> sintau(convert(Float64,1.0)) === zero(Float64)
true

julia> sintau(convert(Complex,1.0)) === zero(Complex)
false

from tau.jl.

waldyrious avatar waldyrious commented on June 18, 2024

Note: this may be helped by JuliaLang/julia#20268

from tau.jl.

giordano avatar giordano commented on June 18, 2024

I don't think this is an issue:

julia> show(Base.return_types(sintau, Tuple{Complex{Float64}}))
Any[Complex{Float64}]

In addition, in PR #19 I used @inferred in new tests, that takes care of testing type stability of the result.

from tau.jl.

waldyrious avatar waldyrious commented on June 18, 2024

Before going further, I'd like to make sure you're aware of the context of my role in this package. I am currently maintaining it due to my interest in both Julia and tau, and the original author's lack of availability to maintain the package. However, my experience programming Julia is rather superficial, so I probably won't be able to communicate with you via code snippets alone :) -- and I'll likely ask some silly questions, so bear with me.

With that said, I must say I don't completely follow what you mean with your comment above. I'd appreciate if you could expand a bit.

from tau.jl.

giordano avatar giordano commented on June 18, 2024

Ok, don't worry ;-)

I don't know exactly what Base.return_types is supposed to do, it isn't documented, I can only guess based on its name. I simply showed that using Complex{Float64} as input type (that is, a Complex object with the parameter explicitly specified), the test is fine (and I added such test at https://github.com/JuliaMath/Tau.jl/pull/19/files#diff-fce720c43af3c52c862fd7451c7374b8R53). Instead, you were using Complex without specifying the parameter, that is the collection of all Complex types, and you can't infer a single returned type for all these input types.

In addition, in the same PR I used everywhere @inferred, which is very useful to test type stability of the given expression. If the function wrapped by @inferred isn't type-stable, an error is raised.

In the end, I believe this issue can be closed, as it isn't an issue at all ;-)

from tau.jl.

waldyrious avatar waldyrious commented on June 18, 2024

Thanks for the details! I had never really studied how Complex works at sufficient detail, which caused my confusion. I assumed it was a straightforward concrete type like Int, while indeed it is more of a container type (like an array of numbers, I suppose).

To confirm that I got this right: the correct form of the Complex test in the second above would be

julia> sintau(convert(Complex,1.0)) === zero(Complex{Float64})
true

right?

In any case, yes, let's close this.

from tau.jl.

giordano avatar giordano commented on June 18, 2024

Exact! Indeed

julia> zero(Complex)
0 + 0im

julia> typeof(ans)
Complex{Int64}

julia> sintau(one(Complex))
0.0 + 0.0im

julia> typeof(ans)
Complex{Float64}

Thus, sintau(one(Complex)) and zero(Complex) have different types, and === (which tests perfect equality) necessarily returns false.

from tau.jl.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.