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

Interpolation not type stable? #48

Open
BeastyBlacksmith opened this issue Feb 19, 2018 · 4 comments
Open

Interpolation not type stable? #48

BeastyBlacksmith opened this issue Feb 19, 2018 · 4 comments

Comments

@BeastyBlacksmith
Copy link

@code_warntype spline( 0.5 )

yields Any for the return type, when I tried this today.
Is it me or is it type unstable?

@kbarbary
Copy link
Collaborator

I don't see this for Spline1D. What kind of spline are you using?

@BeastyBlacksmith
Copy link
Author

ParametricSpline

@xanfus
Copy link

xanfus commented Nov 5, 2019

using Dierckx

julia> spline = Spline1D([1,2],[1,2],k=1)
Spline1D(knots=[1.0, 2.0], k=1, extrapolation="nearest", residual=0.0)

julia> @code_warntype 1.0*spline(1.0)
Variables
  #self#::Core.Compiler.Const(*, false)
  x::Float64
  y::Float64

Body::Float64
1 \u2500 %1 = Base.mul_float(x, y)::Float64
\u2514\u2500\u2500      return %1

julia> f(x) = 1.0*spline(x)
f (generic function with 1 method)

julia> @code_warntype f(1.0)
Variables
  #self#::Core.Compiler.Const(f, false)
  x::Float64

Body::Any
1 \u2500 %1 = Main.spline(x)::Any
\u2502   %2 = (1.0 * %1)::Any
\u2514\u2500\u2500      return %2

@xanfus
Copy link

xanfus commented Nov 5, 2019

Spline has to be defined right in scope of function, which calls the spline. Access to dataframe (S0) by index isn't type-stable, so that leaf-type arrays have to be sent to input of Spline1D.

begin
    S0 = CSV.read("S0.csv",header=false)#Rn222
    S0x = S0[:,2];S0zzi = S0[:,1];
    # S0sp = Spline1D(S0x,S0zzi,k=1)
    # FetchActivity(zzi) = 4.0*S0sp(zzi)
    function FetchActivity(zzi)
        # Dierckx.evaluate(S0sp,zzi)
        S0sp = Spline1D(S0x,S0zzi,k=1)
        # S0sp = Spline1D(S0[:,2],S0[:,1],k=1)
        # x = S0sp(zzi)
        return 4*S0sp(zzi)
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants