From 4726463f1433aebbd344f0a8d9675d7a0669ec5e Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 7 Oct 2017 20:52:51 -0700 Subject: [PATCH] first attempt at callable type support --- src/series.jl | 18 ++++++++++++++++-- test/runtests.jl | 7 +++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/series.jl b/src/series.jl index c0d7d4c2..d0cd3f84 100644 --- a/src/series.jl +++ b/src/series.jl @@ -11,7 +11,21 @@ const FuncOrFuncs{F} = Union{F, Vector{F}, Matrix{F}} all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image), get(d, :seriestype, :none)) # unknown -convertToAnyVector(x, d::KW) = error("No user recipe defined for $(typeof(x))") +# in this case, check if it's actually a callable type and use as a function +# otherwise it's unsupported and throw an error. +function convertToAnyVector(x, d::KW) + try + x(0.0) + catch + try + x(0.0,0.0) + catch + error("No user recipe defined for $(typeof(x))") + end + end + @show "here!" + Any[(v...)->x(v...)] +end # missing convertToAnyVector(v::Void, d::KW) = Any[nothing], nothing @@ -371,7 +385,7 @@ end end # try some intervals over which the function may be defined -function tryrange(F::AbstractArray, vec) +function tryrange(F::AbstractArray, vec) rets = [tryrange(f, vec) for f in F] # get the preferred for each maxind = maximum(indexin(rets, vec)) # get the last attempt that succeeded (most likely to fit all) rets .= [tryrange(f, vec[maxind:maxind]) for f in F] # ensure that all functions compute there diff --git a/test/runtests.jl b/test/runtests.jl index 4f0b2ad0..68c56ced 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -133,6 +133,13 @@ end histogram([1, 0, 0, 0, 0, 0]) end +@testset "Callable Functions" begin + struct MyFun end + (::MyFun)(x) = sin(x) + A = MyFun() + plot(A, -pi, pi, markershape = :circle) +end + # tests for preprocessing recipes # @testset "recipes" begin