Skip to content

ndims not defined in local scope #28

@dannys4

Description

@dannys4

This line assumes the definition of ndims, which is not necessarily defined at such a point. This came about because I tried approximating a function that has different bounds on the input space for each dimension, but want to use Doubling for all the dimensions.

Minimum reproducible example:

using SparseGridsKit, LinearAlgebra
function borehole_fcn(x)
	r_w, r, T_u, H_u, T_l, H_l, L, K_w = x
	logrrw = log(r/r_w)
	denom = logrrw*(1.5+ (2L*T_u)/(logrrw*r_w*r_w*K_w) + T_u/T_l)
	num = 2pi*T_u*(H_u - H_l)
	num/denom
end
borehole_bounds = NTuple{2,Float64}[
	(0.05, 0.15), (100, 50_000), (63_070, 115_600), (990, 1_110),
	(63.1, 116), (700, 820), (1_120, 1_680), (9_855, 12_045)
]
n = length(borehole_bounds)
knots = [CCPoints([b...]) for b in borehole_bounds]
(asg, f_on_asg) = adaptive_sparsegrid(borehole_fcn, n; knots)

Error:

ERROR: UndefVarError: `ndims` not defined in local scope
Suggestion: check for an assignment to a local variable that shadows a global of the same name.
Hint: a global variable of this name also exists in Base.
Stacktrace:
 [1] sparsegridprecompute(maxmi::Int64, knots::Vector{CCPoints{Float64}}, rule::Doubling)
   @ SparseGridsKit ~/.julia/dev/SparseGridsKit/src/sparsegrids.jl:100
 [2] precompute_lagrange_integrals(max_mi::Int64, knots::Vector{CCPoints{Float64}}, rule::Doubling)
   @ SparseGridsKit ~/.julia/dev/SparseGridsKit/src/SparseGridsKit.jl:51
 [3] adaptive_sparsegrid(f::typeof(borehole_fcn), ndims::Int64; maxpts::Int64, proftol::Float64, rule::Doubling, knots::Vector{…}, θ::Float64, type::Symbol, costfunction::Nothing)
   @ SparseGridsKit ~/.julia/dev/SparseGridsKit/src/adaptivesparsegrids.jl:31
 [4] top-level scope
   @ Untitled-2:31

Using Julia 1.11.5. Edited because I forgot to include definition of n.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions