One column arrays and vectors

I have a function that accepts your choice of one column arrays or vectors. Now I want to add a method and dispatch on one column arrays or vectors to get my original method. How do I create a type to let me do that?

This sorta works

KT=Union{Vector{T}, Array{T,2}} where T <: Real

but does not limit the array to a single column. I’m clearly missing something. Am I trying to do the impossible?

The size of an array is not known at compile time, so you can’t dispatch on it. You could just assert in your code that size(a, 2) == 1, or you can always convert matrices into an AbstractVector with vec, so you could just accept AbstractVector only. BTW, Base already defines what you’re defining, with the exception of accepting Any instead of Real as VecOrMat. So your definition would be equivalent to VecOrMat{<:Real}.


Fair enough. I was afraid of that.

You can only dispatch on number of axes with standard Array. You can dispatch on size with arrays from StaticArrays.jl