QuantEcon / ContinuousDPs.jl

Continuous state dynamic programming
BSD 3-Clause "New" or "Revised" License
13 stars 10 forks source link

`Interp` with `Range` #19

Closed oyamad closed 6 years ago

oyamad commented 6 years ago

Constructor of Interp does not work when nodes returns Range, which is the case when basis is generated from LinParams(n::Int64, a::Real, b::Real).

n, a, b = 10, 0, 1
basis = Basis(LinParams(n, a, b))
ContinuousDPs.Interp(basis)
MethodError: no method matching ContinuousDPs.Interp(::BasisMatrices.Basis{1,Tuple{BasisMatrices.LinParams{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}}}, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::Int64, ::Tuple{Int64}, ::Tuple{Float64}, ::Tuple{Float64}, ::SparseMatrixCSC{Float64,Int64}, ::Base.SparseArrays.UMFPACK.UmfpackLU{Float64,Int64})
Closest candidates are:
  ContinuousDPs.Interp(::BasisMatrices.Basis{N,TP} where TP<:Tuple, ::TS<:(Union{Array{T,1}, Array{T,2}} where T), ::Tuple{Vararg{Array{Float64,1},N}}, ::Int64, ::Tuple{Vararg{Int64,N}}, ::Tuple{Vararg{Float64,N}}, ::Tuple{Vararg{Float64,N}}, ::TM<:(AbstractArray{T,2} where T), ::TL<:Factorization) where {N, TS<:(Union{Array{T,1}, Array{T,2}} where T), TM<:(AbstractArray{T,2} where T), TL<:Factorization} at /Users/oyama/.julia/v0.6/ContinuousDPs/src/cdp.jl:20
  ContinuousDPs.Interp(::BasisMatrices.Basis) at /Users/oyama/.julia/v0.6/ContinuousDPs/src/cdp.jl:32
typeof(LinParams(n, a, b))
BasisMatrices.LinParams{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}

Should we extend S::TS and Scoord::NTuple{N,Vector{Float64}} to allow Range, or add an additional constructor which converts the outputs of nodes?

sglyon commented 6 years ago

I actually think this should be fixed on the BasisMatrices side.

It turns out that indexing into small (<100 elements) arrays is faster than the equivalent Range like object, so I think LinParams is leaving some performance on the table by sticking to a range.

oyamad commented 6 years ago

That would be helpful. (It will be simplest if nodes always returns the same type.)

sglyon commented 6 years ago

Fixed on BasisMatrices master