This is a re-post of sorts of a question I already asked a year ago in the
user group. At the time, Stefan Karpinski proposed that base.issorted might
be expanded to accomodate checking in multiple dimensions, but looking at
the docs it seems this hasn't happened. This post now has two purposes:
1. To ask if anyone knows of such a functionality, maybe in a package?
2. To see if someone has an idea about how to improve my approach. I'm
basically doing this:
function checkmonotonicity(v::Array{Float64,2})
counter = zeros(2)
for b = 1:size(v,2)
counter[1] += ~issorted(v[:, b])
end
for a = 1:size(v,1)
counter[2] += ~issorted(v[a, :])
end
return counter
end
which for three dimensions requires me to write:
function checkmonotonicity(v::Array{Float64,3})
counter = zeros(3)
for c = 1:size(v,3), b = 1:size(v,2)
counter[1] += ~issorted(v[:, b, c])
end
for c = 1:size(v,3), a = 1:size(v,1)
counter[2] += ~issorted(v[a, :, c])
end
for b = 1:size(v,2), a = 1:size(v,1)
counter[3] += ~issorted(v[a, b, :])
end
return counter
end
and so on for higher dimensions. Obviously, this quickly gets cumbersome
for higher dimensions, so I wanted to see if anyone could recommend a smart
way of doing this (maybe via metaprogramming?).
(For context, I'm actually interested in the number of monotonicity
violations, which is why I count them rather than just breaking at the
first violation in a given dimension. This isn't too important, so if
there's an existing function that simply returns a Boolean for each
dimension, I'm happy with that.)