Skip to content
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

wrap bessel functions from libamos #363

Closed
JeffBezanson opened this issue Feb 11, 2012 · 2 comments
Closed

wrap bessel functions from libamos #363

JeffBezanson opened this issue Feb 11, 2012 · 2 comments
Labels
status:help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@JeffBezanson
Copy link
Sponsor Member

The code in external/amos provides bessel functions of complex arguments, which can be exposed using code similar to that for airy in j/math_libm.j.

@nolta
Copy link
Member

nolta commented Feb 19, 2012

Hope you don't mind, i thought i'd take a crack at this. The following snippet implements besselj(nu,z) and appears to work -- spot checks agree with matlab & mathematica.

let
    const cy::Array{Float64,1} = Array(Float64,2)
    const ae::Array{Int32,1} = Array(Int32,2)
    const wrk::Array{Float64,1} = Array(Float64,2)

    function _besselj(nu::Float64, z::Complex128)
        ccall(dlsym(_jl_libamos, :zbesj_), Void,
              (Ptr{Float64}, Ptr{Float64}, Ptr{Float64}, Ptr{Int32}, Ptr{Int32},
               Ptr{Float64}, Ptr{Float64}, Ptr{Int32}, Ptr{Int32}),
              real(z), imag(z), nu, int32(1), int32(1),
              pointer(cy,1), pointer(cy,2),
              pointer(ae,1), pointer(ae,2))
        return complex(cy[1],cy[2])
    end

    function _bessely(nu::Float64, z::Complex128)
        ccall(dlsym(_jl_libamos, :zbesy_), Void,
              (Ptr{Float64}, Ptr{Float64}, Ptr{Float64}, Ptr{Int32},
               Ptr{Int32}, Ptr{Float64}, Ptr{Float64}, Ptr{Int32},
               Ptr{Float64}, Ptr{Float64}, Ptr{Int32}),
              real(z), imag(z), nu, int32(1), int32(1),
              pointer(cy,1), pointer(cy,2),
              pointer(ae,1), pointer(wrk,1),
              pointer(wrk,2), pointer(ae,2))
        return complex(cy[1],cy[2])
    end

    global besselj
    function besselj(nu::Float64, z::Complex128)
        if nu < 0
            return _besselj(-nu,z)cos(pi*nu) + _bessely(-nu,z)sin(pi*nu)
        else
            return _besselj(nu, z)
        end
    end

    function besselj(nu::Int, x::Float)
        if x == 0
            return (nu == 0) ? one(x) : zero(x)
        end
        if nu < 0
            nu = -nu
            x = -x
        end
        ans = _besselj(float64(nu), complex128(abs(x)))
        if (x < 0) && (nu % 2 == 1)
            ans = -ans
        end
        oftype(x, real(ans))
    end
end

function besselj(nu::Float, x::Float)
    ans = besselj(float64(nu), complex128(x))
    (x > 0) ? oftype(x, real(ans)) : ans
end

besselj(nu::Real, z::Complex64) = complex64(besselj(float64(nu), complex128(z)))
besselj(nu::Int, x::Real) = besselj(nu, float(x))
besselj(nu::Real, x::Real) = besselj(float(nu), float(x))

@JeffBezanson
Copy link
Sponsor Member Author

I sure don't mind; that's what the "up for grabs" tag is for :)

Looks great, thanks! Best thing is to commit this in a fork and make a pull request for it, then I will merge it in.

StefanKarpinski pushed a commit that referenced this issue Feb 8, 2018
cmcaine pushed a commit to cmcaine/julia that referenced this issue Nov 11, 2022
* CI: Respect version requirement of exercises

* Add artifact caching
Keno pushed a commit that referenced this issue Oct 9, 2023
Our optimization to pull out any internal calls causes
problems when a structure hasn't yet been defined.
Fixes timholy/Revise.jl#417
Keno pushed a commit that referenced this issue Oct 9, 2023
PR #363 broke certain types of structure definition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants