I don’t understand why a function like sort doesn’t accept dims=1 for a vector input. Let’s take b=rand(3) for instance. sort(b) works, but sort(b,dims=1) gives an error. It means that, in a case where size(b,2) is not fixed, I have to catch when size(b,2)==1 in order to compute sort(b) instead of sort(b,dims=1). Why doesn’t sort behave like that already?
Julia treats vectors as different than n x 1 matrices. For example,
julia> x = rand(4, 1) # 4 x 1 matrix
4×1 Matrix{Float64}:
0.5699429434936178
0.38264907855330454
0.2974011813965416
0.9032771294647794
julia> sort(x; dims=1) # works fine
4×1 Matrix{Float64}:
0.2974011813965416
0.38264907855330454
0.5699429434936178
0.9032771294647794
So it’s not about if size(x,2)==1, it’s about the type of the object. Usually code where x is sometimes a vector and sometimes a matrix is avoided (it’s usually type unstable), but if y is a vector, you can reshape it to be an n x 1 matrix via