I’m trying to create an abstract type
that is a superclass (called Kernel
) several different of functions, each a subclass of Kernel
--i.e.
abstract type Kernel end
struct ExponentialKernel <: Kernel
ExponentialKernel(rate::Number, x::Number) = exp(-1*rate*x)
end
struct GaussianKernel <: Kernel
GaussianKernel(sigma::Number, x::Number) = (1.0/(sigma*sqrt(2*pi))) * exp((-1*x^2)/(2*sigma^2)
end
...
and so on.
When I use what I have above, it works in the sense that when I call ExpKernel(a,b)
I get the right value, but when I try to pass these kernel objects to a different constructor, like
mutable struct Model
kernel::T where {T <: Kernel}
Model(kernel) = new(kernel)
end
When I call Model(ExpKernel)
I get the error
ERROR: MethodError: Cannot `convert` an object of type Type{ExpKernel} to an object of type Kernel
Is there something I’m missing about types here?