Hi Brendan,
It looks like you’re hitting Julia’s invariance for the first time:
http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)
If you’re working with inputs to a function, you can do the typecheck using a
type parameter, T:
function foo{T <: FloatingPoint}(x::Vector{T})
...
end
— John
On Aug 15, 2014, at 6:50 PM, Brendan O'Connor <[email protected]> wrote:
> Hi,
>
> What's the best way to typecheck that an array is of floats, but any
> precision is OK? I've found it useful to do this because a number of
> operations fail when given integer vector inputs (for example, 10.^[-3:3]).
>
> I noticed that
>
> x::Vector{FloatingPoint}
>
> does not seem to cover them. I ended up doing
>
> FloatVec = Union(Vector{Float32}, Vector{Float64})
>
> which seems slightly ugly given that I'd like that type in many different
> places. Is there a better way?
>
> Thanks, Brendan
>