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

BUG: funeval returns a 0 dimensional array when BasisStructure has single point #16

Open
sglyon opened this issue Oct 25, 2016 · 2 comments

Comments

@sglyon
Copy link
Member

sglyon commented Oct 25, 2016

Issue by spencerlyon2
Friday Jul 31, 2015 at 02:16 GMT
Originally opened as QuantEcon/CompEcon.jl#10


Test case:

using CompEcon
basis = Basis(ChebParams(10, -1, 1), ChebParams(5, 2, 4));
grid = nodes(basis)[1];
y = grid[:, 1] - grid[:, 2];  # simple function x - y
c = funfitxy(basis, grid, y)[1];
pt = [0.5, 2.1];
bs = BasisStructure(basis, Direct(), pt);
funeval(c, bs)

REPL example:

julia> using CompEcon

julia> basis = Basis(ChebParams(10, -1, 1), ChebParams(5, 2, 4));


julia> grid = nodes(basis)[1];

julia> y = grid[:, 1] - grid[:, 2];  # simple function x - y

julia> c = funfitxy(basis, grid, y)[1];

julia> pt = [0.5, 2.1];

julia> bs = BasisStructure(basis, Direct(), pt);

julia> funeval(c, bs)
0-dimensional Array{Float64,0}:
-1.6
@sglyon
Copy link
Member Author

sglyon commented Oct 25, 2016

Comment by spencerlyon2
Friday Jul 31, 2015 at 02:19 GMT


Could be fixed by changing

function squeeze_trail(x::Array)
    sz = size(x)
    squeezers = Int[]
    n = length(sz)
    for i=n:-1:1
        if sz[i] == 1
            push!(squeezers, i)
        else
            break
        end
    end
    squeeze(x, tuple(squeezers...))
end

to

function squeeze_trail(x::Array)
    sz = size(x)
    squeezers = Int[]
    n = length(sz)
    for i=n:-1:1
        if sz[i] == 1
            push!(squeezers, i)
        else
            break
        end
    end
    out = squeeze(x, tuple(squeezers...))
    length(out) == 1 ? out[1] : out
end

but I think with some design work we can do a better job at finding a type-stable version of funeval (because as of right now it is very type unstable...)

@sglyon
Copy link
Member Author

sglyon commented Oct 25, 2016

Comment by spencerlyon2
Friday Jul 31, 2015 at 02:21 GMT


See type instability by continuing previous example and doing @code_warntype funeval(c, bs, fill(0, 1, 1)) (if you are on julia 0.4dev)

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

1 participant