Skip to content

Commit

Permalink
don't constrain return values for mapped function
Browse files Browse the repository at this point in the history
fixes #67
  • Loading branch information
j-fu committed Nov 4, 2024
1 parent 7e6f6fc commit 9008623
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ExtendableGrids"
uuid = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
authors = ["Juergen Fuhrmann <[email protected]>", "Christian Merdon <[email protected]>", "Johannes Taraz <[email protected]>"]
version = "1.10.3"
version = "1.10.4"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
8 changes: 1 addition & 7 deletions src/extendablegrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -488,16 +488,13 @@ function Base.map(f::Function, grid::ExtendableGrid{Tc, Ti}) where {Tc,Ti}
c1=coord[:,1]
dim = dim_space(grid)

## Check if f can be called with numeric args like f(x,y) and returns a number
## Check if f can be called with number args like f(x,y)
function checknumargs(f,args...)
if !hasmethod(f,Tuple(typeof.(args)))
return false
end
try
y=f(args...)
if !isa(y,Number)
return false
end
catch e
if isa(e,MethodError)
return false
Expand All @@ -517,9 +514,6 @@ function Base.map(f::Function, grid::ExtendableGrid{Tc, Ti}) where {Tc,Ti}
end
try
y=f(v)
if !isa(y,Number)
return false
end
catch e
if isa(e,MethodError)
return false
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ end
@test map(fx,gx)==map(fv,gx)
@test map(fxy,gxy)==map(fv,gxy)
@test map(fxyz,gxyz)==map(fv,gxyz)

vfx(x)=[x]
vfxy(x,y)=[x,y]
vfxyz(x,y,z)=[x,y,z]
vfv(v)=v
@test map(vfx,gx)==map(x->[vfv(x)],gx)
@test map(vfxy,gxy)==map(vfv,gxy)
@test map(vfxyz,gxyz)==map(vfv,gxyz)
end

function testrw(grid, format; confidence = :full, kwargs...)
Expand Down

0 comments on commit 9008623

Please sign in to comment.