diff --git a/src/grid_discretized.jl b/src/grid_discretized.jl index 9fbea66..86a0074 100644 --- a/src/grid_discretized.jl +++ b/src/grid_discretized.jl @@ -94,8 +94,8 @@ struct DiscretizedGrid{D} <: Grid{D} function DiscretizedGrid{D}( Rs, lower_bound, upper_bound, variablenames, base, indextable, includeendpoint ) where {D} - lower_bound = _to_tuple(Val(D), lower_bound) - upper_bound = _to_tuple(Val(D), upper_bound) + lower_bound = _to_float_tuple(Val(D), lower_bound) + upper_bound = _to_float_tuple(Val(D), upper_bound) base = _to_tuple(Val(D), base) includeendpoint = _to_tuple(Val(D), includeendpoint) for d in 1:D @@ -119,14 +119,23 @@ end # ============================================================================ function _check_bounds_dim(::Val{D}, lower_bound, upper_bound) where {D} - if lower_bound isa NTuple && length(lower_bound) != D + if lower_bound isa Tuple && length(lower_bound) != D throw(ArgumentError(lazy"Got lower_bound with length $(length(lower_bound)); expected $D for DiscretizedGrid{$D}.")) end - if upper_bound isa NTuple && length(upper_bound) != D + if upper_bound isa Tuple && length(upper_bound) != D throw(ArgumentError(lazy"Got upper_bound with length $(length(upper_bound)); expected $D for DiscretizedGrid{$D}.")) end end +function _to_float_tuple(::Val{D}, x::Tuple) where {D} + if length(x) != D + throw(ArgumentError(lazy"Got tuple with length $(length(x)); expected $D.")) + end + return ntuple(d -> Float64(x[d]), D) +end + +_to_float_tuple(::Val{D}, x) where {D} = ntuple(_ -> Float64(x), D) + function _adjust_upper_bounds(upper_bound, lower_bound, includeendpoint, base, Rs, ::Val{D}) where D base = _to_tuple(Val(D), base) includeendpoint = _to_tuple(Val(D), includeendpoint) diff --git a/test/discretizedgrid_misc_tests.jl b/test/discretizedgrid_misc_tests.jl index e7c1986..9ed1c83 100644 --- a/test/discretizedgrid_misc_tests.jl +++ b/test/discretizedgrid_misc_tests.jl @@ -52,6 +52,15 @@ end @test_throws ArgumentError DiscretizedGrid{2}(3, (0.0, 1.0), (1.0,)) end +@testitem "DiscretizedGrid mixed-type bounds" begin + R = 10 + N = 2^R + g = DiscretizedGrid{2}((R, R), (0.0, 0), (2.0, N - 1); includeendpoint=(false, true)) + + @test QuanticsGrids.lower_bound(g) == (0.0, 0.0) + @test QuanticsGrids.grid_max(g)[2] ≈ N - 1 +end + @testitem "DiscretizedGrid 0-dimensional show method" begin g = DiscretizedGrid(()) @test try